PageSourceSearch

https://www.anphabe.com/sites/all/modules/mio/discussion/qa/js/date.format.js?suyevr

js anphabe.com collected 2026-09-24 08:34:05 UTC 5,899 bytes, 180 lines download raw bytes

1
2(function ($) {
3  /*
4   * Date Format 1.2.3
5   * (c) 2007-2009 Steven Levithan <stevenlevithan.com>
6   * MIT license
7   *
8   * Includes enhancements by Scott Trenda <scott.trenda.net>
9   * and Kris Kowal <cixar.com/~kris.kowal/>
10   *
11   * Accepts a date, a mask, or a date and a mask.
12   * Returns a formatted version of the given date.
13   * The date defaults to the current date/time.
14   * The mask defaults to dateFormat.masks.default.
15   */
16
17  /**
18   * var now = new Date();
19
20   now.format("m/dd/yy");
21   // Returns, e.g., 6/09/07
22
23   // Can also be used as a standalone function
24   dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
25   // Saturday, June 9th, 2007, 5:46:21 PM
26
27   // You can use one of several named masks
28   now.format("isoDateTime");
29   // 2007-06-09T17:46:21
30
31   // ...Or add your own
32   dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
33   now.format("hammerTime");
34   // 17:46! Can't touch this!
35
36   // When using the standalone dateFormat function,
37   // you can also provide the date as a string
38   dateFormat("Jun 9 2007", "fullDate");
39   // Saturday, June 9, 2007
40
41   // Note that if you don't include the mask argument,
42   // dateFormat.masks.default is used
43   now.format();
44   // Sat Jun 09 2007 17:46:21
45
46   // And if you don't include the date argument,
47   // the current date and time is used
48   dateFormat();
49   // Sat Jun 09 2007 17:46:22
50
51   // You can also skip the date argument (as long as your mask doesn't
52   // contain any numbers), in which case the current date/time is used
53   dateFormat("longTime");
54   // 5:46:22 PM EST
55
56   // And finally, you can convert local time to UTC time. Either pass in
57   // true as an additional argument (no argument skipping allowed in this case):
58   dateFormat(now, "longTime", true);
59   now.format("longTime", true);
60   // Both lines return, e.g., 10:46:21 PM UTC
61
62   // ...Or add the prefix "UTC:" to your mask.
63   now.format("UTC:h:MM:ss TT Z");
64   // 10:46:21 PM UTC
65   */
66
67  $.dateFormat = function() {
68    var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
69      timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
70      timezoneClip = /[^-+\dA-Z]/g,
71      pad = function (val, len) {
72        val = String(val);
73        len = len || 2;
74        while (val.length < len) val = "0" + val;
75        return val;
76      };
77
78    // Regexes and supporting functions are cached through closure
79    return function (date, mask, utc) {
80      var dF = $.dateFormat;
81
82      // You can't provide utc if you skip other args (use the "UTC:" mask prefix)
83      if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
84        mask = date;
85        date = undefined;
86      }
87
88      // Passing date through Date applies Date.parse, if necessary
89      date = date ? new Date(date) : new Date;
90      if (isNaN(date)) throw SyntaxError("invalid date");
91
92      mask = String(dF.masks[mask] || mask || dF.masks["default"]);
93
94      // Allow setting the utc argument via the mask
95      if (mask.slice(0, 4) == "UTC:") {
96        mask = mask.slice(4);
97        utc = true;
98      }
99
100      var	_ = utc ? "getUTC" : "get",
101        d = date[_ + "Date"](),
102        D = date[_ + "Day"](),
103        m = date[_ + "Month"](),
104        y = date[_ + "FullYear"](),
105        H = date[_ + "Hours"](),
106        M = date[_ + "Minutes"](),
107        s = date[_ + "Seconds"](),
108        L = date[_ + "Milliseconds"](),
109        o = utc ? 0 : date.getTimezoneOffset(),
110        flags = {
111          d:    d,
112          dd:   pad(d),
113          ddd:  dF.i18n.dayNames[D],
114          dddd: dF.i18n.dayNames[D + 7],
115          m:    m + 1,
116          mm:   pad(m + 1),
117          mmm:  dF.i18n.monthNames[m],
118          mmmm: dF.i18n.monthNames[m + 12],
119          yy:   String(y).slice(2),
120          yyyy: y,
121          h:    H % 12 || 12,
122          hh:   pad(H % 12 || 12),
123          H:    H,
124          HH:   pad(H),
125          M:    M,
126          MM:   pad(M),
127          s:    s,
128          ss:   pad(s),
129          l:    pad(L, 3),
130          L:    pad(L > 99 ? Math.round(L / 10) : L),
131          t:    H < 12 ? "a"  : "p",
132          tt:   H < 12 ? "am" : "pm",
133          T:    H < 12 ? "A"  : "P",
134          TT:   H < 12 ? "AM" : "PM",
135          Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
136          o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
137          S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
138        };
139
140      return mask.replace(token, function ($0) {
141        return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
142      });
143    };
144  }();
145
146// Some common format strings
147  $.dateFormat.masks = {
148    "default":      "ddd mmm dd yyyy HH:MM:ss",
149    shortDate:      "m/d/yy",
150    mediumDate:     "mmm d, yyyy",
151    longDate:       "mmmm d, yyyy",
152    fullDate:       "dddd, mmmm d, yyyy",
153    shortTime:      "h:MM TT",
154    mediumTime:     "h:MM:ss TT",
155    longTime:       "h:MM:ss TT Z",
156    isoDate:        "yyyy-mm-dd",
157    isoTime:        "HH:MM:ss",
158    isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
159    isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
160  };
161
162// Internationalization strings
163  $.dateFormat.i18n = {
164    dayNames: [
165      "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
166      "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
167    ],
168    monthNames: [
169      "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
170      "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
171    ]
172  };
173
174// For convenience...
175  Date.prototype.format = function (mask, utc) {
176    return $.dateFormat(this, mask, utc);
177  };
178
179
180})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.