mirror of
https://github.com/samsonjs/strftime.git
synced 2026-03-25 09:05:48 +00:00
Compare commits
76 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f2d5290d28 | |||
| 8db2211a2f | |||
| 774e3ce102 | |||
| e61895af6c | |||
| 8a335897ae | |||
| db1c066f13 | |||
| 6cf7d59a46 | |||
| 53e26ba77d | |||
| a0a62db076 | |||
| 52753479c8 | |||
| 67c02b5352 | |||
|
|
b50d512dee | ||
|
|
6157e8a650 | ||
|
|
51a6ade03d | ||
| 93aaf1eac6 | |||
| 12088240fc | |||
| 3af75444e1 | |||
| 1bee290ce5 | |||
| dee584fda4 | |||
| 5a1db7ba03 | |||
| 000143999d | |||
| ce80bc39e3 | |||
|
|
e0780d045f | ||
| 08a9a4b738 | |||
|
|
06107d286a | ||
| 8a06a30115 | |||
| 52720f64f5 | |||
| d3a2095ca3 | |||
| 793ecfb7b4 | |||
| 0fd891c2ab | |||
| 5e674f0a17 | |||
| 3ed3100018 | |||
| c4967d51e0 | |||
| fd648f7f19 | |||
| efcd086585 | |||
| 2375b9732f | |||
| 335ef2ebe8 | |||
| 1e41e85146 | |||
| e571efe7bb | |||
| 71737c8004 | |||
| a54410d663 | |||
| f6c88d0629 | |||
| 02586fa41e | |||
| 4c747ffa2a | |||
| b4e57a851e | |||
| 2294caa44b | |||
| 65aa4d5ea9 | |||
|
|
f8e5b11c9b | ||
|
|
82a8bfae79 | ||
|
|
fc16548517 | ||
|
|
0d0f90f7eb | ||
| b1629fa333 | |||
|
|
84bad921ab | ||
|
|
f5bb098221 | ||
|
|
58f5c3fee8 | ||
|
|
72a2f418c8 | ||
| a133ab1a4e | |||
|
|
b0659a5f78 | ||
|
|
870e4e3771 | ||
| d6f6e74351 | |||
| b852daca88 | |||
| 93326a4d73 | |||
| a213d716a6 | |||
|
|
29111d3bbb | ||
| 8adfd97924 | |||
| 48d143eb90 | |||
| fe2892ebfa | |||
|
|
aee0e19edc | ||
| 22ddd8982f | |||
| ab3d4a052e | |||
| 603a716bf8 | |||
|
|
067ae77ad9 | ||
|
|
002ac8ca4c | ||
| 1d4365f3d5 | |||
| 30fd95dbba | |||
| 8ba1f03a71 |
10 changed files with 641 additions and 207 deletions
77
Changelog.md
77
Changelog.md
|
|
@ -1,3 +1,68 @@
|
|||
v0.10.3 on 2024-06-11
|
||||
---------------------
|
||||
|
||||
- Stop using `let` to avoid breaking backwards compatibility with ES5. Thanks to [Maximilian Herold](https://github.com/mherold) for the report #87
|
||||
|
||||
- Drop '份' suffix from Chinese month names. Thanks to [@mogando668](https://github.com/mogando668) for the report #88
|
||||
|
||||
v0.10.2 on 2023-05-24
|
||||
---------------------
|
||||
|
||||
- Fix test case for %c in current versions of node.js
|
||||
|
||||
- Fix %-y so it omits the leading zero
|
||||
|
||||
Thanks to [Aryan Arora](https://github.com/aryan-debug) for both fixes!
|
||||
|
||||
v0.10.1 on 2021-12-12
|
||||
---------------------
|
||||
|
||||
- Fix it_IT shortMonths locale
|
||||
Thanks to [Douglas de Espindola](https://github.com/douglasep)
|
||||
|
||||
- Try to get a short time zone name for %Z, falling back to the long one. This attempts to work around a change to Date.toString in v8 (node v10+, Chrome 66+). Unfortunately sometimes Date.toLocaleString returns a time zone like GMT+2 and we fall back to the long name in that case.
|
||||
|
||||
v0.10.0 on 2016-12-28
|
||||
---------------------
|
||||
|
||||
- Remove the old API deprecated in v0.9.
|
||||
|
||||
- Bundle some locales that you can use with `strftime.localizeByIdentifier('nl_NL')`. Full list available in the [readme](https://github.com/samsonjs/strftime/blob/master/Readme.md).
|
||||
Thanks to [Andrew Pirondini](https://github.com/andrewjpiro) of [iFixit](https://ifixit.com)
|
||||
|
||||
- Add instructions to install with Yarn.
|
||||
Thanks to [Ayman Nedjmeddine](https://github.com/IOAyman)
|
||||
|
||||
- Unrecognized format specifiers preserve the % sign, e.g. `strftime('%K') => "%K"`.
|
||||
Thanks to [Kevin Jin](https://github.com/Kevin-Jin)
|
||||
|
||||
- Make `strftime` work with dates that have been extended by [DateJS](http://www.datejs.com).
|
||||
Thanks to [Stian Grytøyr](https://github.com/stiang)
|
||||
|
||||
- Add instructions to install with Yarn.
|
||||
Thanks to [Ayman Nedjmeddine](https://github.com/IOAyman)
|
||||
|
||||
- Fix UTC formatting of dates that cross a DST boundary.
|
||||
Thanks to [ray007](https://github.com/ray007)
|
||||
|
||||
- Allow localizing ordinals.
|
||||
Thanks to [Simon Liétar](https://github.com/Sim9760)
|
||||
|
||||
v0.9.2 on 2015-05-29
|
||||
--------------------
|
||||
|
||||
- fix a caching bug, which was a regression in 0.9.0 ([issue #63](https://github.com/samsonjs/strftime/issues/63))
|
||||
|
||||
- update license attribute in package.json as required by npm
|
||||
Thanks to [Peter deHaan](https://github.com/pdehaan)
|
||||
|
||||
- construct GMT times used in tests in a more robust way
|
||||
|
||||
- fix a bug calculating week numbers ([issue #56](https://github.com/samsonjs/strftime/issues/56))
|
||||
Thanks to [Alexandr Nikitin](https://github.com/alexandrnikitin)
|
||||
|
||||
- warn about possible misuse of %:: or %::: modifiers
|
||||
|
||||
v0.9.1 on 2015-03-16
|
||||
--------------------
|
||||
|
||||
|
|
@ -14,17 +79,19 @@ The headline feature is a huge performance boost resulting from [this contest](h
|
|||
|
||||
Along with this the API has been unified and cleaned up. `strftimeTZ`, `strftimeUTC`, and `localizedStrftime` have all been deprecated in favour of the following functions: `timezone(tz)`, `utc()`, and `localize(locale)`. You use them like so:
|
||||
|
||||
```JavaScript
|
||||
var strftime = require('strftime'); // not required in web browsers
|
||||
|
||||
|
||||
var strftimeIT = strftime.localize(anItalianLocale);
|
||||
var strftimePST = strftime.timezone('-0800');
|
||||
var strftimeUTC = strftime.utc();
|
||||
|
||||
|
||||
// You can combine them
|
||||
var strftimeIT_PST = strftimeIT.timezone('-0800');
|
||||
|
||||
|
||||
// And chain them all at once
|
||||
var strftimeIT_PST = strftime.localize(anItalianLocale).timezone('-0800');
|
||||
```
|
||||
|
||||
The previous API is deprecated and will be removed for v1.0. The good news is that the previous API is supported by adapting the new API, so you get most of the performance benefits before you even update your code to use the new API.
|
||||
|
||||
|
|
@ -161,7 +228,7 @@ v0.4.5 on 2011-06-08
|
|||
|
||||
v0.4.4 on 2011-06-07
|
||||
--------------------
|
||||
|
||||
|
||||
- fix `%L` for values < 100
|
||||
|
||||
- convert tests from CoffeeScript to JavaScript
|
||||
|
|
@ -181,7 +248,7 @@ This release was all [Andrew Schaaf](https://github.com/andrewschaaf).
|
|||
v0.4.2 on 2011-06-05
|
||||
--------------------
|
||||
|
||||
- add `strftimeUTC` for ignoring timezones
|
||||
- add `strftimeUTC` for ignoring timezones
|
||||
Thanks to [Andrew Schaaf](https://github.com/andrewschaaf)
|
||||
|
||||
- support exporting to the top level object in ES5 strict mode
|
||||
|
|
|
|||
6
Makefile
6
Makefile
|
|
@ -2,14 +2,14 @@ minify: real-minify test-minified
|
|||
|
||||
real-minify: strftime.js
|
||||
rm -f strftime-min.js
|
||||
closure <strftime.js >|strftime-min.js
|
||||
closure-compiler <strftime.js >|strftime-min.js
|
||||
|
||||
test:
|
||||
TZ=America/Vancouver node test.js
|
||||
TZ=CET node test.js
|
||||
TZ=Europe/Amsterdam node test.js
|
||||
|
||||
test-minified: minify
|
||||
TZ=America/Vancouver node test.js ./strftime-min.js
|
||||
TZ=CET node test.js ./strftime-min.js
|
||||
TZ=Europe/Amsterdam node test.js ./strftime-min.js
|
||||
|
||||
.PHONY: test test-minified
|
||||
|
|
|
|||
111
Readme.md
111
Readme.md
|
|
@ -3,6 +3,10 @@ strftime
|
|||
|
||||
strftime for JavaScript. Works in (at least) node.js and browsers. Supports localization and timezones. Most standard specifiers from C are supported as well as some other extensions from Ruby.
|
||||
|
||||
[](https://www.npmjs.com/package/strftime)
|
||||
[](https://nodejs.org)
|
||||
[](https://sjs.mit-license.org)
|
||||
[](https://0dependencies.dev)
|
||||
|
||||
Installation
|
||||
============
|
||||
|
|
@ -19,29 +23,33 @@ Installation
|
|||
|
||||
component install samsonjs/strftime
|
||||
|
||||
[yarn](https://yarnpkg.com):
|
||||
|
||||
yarn add strftime
|
||||
|
||||
Or you can copy [strftime.js](https://github.com/samsonjs/strftime/blob/master/strftime.js) wherever you want to use it, whether that's with a <script> tag or `require` or anything else.
|
||||
|
||||
The New API in 0.9
|
||||
==================
|
||||
Changelog
|
||||
=========
|
||||
|
||||
The current version, 0.9, deprecates the older API that exported several functions: `strftimeTZ`, `strftimeUTC`, and `localizedStrftime`. In addition to this the exported function referenced itself as `require('strftime').strftime` or `window.strftime.strftime` for consistency with the other functions. *These functions are deprecated in 0.9 and will be removed in 1.0.*
|
||||
|
||||
Now you only need the single object exported and you can create a specialized version of it using the functions `utc()`, `localize(locale)`, and `timezone(offset)`. You can no longer pass in a timezone or locale on each call to `strftime` which is a regression. If you need this let me know and we will add it back into the API.
|
||||
|
||||
[More details are available in the changelog](https://github.com/samsonjs/strftime/blob/master/Changelog.md).
|
||||
[View the changelog](https://github.com/samsonjs/strftime/blob/master/Changelog.md).
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
```JavaScript
|
||||
var strftime = require('strftime') // not required in browsers
|
||||
console.log(strftime('%B %d, %Y %H:%M:%S')) // => April 28, 2011 18:21:08
|
||||
console.log(strftime('%F %T', new Date(1307472705067))) // => 2011-06-07 18:51:45
|
||||
```
|
||||
|
||||
|
||||
If you want to localize it:
|
||||
|
||||
```JavaScript
|
||||
var strftime = require('strftime') // not required in browsers
|
||||
var it_IT = {
|
||||
identifier: 'it-IT',
|
||||
days: ['domenica', 'lunedi', 'martedi', 'mercoledi', 'giovedi', 'venerdi', 'sabato'],
|
||||
shortDays: ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'],
|
||||
months: ['gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre'],
|
||||
|
|
@ -65,25 +73,38 @@ If you want to localize it:
|
|||
var strftimeIT = strftime.localize(it_IT)
|
||||
console.log(strftimeIT('%B %d, %Y %H:%M:%S')) // => aprile 28, 2011 18:21:08
|
||||
console.log(strftimeIT('%B %d, %Y %H:%M:%S', new Date(1307472705067))) // => giugno 7, 2011 18:51:45
|
||||
```
|
||||
|
||||
Some locales are bundled and can be used like so:
|
||||
|
||||
```JavaScript
|
||||
var strftime = require('strftime') // not required in browsers
|
||||
var strftimeIT = strftime.localizeByIdentifier('it_IT')
|
||||
console.log(strftimeIT('%B %d, %Y %H:%M:%S')) // => aprile 28, 2011 18:21:08
|
||||
console.log(strftimeIT('%B %d, %Y %H:%M:%S', new Date(1307472705067))) // => giugno 7, 2011 18:51:45
|
||||
```
|
||||
|
||||
_The [full list of bundled locales](#locales) is below._
|
||||
|
||||
Time zones can be passed in as an offset from GMT in minutes.
|
||||
|
||||
```JavaScript
|
||||
var strftime = require('strftime') // not required in browsers
|
||||
var strftimePDT = strftime.timezone(-420)
|
||||
var strftimeCEST = strftime.timezone(120)
|
||||
console.log(strftimePDT('%B %d, %y %H:%M:%S', new Date(1307472705067))) // => June 07, 11 11:51:45
|
||||
console.log(strftimeCEST('%F %T', new Date(1307472705067))) // => 2011-06-07 20:51:45
|
||||
|
||||
```
|
||||
|
||||
Alternatively you can use the timezone format used by ISO 8601, `+HHMM` or `-HHMM`.
|
||||
|
||||
```JavaScript
|
||||
var strftime = require('strftime') // not required in browsers
|
||||
var strftimePDT = strftime.timezone('-0700')
|
||||
var strftimeCEST = strftime.timezone('+0200')
|
||||
console.log(strftimePDT('', new Date(1307472705067))) // => June 07, 11 11:51:45
|
||||
console.log(strftimePDT('%F %T', new Date(1307472705067))) // => 2011-06-07 11:51:45
|
||||
console.log(strftimeCEST('%F %T', new Date(1307472705067))) // => 2011-06-07 20:51:45
|
||||
|
||||
```
|
||||
|
||||
Supported Specifiers
|
||||
====================
|
||||
|
|
@ -98,11 +119,11 @@ e.g. `%q` becomes `q`. Use `%%` to get a literal `%` sign.
|
|||
- B: full month name
|
||||
- b: abbreviated month name
|
||||
- C: AD century (year / 100), padded to 2 digits
|
||||
- c: equivalent to `%a %b %d %X %Y` in en-US (based on locale)
|
||||
- D: equivalent to `%m/%d/%y` in en-US (based on locale)
|
||||
- c: equivalent to `%a %b %d %X %Y %Z` in en_US (based on locale)
|
||||
- D: equivalent to `%m/%d/%y` in en_US (based on locale)
|
||||
- d: day of the month, padded to 2 digits (01-31)
|
||||
- e: day of the month, padded with a leading space for single digit values (1-31)
|
||||
- F: equivalent to `%Y-%m-%d` in en-US (based on locale)
|
||||
- F: equivalent to `%Y-%m-%d` in en_US (based on locale)
|
||||
- H: the hour (24-hour clock), padded to 2 digits (00-23)
|
||||
- h: the same as %b (abbreviated month name)
|
||||
- I: the hour (12-hour clock), padded to 2 digits (01-12)
|
||||
|
|
@ -116,21 +137,21 @@ e.g. `%q` becomes `q`. Use `%%` to get a literal `%` sign.
|
|||
- o: day of the month as an ordinal (without padding), e.g. 1st, 2nd, 3rd, 4th, ...
|
||||
- P: "am" or "pm" in lowercase (Ruby extension, based on locale)
|
||||
- p: "AM" or "PM" (based on locale)
|
||||
- R: equivalent to `%H:%M` in en-US (based on locale)
|
||||
- r: equivalent to `%I:%M:%S %p` in en-US (based on locale)
|
||||
- R: equivalent to `%H:%M` in en_US (based on locale)
|
||||
- r: equivalent to `%I:%M:%S %p` in en_US (based on locale)
|
||||
- S: the second, padded to 2 digits (00-60)
|
||||
- s: the number of seconds since the Epoch, UTC
|
||||
- T: equivalent to `%H:%M:%S` in en-US (based on locale)
|
||||
- T: equivalent to `%H:%M:%S` in en_US (based on locale)
|
||||
- t: tab character
|
||||
- U: week number of the year, Sunday as the first day of the week, padded to 2 digits (00-53)
|
||||
- u: the weekday, Monday as the first day of the week (1-7)
|
||||
- v: equivalent to `%e-%b-%Y` in en-US (based on locale)
|
||||
- v: equivalent to `%e-%b-%Y` in en_US (based on locale)
|
||||
- W: week number of the year, Monday as the first day of the week, padded to 2 digits (00-53)
|
||||
- w: the weekday, Sunday as the first day of the week (0-6)
|
||||
- X: equivalent to `%D` in en-US (based on locale)
|
||||
- x: equivalent to `%T` in en-US (based on locale)
|
||||
- X: equivalent to `%T` or `%r` in en_US (based on locale)
|
||||
- x: equivalent to `%D` in en_US (based on locale)
|
||||
- Y: the year with the century
|
||||
- y: the year without the century (00-99)
|
||||
- y: the year without the century, padded to 2 digits (00-99)
|
||||
- Z: the time zone name, replaced with an empty string if it is not found
|
||||
- z: the time zone offset from UTC, with a leading plus sign for UTC and zones east
|
||||
of UTC and a minus sign for those west of UTC, hours and minutes follow each
|
||||
|
|
@ -140,26 +161,52 @@ For more detail see `man 3 strftime` as the format specifiers should behave iden
|
|||
|
||||
Any specifier can be modified with `-`, `_`, `0`, or `:` as well, as in Ruby. Using `%-` will omit any leading zeroes or spaces, `%_` will force spaces for padding instead of the default, and `%0` will force zeroes for padding. There's some redundancy here as `%-d` and `%e` have the same result, but it solves some awkwardness with formats like `%l`. Using `%:` for time zone offset, as in `%:z` will insert a colon as a delimiter.
|
||||
|
||||
<a name="locales"></a>
|
||||
Bundled Locales
|
||||
===============
|
||||
|
||||
- de\_DE
|
||||
- en\_CA
|
||||
- en\_US
|
||||
- es\_MX
|
||||
- fr\_FR
|
||||
- it\_IT
|
||||
- nl\_NL
|
||||
- pt\_BR
|
||||
- ru\_RU
|
||||
- tr\_TR
|
||||
- zh\_CN
|
||||
|
||||
Contributors
|
||||
============
|
||||
|
||||
* [Rob Colburn](https://github.com/robcolburn)
|
||||
* [Cory Heslip](https://github.com/cheslip)
|
||||
* [TJ Holowaychuk](https://github.com/tj)
|
||||
* [Forbes Lindesay](https://github.com/ForbesLindesay)
|
||||
* [Alexandr Nikitin](https://github.com/alexandrnikitin)
|
||||
* [Ryan Regalado](https://github.com/d48)
|
||||
* [Sami Samhuri](https://github.com/samsonjs)
|
||||
* [Andrew Pirondini](https://github.com/andrewjpiro) of [iFixit](https://github.com/iFixit)
|
||||
* [Andrew Schaaf](https://github.com/andrewschaaf)
|
||||
* [Ryan Stafford](https://github.com/ryanstafford)
|
||||
* [w0den](https://github.com/w0den)
|
||||
* [Aryan Arora](https://github.com/aryan-debug)
|
||||
* [Ayman Nedjmeddine](https://github.com/IOAyman)
|
||||
* [Cory Heslip](https://github.com/cheslip)
|
||||
* [Douglas de Espindola](https://github.com/douglasep)
|
||||
* [Forbes Lindesay](https://github.com/ForbesLindesay)
|
||||
* [John Zwinck](https://github.com/jzwinck)
|
||||
|
||||
* [Joost Hietbrink](https://github.com/joost)
|
||||
* [Kevin Jin](https://github.com/Kevin-Jin)
|
||||
* [Maximilian Herold](https://github.com/mherold)
|
||||
* [Michael J.](https://github.com/michaeljayt)
|
||||
* [@mogando668](https://github.com/mogando668)
|
||||
* [Peter deHaan](https://github.com/pdehaan)
|
||||
* [Rob Colburn](https://github.com/robcolburn)
|
||||
* [Ryan Regalado](https://github.com/d48)
|
||||
* [Ryan Stafford](https://github.com/ryanstafford)
|
||||
* [Sami Samhuri](https://github.com/samsonjs)
|
||||
* [Stian Grytøyr](https://github.com/stiang)
|
||||
* [TJ Holowaychuk](https://github.com/tj)
|
||||
* [@w0den](https://github.com/w0den)
|
||||
* [Yusuke Kawasaki](https://github.com/kawanet)
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
Copyright 2010 - 2015 Sami Samhuri sami@samhuri.net
|
||||
|
||||
[MIT license](http://sjs.mit-license.org)
|
||||
Copyright 2010 - 2024 Sami Samhuri sami@samhuri.net
|
||||
|
||||
[MIT license](https://sjs.mit-license.org)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "strftime",
|
||||
"version": "0.9.1",
|
||||
"version": "0.10.3",
|
||||
"main": "strftime.js",
|
||||
"ignore": [
|
||||
"Readme.md",
|
||||
|
|
|
|||
|
|
@ -2,8 +2,15 @@
|
|||
"name": "strftime",
|
||||
"repo": "samsonjs/strftime",
|
||||
"description": "strftime date formatting",
|
||||
"keywords": ["strftime", "format", "date", "time"],
|
||||
"version": "0.9.1",
|
||||
"keywords": [
|
||||
"strftime",
|
||||
"format",
|
||||
"date",
|
||||
"time"
|
||||
],
|
||||
"version": "0.10.3",
|
||||
"main": "strftime.js",
|
||||
"scripts": ["strftime.js"]
|
||||
}
|
||||
"scripts": [
|
||||
"strftime.js"
|
||||
]
|
||||
}
|
||||
17
package-lock.json
generated
Normal file
17
package-lock.json
generated
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "strftime",
|
||||
"version": "0.10.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "strftime",
|
||||
"version": "0.10.3",
|
||||
"license": "MIT",
|
||||
"devDependencies": {},
|
||||
"engines": {
|
||||
"node": ">=0.2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
package.json
47
package.json
|
|
@ -1,20 +1,38 @@
|
|||
{
|
||||
"name": "strftime",
|
||||
"description": "strftime for JavaScript",
|
||||
"version": "0.9.1",
|
||||
"homepage": "http://samhuri.net/proj/strftime",
|
||||
"version": "0.10.3",
|
||||
"homepage": "https://samhuri.net/projects/strftime",
|
||||
"author": "Sami Samhuri <sami@samhuri.net>",
|
||||
"contributors": [
|
||||
"Sami Samhuri <sami@samhuri.net> (http://samhuri.net)",
|
||||
"Andrew Schaaf <andrew@andrewschaaf.com> (http://andrewschaaf.com/)",
|
||||
"Rob Colburn <rob@robcolburn.com> (http://robcolburn.com/)",
|
||||
"Ryan Stafford (http://droffats.net/)",
|
||||
"Alexandr Nikitin <nikitin.alexandr.a@gmail.com>",
|
||||
"TJ Holowaychuk (http://tjholowaychuk.com/)",
|
||||
"John Zwinck (https://github.com/jzwinck)",
|
||||
"Alexandr Nikitin (https://github.com/alexandrnikitin)",
|
||||
"Andrew Pirondini of iFixit (https://github.com/andrewjpiro)",
|
||||
"Andrew Schaaf <andrew@andrewschaaf.com> (https://github.com/andrewschaaf)",
|
||||
"Ayman Nedjmeddine (https://github.com/IOAyman)",
|
||||
"Cory Heslip (https://github.com/cheslip)",
|
||||
"Douglas de Espindola (https://github.com/douglasep)",
|
||||
"Forbes Lindesay (https://github.com/ForbesLindesay)",
|
||||
"John Zwinck (https://github.com/jzwinck)",
|
||||
"Joost Hietbrink (https://github.com/joost)",
|
||||
"Kevin Jin (https://github.com/Kevin-Jin)",
|
||||
"Michael J. (https://github.com/michaeljayt)",
|
||||
"Peter deHaan (https://github.com/pdehaan)",
|
||||
"Rob Colburn <rob@robcolburn.com> (https://github.com/robcolburn)",
|
||||
"Ryan Regalado (https://github.com/d48)",
|
||||
"w0den (https://github.com/w0den)"
|
||||
"Ryan Stafford (https://github.com/ryanstafford)",
|
||||
"Sami Samhuri <sami@samhuri.net> (https://github.com/samsonjs)",
|
||||
"Stian Grytøyr (https://github.com/stiang)",
|
||||
"TJ Holowaychuk (https://github.com/tj)",
|
||||
"w0den (https://github.com/w0den)",
|
||||
"Yusuke Kawasaki (https://github.com/kawanet)",
|
||||
"Aryan Arora (https://github.com/aryan-debug)"
|
||||
],
|
||||
"keywords": [
|
||||
"strftime",
|
||||
"format",
|
||||
"string",
|
||||
"time",
|
||||
"date"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
@ -28,13 +46,8 @@
|
|||
"engines": {
|
||||
"node": ">=0.2.0"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://sjs.mit-license.org"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {},
|
||||
"devDependencies": {},
|
||||
"optionalDependencies": {}
|
||||
}
|
||||
}
|
||||
32
strftime-min.js
vendored
32
strftime-min.js
vendored
|
|
@ -1,11 +1,21 @@
|
|||
(function(){function k(a,c){s[a]||(typeof console!=="undefined"&&typeof console.warn=="function"&&console.warn("[WARNING] "+a+" is deprecated and will be removed in version 1.0. Instead, use `"+c+"`."),s[a]=!0)}function t(a){a.localize=i.localize.bind(i);a.timezone=i.timezone.bind(i);a.utc=i.utc.bind(i)}function r(a,c,e){c&&c.days&&(e=c,c=void 0);e&&k("`"+g+"(format, [date], [locale])`","var s = "+g+".localize(locale); s(format, [date])");return(e?i.localize(e):i)(a,c)}function u(a,c,e){e?k("`"+g+
|
||||
".strftime(format, [date], [locale])`","var s = "+g+".localize(locale); s(format, [date])"):k("`"+g+".strftime(format, [date])`",g+"(format, [date])");return(e?i.localize(e):i)(a,c)}function p(a,c,e){function g(a,b,h,c){for(var d="",f=null,e=!1,i=a.length,j=!1,o=0;o<i;o++){var n=a.charCodeAt(o);if(e===!0)if(n===45)f="";else if(n===95)f=" ";else if(n===48)f="0";else if(n===58)j=!0;else{switch(n){case 65:d+=h.days[b.getDay()];break;case 66:d+=h.months[b.getMonth()];break;case 67:d+=l(Math.floor(b.getFullYear()/
|
||||
100),f);break;case 68:d+=g(h.formats.D,b,h,c);break;case 70:d+=g(h.formats.F,b,h,c);break;case 72:d+=l(b.getHours(),f);break;case 73:d+=l(v(b.getHours()),f);break;case 76:d+=Math.floor(c%1E3)>99?Math.floor(c%1E3):Math.floor(c%1E3)>9?"0"+Math.floor(c%1E3):"00"+Math.floor(c%1E3);break;case 77:d+=l(b.getMinutes(),f);break;case 80:d+=b.getHours()<12?h.am:h.pm;break;case 82:d+=g(h.formats.R,b,h,c);break;case 83:d+=l(b.getSeconds(),f);break;case 84:d+=g(h.formats.T,b,h,c);break;case 85:d+=l(w(b,"sunday"),
|
||||
f);break;case 87:d+=l(w(b,"monday"),f);break;case 88:d+=g(h.formats.X,b,h,c);break;case 89:d+=b.getFullYear();break;case 90:k&&m===0?d+="GMT":(f=b.toString().match(/\(([\w\s]+)\)/),d+=f&&f[1]||"");break;case 97:d+=h.shortDays[b.getDay()];break;case 98:d+=h.shortMonths[b.getMonth()];break;case 99:d+=g(h.formats.c,b,h,c);break;case 100:d+=l(b.getDate(),f);break;case 101:d+=l(b.getDate(),f==null?" ":f);break;case 104:d+=h.shortMonths[b.getMonth()];break;case 106:f=new Date(b.getFullYear(),0,1);f=Math.ceil((b.getTime()-
|
||||
f.getTime())/864E5);d+=f>99?f:f>9?"0"+f:"00"+f;break;case 107:d+=l(b.getHours(),f==null?" ":f);break;case 108:d+=l(v(b.getHours()),f==null?" ":f);break;case 109:d+=l(b.getMonth()+1,f);break;case 110:d+="\n";break;case 111:d+=String(b.getDate())+A(b.getDate());break;case 112:d+=b.getHours()<12?h.AM:h.PM;break;case 114:d+=g(h.formats.r,b,h,c);break;case 115:d+=Math.floor(c/1E3);break;case 116:d+="\t";break;case 117:f=b.getDay();d+=f===0?7:f;break;case 118:d+=g(h.formats.v,b,h,c);break;case 119:d+=b.getDay();
|
||||
break;case 120:d+=g(h.formats.x,b,h,c);break;case 121:d+=(""+b.getFullYear()).slice(2);break;case 122:k&&m===0?d+=j?"+00:00":"+0000":(f=m!==0?m/6E4:-b.getTimezoneOffset(),e=j?":":"",n=Math.abs(f%60),d+=(f<0?"-":"+")+l(Math.floor(Math.abs(f/60)))+e+l(n));break;default:d+=a[o]}f=null;e=!1}else n===37?e=!0:d+=a[o]}return d}var i=a||x,m=c||0,k=e||!1,j=0,q,a=function(a,b){var c;if(b)c=b.getTime(),k&&(b=new Date(b.getTime()+(b.getTimezoneOffset()||0)*6E4+m));else{var e=Date.now();e>j&&(j=e,q=new Date(j),
|
||||
c=j,k&&(q=new Date(j+(q.getTimezoneOffset()||0)*6E4+m)));b=q}return g(a,b,i,c)};a.localize=function(a){return new p(a||i,m,k)};a.timezone=function(a){var b=m,c=k,e=typeof a;if(e==="number"||e==="string")c=!0,e==="string"?(b=a[0]==="-"?-1:1,e=parseInt(a.slice(1,3),10),a=parseInt(a.slice(3,5),10),b=b*(60*e+a)*6E4):e==="number"&&(b=a*6E4);return new p(i,b,c)};a.utc=function(){return new p(i,m,!0)};return a}function l(a,c){if(c===""||a>9)return a;c==null&&(c="0");return c+a}function v(a){if(a===0)return 12;
|
||||
else if(a>12)return a-12;return a}function w(a,c){var c=c||"sunday",e=a.getDay();c==="monday"&&(e===0?e=6:e--);var g=new Date(a.getFullYear(),0,1);return Math.floor(((a-g)/864E5+7-e)/7)}function A(a){var c=a%10;a%=100;if(a>=11&&a<=13||c===0||c>=4)return"th";switch(c){case 1:return"st";case 2:return"nd";case 3:return"rd"}}var x={days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April",
|
||||
"May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],AM:"AM",PM:"PM",am:"am",pm:"pm",formats:{D:"%m/%d/%y",F:"%Y-%m-%d",R:"%H:%M",T:"%H:%M:%S",X:"%T",c:"%a %b %d %X %Y",r:"%I:%M:%S %p",v:"%e-%b-%Y",x:"%D"}},i=new p(x,0,!1),y=typeof module!=="undefined",j;y?(j=module.exports=r,j.strftime=u):(j=function(){return this||(0,eval)("this")}(),j.strftime=r);var g=y?"require('strftime')":"strftime",s=
|
||||
{};j.strftimeTZ=function(a,c,e,j){if((typeof e=="number"||typeof e=="string")&&j==null)j=e,e=void 0;e?k("`"+g+".strftimeTZ(format, date, locale, tz)`","var s = "+g+".localize(locale).timezone(tz); s(format, [date])` or `var s = "+g+".localize(locale); s.timezone(tz)(format, [date])"):k("`"+g+".strftimeTZ(format, date, tz)`","var s = "+g+".timezone(tz); s(format, [date])` or `"+g+".timezone(tz)(format, [date])");return(e?i.localize(e):i).timezone(j)(a,c)};j.strftimeUTC=function(a,c,e){e?k("`"+g+".strftimeUTC(format, date, locale)`",
|
||||
"var s = "+g+".localize(locale).utc(); s(format, [date])"):k("`"+g+".strftimeUTC(format, [date])`","var s = "+g+".utc(); s(format, [date])");return(e?z.localize(e):z)(a,c)};j.localizedStrftime=function(a){k("`"+g+".localizedStrftime(locale)`",g+".localize(locale)");return i.localize(a)};t(r);t(u);var z=i.utc();if(typeof Date.now!=="function")Date.now=function(){return+new Date}})();
|
||||
(function(){function w(e,h,q){function l(g,a,c,f){for(var b="",d=null,r=!1,J=g.length,x=!1,v=0;v<J;v++){var n=g.charCodeAt(v);if(!0===r)if(45===n)d="";else if(95===n)d=" ";else if(48===n)d="0";else if(58===n)x&&A("[WARNING] detected use of unsupported %:: or %::: modifiers to strftime"),x=!0;else{switch(n){case 37:b+="%";break;case 65:b+=c.days[a.getDay()];break;case 66:b+=c.months[a.getMonth()];break;case 67:b+=k(Math.floor(a.getFullYear()/100),d);break;case 68:b+=l(c.formats.D,a,c,f);break;case 70:b+=
|
||||
l(c.formats.F,a,c,f);break;case 72:b+=k(a.getHours(),d);break;case 73:b+=k(B(a.getHours()),d);break;case 76:b+=C(Math.floor(f%1E3));break;case 77:b+=k(a.getMinutes(),d);break;case 80:b+=12>a.getHours()?c.am:c.pm;break;case 82:b+=l(c.formats.R,a,c,f);break;case 83:b+=k(a.getSeconds(),d);break;case 84:b+=l(c.formats.T,a,c,f);break;case 85:b+=k(D(a,"sunday"),d);break;case 87:b+=k(D(a,"monday"),d);break;case 88:b+=l(c.formats.X,a,c,f);break;case 89:b+=a.getFullYear();break;case 90:t&&0===m?b+="GMT":(d=
|
||||
a.toString().match(/\(([\w\s]+)\)/),b+=d&&d[1]||"");break;case 97:b+=c.shortDays[a.getDay()];break;case 98:b+=c.shortMonths[a.getMonth()];break;case 99:b+=l(c.formats.c,a,c,f);break;case 100:b+=k(a.getDate(),d);break;case 101:b+=k(a.getDate(),null==d?" ":d);break;case 104:b+=c.shortMonths[a.getMonth()];break;case 106:d=new Date(a.getFullYear(),0,1);d=Math.ceil((a.getTime()-d.getTime())/864E5);b+=C(d);break;case 107:b+=k(a.getHours(),null==d?" ":d);break;case 108:b+=k(B(a.getHours()),null==d?" ":d);
|
||||
break;case 109:b+=k(a.getMonth()+1,d);break;case 110:b+="\n";break;case 111:d=a.getDate();b=c.ordinalSuffixes?b+(String(d)+(c.ordinalSuffixes[d-1]||E(d))):b+(String(d)+E(d));break;case 112:b+=12>a.getHours()?c.AM:c.PM;break;case 114:b+=l(c.formats.r,a,c,f);break;case 115:b+=Math.floor(f/1E3);break;case 116:b+="\t";break;case 117:d=a.getDay();b+=0===d?7:d;break;case 118:b+=l(c.formats.v,a,c,f);break;case 119:b+=a.getDay();break;case 120:b+=l(c.formats.x,a,c,f);break;case 121:b+=k(a.getFullYear()%100,
|
||||
d);break;case 122:t&&0===m?b+=x?"+00:00":"+0000":(d=0!==m?m/6E4:-a.getTimezoneOffset(),r=x?":":"",n=Math.abs(d%60),b+=(0>d?"-":"+")+k(Math.floor(Math.abs(d/60)))+r+k(n));break;default:r&&(b+="%"),b+=g[v]}d=null;r=!1}else 37===n?r=!0:b+=g[v]}return b}var y=e||F,m=h||0,t=q||!1,u=0,z,p=function(g,a){if(a){var c=a.getTime();if(t){var f=6E4*(a.getTimezoneOffset()||0);a=new Date(c+f+m);6E4*(a.getTimezoneOffset()||0)!==f&&(a=6E4*(a.getTimezoneOffset()||0),a=new Date(c+a+m))}}else c=Date.now(),c>u?(u=c,z=
|
||||
new Date(u),c=u,t&&(z=new Date(u+6E4*(z.getTimezoneOffset()||0)+m))):c=u,a=z;return l(g,a,y,c)};p.localize=function(g){return new w(g||y,m,t)};p.localizeByIdentifier=function(g){var a=G[g];return a?p.localize(a):(A('[WARNING] No locale found with identifier "'+g+'".'),p)};p.timezone=function(g){var a=m,c=t,f=typeof g;if("number"===f||"string"===f)c=!0,"string"===f?(a="-"===g[0]?-1:1,f=parseInt(g.slice(1,3),10),g=parseInt(g.slice(3,5),10),a=a*(60*f+g)*6E4):"number"===f&&(a=6E4*g);return new w(y,a,
|
||||
c)};p.utc=function(){return new w(y,m,!0)};return p}function k(e,h){if(""===h||9<e)return""+e;null==h&&(h="0");return h+e}function C(e){return 99<e?e:9<e?"0"+e:"00"+e}function B(e){return 0===e?12:12<e?e-12:e}function D(e,h){h=h||"sunday";var q=e.getDay();"monday"===h&&(0===q?q=6:q--);h=Date.UTC(e.getFullYear(),0,1);e=Date.UTC(e.getFullYear(),e.getMonth(),e.getDate());return Math.floor((Math.floor((e-h)/864E5)+7-q)/7)}function E(e){var h=e%10;e%=100;if(11<=e&&13>=e||0===h||4<=h)return"th";switch(h){case 1:return"st";
|
||||
case 2:return"nd";case 3:return"rd"}}function A(e){"undefined"!==typeof console&&"function"==typeof console.warn&&console.warn(e)}var G={de_DE:{identifier:"de-DE",days:"Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag".split(" "),shortDays:"So Mo Di Mi Do Fr Sa".split(" "),months:"Januar Februar M\u00e4rz April Mai Juni Juli August September Oktober November Dezember".split(" "),shortMonths:"Jan Feb M\u00e4r Apr Mai Jun Jul Aug Sep Okt Nov Dez".split(" "),AM:"AM",PM:"PM",am:"am",pm:"pm",
|
||||
formats:{c:"%a %d %b %Y %X %Z",D:"%d.%m.%Y",F:"%Y-%m-%d",R:"%H:%M",r:"%I:%M:%S %p",T:"%H:%M:%S",v:"%e-%b-%Y",X:"%T",x:"%D"}},en_CA:{identifier:"en-CA",days:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),shortDays:"Sun Mon Tue Wed Thu Fri Sat".split(" "),months:"January February March April May June July August September October November December".split(" "),shortMonths:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),ordinalSuffixes:"st nd rd th th th th th th th th th th th th th th th th th st nd rd th th th th th th th st".split(" "),
|
||||
AM:"AM",PM:"PM",am:"am",pm:"pm",formats:{c:"%a %d %b %Y %X %Z",D:"%d/%m/%y",F:"%Y-%m-%d",R:"%H:%M",r:"%I:%M:%S %p",T:"%H:%M:%S",v:"%e-%b-%Y",X:"%r",x:"%D"}},en_US:{identifier:"en-US",days:"Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),shortDays:"Sun Mon Tue Wed Thu Fri Sat".split(" "),months:"January February March April May June July August September October November December".split(" "),shortMonths:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),ordinalSuffixes:"st nd rd th th th th th th th th th th th th th th th th th st nd rd th th th th th th th st".split(" "),
|
||||
AM:"AM",PM:"PM",am:"am",pm:"pm",formats:{c:"%a %d %b %Y %X %Z",D:"%m/%d/%y",F:"%Y-%m-%d",R:"%H:%M",r:"%I:%M:%S %p",T:"%H:%M:%S",v:"%e-%b-%Y",X:"%r",x:"%D"}},es_MX:{identifier:"es-MX",days:"domingo lunes martes mi\u00e9rcoles jueves viernes s\u00e1bado".split(" "),shortDays:"dom lun mar mi\u00e9 jue vie s\u00e1b".split(" "),months:"enero febrero marzo abril mayo junio julio agosto septiembre octubre noviembre diciembre".split(" "),shortMonths:"ene feb mar abr may jun jul ago sep oct nov dic".split(" "),
|
||||
AM:"AM",PM:"PM",am:"am",pm:"pm",formats:{c:"%a %d %b %Y %X %Z",D:"%d/%m/%Y",F:"%Y-%m-%d",R:"%H:%M",r:"%I:%M:%S %p",T:"%H:%M:%S",v:"%e-%b-%Y",X:"%T",x:"%D"}},fr_FR:{identifier:"fr-FR",days:"dimanche lundi mardi mercredi jeudi vendredi samedi".split(" "),shortDays:"dim. lun. mar. mer. jeu. ven. sam.".split(" "),months:"janvier f\u00e9vrier mars avril mai juin juillet ao\u00fbt septembre octobre novembre d\u00e9cembre".split(" "),shortMonths:"janv. f\u00e9vr. mars avril mai juin juil. ao\u00fbt sept. oct. nov. d\u00e9c.".split(" "),
|
||||
AM:"AM",PM:"PM",am:"am",pm:"pm",formats:{c:"%a %d %b %Y %X %Z",D:"%d/%m/%Y",F:"%Y-%m-%d",R:"%H:%M",r:"%I:%M:%S %p",T:"%H:%M:%S",v:"%e-%b-%Y",X:"%T",x:"%D"}},it_IT:{identifier:"it-IT",days:"domenica luned\u00ec marted\u00ec mercoled\u00ec gioved\u00ec venerd\u00ec sabato".split(" "),shortDays:"dom lun mar mer gio ven sab".split(" "),months:"gennaio febbraio marzo aprile maggio giugno luglio agosto settembre ottobre novembre dicembre".split(" "),shortMonths:"gen feb mar apr mag giu lug ago set ott nov dic".split(" "),
|
||||
AM:"AM",PM:"PM",am:"am",pm:"pm",formats:{c:"%a %d %b %Y %X %Z",D:"%d/%m/%Y",F:"%Y-%m-%d",R:"%H:%M",r:"%I:%M:%S %p",T:"%H:%M:%S",v:"%e-%b-%Y",X:"%T",x:"%D"}},nl_NL:{identifier:"nl-NL",days:"zondag maandag dinsdag woensdag donderdag vrijdag zaterdag".split(" "),shortDays:"zo ma di wo do vr za".split(" "),months:"januari februari maart april mei juni juli augustus september oktober november december".split(" "),shortMonths:"jan feb mrt apr mei jun jul aug sep okt nov dec".split(" "),AM:"AM",PM:"PM",
|
||||
am:"am",pm:"pm",formats:{c:"%a %d %b %Y %X %Z",D:"%d-%m-%y",F:"%Y-%m-%d",R:"%H:%M",r:"%I:%M:%S %p",T:"%H:%M:%S",v:"%e-%b-%Y",X:"%T",x:"%D"}},pt_BR:{identifier:"pt-BR",days:"domingo segunda ter\u00e7a quarta quinta sexta s\u00e1bado".split(" "),shortDays:"Dom Seg Ter Qua Qui Sex S\u00e1b".split(" "),months:"janeiro fevereiro mar\u00e7o abril maio junho julho agosto setembro outubro novembro dezembro".split(" "),shortMonths:"Jan Fev Mar Abr Mai Jun Jul Ago Set Out Nov Dez".split(" "),AM:"AM",PM:"PM",
|
||||
am:"am",pm:"pm",formats:{c:"%a %d %b %Y %X %Z",D:"%d-%m-%Y",F:"%Y-%m-%d",R:"%H:%M",r:"%I:%M:%S %p",T:"%H:%M:%S",v:"%e-%b-%Y",X:"%T",x:"%D"}},ru_RU:{identifier:"ru-RU",days:"\u0412\u043e\u0441\u043a\u0440\u0435\u0441\u0435\u043d\u044c\u0435 \u041f\u043e\u043d\u0435\u0434\u0435\u043b\u044c\u043d\u0438\u043a \u0412\u0442\u043e\u0440\u043d\u0438\u043a \u0421\u0440\u0435\u0434\u0430 \u0427\u0435\u0442\u0432\u0435\u0440\u0433 \u041f\u044f\u0442\u043d\u0438\u0446\u0430 \u0421\u0443\u0431\u0431\u043e\u0442\u0430".split(" "),
|
||||
shortDays:"\u0412\u0441 \u041f\u043d \u0412\u0442 \u0421\u0440 \u0427\u0442 \u041f\u0442 \u0421\u0431".split(" "),months:"\u042f\u043d\u0432\u0430\u0440\u044c \u0424\u0435\u0432\u0440\u0430\u043b\u044c \u041c\u0430\u0440\u0442 \u0410\u043f\u0440\u0435\u043b\u044c \u041c\u0430\u0439 \u0418\u044e\u043d\u044c \u0418\u044e\u043b\u044c \u0410\u0432\u0433\u0443\u0441\u0442 \u0421\u0435\u043d\u0442\u044f\u0431\u0440\u044c \u041e\u043a\u0442\u044f\u0431\u0440\u044c \u041d\u043e\u044f\u0431\u0440\u044c \u0414\u0435\u043a\u0430\u0431\u0440\u044c".split(" "),
|
||||
shortMonths:"\u044f\u043d\u0432 \u0444\u0435\u0432 \u043c\u0430\u0440 \u0430\u043f\u0440 \u043c\u0430\u0439 \u0438\u044e\u043d \u0438\u044e\u043b \u0430\u0432\u0433 \u0441\u0435\u043d \u043e\u043a\u0442 \u043d\u043e\u044f \u0434\u0435\u043a".split(" "),AM:"AM",PM:"PM",am:"am",pm:"pm",formats:{c:"%a %d %b %Y %X",D:"%d.%m.%y",F:"%Y-%m-%d",R:"%H:%M",r:"%I:%M:%S %p",T:"%H:%M:%S",v:"%e-%b-%Y",X:"%T",x:"%D"}},tr_TR:{identifier:"tr-TR",days:"Pazar Pazartesi Sal\u0131 \u00c7ar\u015famba Per\u015fembe Cuma Cumartesi".split(" "),
|
||||
shortDays:"Paz Pzt Sal \u00c7r\u015f Pr\u015f Cum Cts".split(" "),months:"Ocak \u015eubat Mart Nisan May\u0131s Haziran Temmuz A\u011fustos Eyl\u00fcl Ekim Kas\u0131m Aral\u0131k".split(" "),shortMonths:"Oca \u015eub Mar Nis May Haz Tem A\u011fu Eyl Eki Kas Ara".split(" "),AM:"\u00d6\u00d6",PM:"\u00d6S",am:"\u00d6\u00d6",pm:"\u00d6S",formats:{c:"%a %d %b %Y %X %Z",D:"%d-%m-%Y",F:"%Y-%m-%d",R:"%H:%M",r:"%I:%M:%S %p",T:"%H:%M:%S",v:"%e-%b-%Y",X:"%T",x:"%D"}},zh_CN:{identifier:"zh-CN",days:"\u661f\u671f\u65e5 \u661f\u671f\u4e00 \u661f\u671f\u4e8c \u661f\u671f\u4e09 \u661f\u671f\u56db \u661f\u671f\u4e94 \u661f\u671f\u516d".split(" "),
|
||||
shortDays:"\u65e5\u4e00\u4e8c\u4e09\u56db\u4e94\u516d".split(""),months:"\u4e00\u6708 \u4e8c\u6708 \u4e09\u6708 \u56db\u6708 \u4e94\u6708 \u516d\u6708 \u4e03\u6708 \u516b\u6708 \u4e5d\u6708 \u5341\u6708 \u5341\u4e00\u6708 \u5341\u4e8c\u6708".split(" "),shortMonths:"\u4e00\u6708 \u4e8c\u6708 \u4e09\u6708 \u56db\u6708 \u4e94\u6708 \u516d\u6708 \u4e03\u6708 \u516b\u6708 \u4e5d\u6708 \u5341\u6708 \u5341\u4e00\u6708 \u5341\u4e8c\u6708".split(" "),AM:"\u4e0a\u5348",PM:"\u4e0b\u5348",am:"\u4e0a\u5348",pm:"\u4e0b\u5348",
|
||||
formats:{c:"%a %d %b %Y %X %Z",D:"%d/%m/%y",F:"%Y-%m-%d",R:"%H:%M",r:"%I:%M:%S %p",T:"%H:%M:%S",v:"%e-%b-%Y",X:"%r",x:"%D"}}},F=G.en_US,H=new w(F,0,!1);if("undefined"!==typeof module)var I=module.exports=H;else I=function(){return this||(0,eval)("this")}(),I.strftime=H;"function"!==typeof Date.now&&(Date.now=function(){return+new Date})})();
|
||||
|
|
|
|||
466
strftime.js
466
strftime.js
|
|
@ -3,140 +3,303 @@
|
|||
// github.com/samsonjs/strftime
|
||||
// @_sjs
|
||||
//
|
||||
// Copyright 2010 - 2015 Sami Samhuri <sami@samhuri.net>
|
||||
// Copyright 2010 - 2021 Sami Samhuri <sami@samhuri.net>
|
||||
//
|
||||
// MIT License
|
||||
// http://sjs.mit-license.org
|
||||
//
|
||||
|
||||
;(function() {
|
||||
; (function () {
|
||||
|
||||
var DefaultLocale = {
|
||||
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
||||
shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
||||
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||
var Locales = {
|
||||
de_DE: {
|
||||
identifier: 'de-DE',
|
||||
days: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
|
||||
shortDays: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
|
||||
months: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
|
||||
shortMonths: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
|
||||
AM: 'AM',
|
||||
PM: 'PM',
|
||||
am: 'am',
|
||||
pm: 'pm',
|
||||
formats: {
|
||||
D: '%m/%d/%y',
|
||||
c: '%a %d %b %Y %X %Z',
|
||||
D: '%d.%m.%Y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
T: '%H:%M:%S',
|
||||
X: '%T',
|
||||
c: '%a %b %d %X %Y',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y',
|
||||
X: '%T',
|
||||
x: '%D'
|
||||
}
|
||||
},
|
||||
|
||||
en_CA: {
|
||||
identifier: 'en-CA',
|
||||
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
||||
shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
||||
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||
ordinalSuffixes: [
|
||||
'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th',
|
||||
'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th',
|
||||
'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th',
|
||||
'st'
|
||||
],
|
||||
AM: 'AM',
|
||||
PM: 'PM',
|
||||
am: 'am',
|
||||
pm: 'pm',
|
||||
formats: {
|
||||
c: '%a %d %b %Y %X %Z',
|
||||
D: '%d/%m/%y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y',
|
||||
X: '%r',
|
||||
x: '%D'
|
||||
}
|
||||
},
|
||||
|
||||
en_US: {
|
||||
identifier: 'en-US',
|
||||
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
||||
shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
||||
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||
ordinalSuffixes: [
|
||||
'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th',
|
||||
'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th',
|
||||
'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th', 'th',
|
||||
'st'
|
||||
],
|
||||
AM: 'AM',
|
||||
PM: 'PM',
|
||||
am: 'am',
|
||||
pm: 'pm',
|
||||
formats: {
|
||||
c: '%a %d %b %Y %X %Z',
|
||||
D: '%m/%d/%y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y',
|
||||
X: '%r',
|
||||
x: '%D'
|
||||
}
|
||||
},
|
||||
|
||||
es_MX: {
|
||||
identifier: 'es-MX',
|
||||
days: ['domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado'],
|
||||
shortDays: ['dom', 'lun', 'mar', 'mié', 'jue', 'vie', 'sáb'],
|
||||
months: ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'],
|
||||
shortMonths: ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 'jul', 'ago', 'sep', 'oct', 'nov', 'dic'],
|
||||
AM: 'AM',
|
||||
PM: 'PM',
|
||||
am: 'am',
|
||||
pm: 'pm',
|
||||
formats: {
|
||||
c: '%a %d %b %Y %X %Z',
|
||||
D: '%d/%m/%Y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y',
|
||||
X: '%T',
|
||||
x: '%D'
|
||||
}
|
||||
},
|
||||
|
||||
fr_FR: {
|
||||
identifier: 'fr-FR',
|
||||
days: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
|
||||
shortDays: ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'],
|
||||
months: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
|
||||
shortMonths: ['janv.', 'févr.', 'mars', 'avril', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.'],
|
||||
AM: 'AM',
|
||||
PM: 'PM',
|
||||
am: 'am',
|
||||
pm: 'pm',
|
||||
formats: {
|
||||
c: '%a %d %b %Y %X %Z',
|
||||
D: '%d/%m/%Y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y',
|
||||
X: '%T',
|
||||
x: '%D'
|
||||
}
|
||||
},
|
||||
|
||||
it_IT: {
|
||||
identifier: 'it-IT',
|
||||
days: ['domenica', 'lunedì', 'martedì', 'mercoledì', 'giovedì', 'venerdì', 'sabato'],
|
||||
shortDays: ['dom', 'lun', 'mar', 'mer', 'gio', 'ven', 'sab'],
|
||||
months: ['gennaio', 'febbraio', 'marzo', 'aprile', 'maggio', 'giugno', 'luglio', 'agosto', 'settembre', 'ottobre', 'novembre', 'dicembre'],
|
||||
shortMonths: ['gen', 'feb', 'mar', 'apr', 'mag', 'giu', 'lug', 'ago', 'set', 'ott', 'nov', 'dic'],
|
||||
AM: 'AM',
|
||||
PM: 'PM',
|
||||
am: 'am',
|
||||
pm: 'pm',
|
||||
formats: {
|
||||
c: '%a %d %b %Y %X %Z',
|
||||
D: '%d/%m/%Y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y',
|
||||
X: '%T',
|
||||
x: '%D'
|
||||
}
|
||||
},
|
||||
|
||||
nl_NL: {
|
||||
identifier: 'nl-NL',
|
||||
days: ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'],
|
||||
shortDays: ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'],
|
||||
months: ['januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december'],
|
||||
shortMonths: ['jan', 'feb', 'mrt', 'apr', 'mei', 'jun', 'jul', 'aug', 'sep', 'okt', 'nov', 'dec'],
|
||||
AM: 'AM',
|
||||
PM: 'PM',
|
||||
am: 'am',
|
||||
pm: 'pm',
|
||||
formats: {
|
||||
c: '%a %d %b %Y %X %Z',
|
||||
D: '%d-%m-%y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y',
|
||||
X: '%T',
|
||||
x: '%D'
|
||||
}
|
||||
},
|
||||
|
||||
pt_BR: {
|
||||
identifier: 'pt-BR',
|
||||
days: ['domingo', 'segunda', 'terça', 'quarta', 'quinta', 'sexta', 'sábado'],
|
||||
shortDays: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'],
|
||||
months: ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'],
|
||||
shortMonths: ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],
|
||||
AM: 'AM',
|
||||
PM: 'PM',
|
||||
am: 'am',
|
||||
pm: 'pm',
|
||||
formats: {
|
||||
c: '%a %d %b %Y %X %Z',
|
||||
D: '%d-%m-%Y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y',
|
||||
X: '%T',
|
||||
x: '%D'
|
||||
}
|
||||
},
|
||||
|
||||
ru_RU: {
|
||||
identifier: 'ru-RU',
|
||||
days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'],
|
||||
shortDays: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'],
|
||||
months: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'],
|
||||
shortMonths: ['янв', 'фев', 'мар', 'апр', 'май', 'июн', 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек'],
|
||||
AM: 'AM',
|
||||
PM: 'PM',
|
||||
am: 'am',
|
||||
pm: 'pm',
|
||||
formats: {
|
||||
c: '%a %d %b %Y %X',
|
||||
D: '%d.%m.%y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y',
|
||||
X: '%T',
|
||||
x: '%D'
|
||||
}
|
||||
},
|
||||
|
||||
tr_TR: {
|
||||
identifier: 'tr-TR',
|
||||
days: ['Pazar', 'Pazartesi', 'Salı', 'Çarşamba', 'Perşembe', 'Cuma', 'Cumartesi'],
|
||||
shortDays: ['Paz', 'Pzt', 'Sal', 'Çrş', 'Prş', 'Cum', 'Cts'],
|
||||
months: ['Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık'],
|
||||
shortMonths: ['Oca', 'Şub', 'Mar', 'Nis', 'May', 'Haz', 'Tem', 'Ağu', 'Eyl', 'Eki', 'Kas', 'Ara'],
|
||||
AM: 'ÖÖ',
|
||||
PM: 'ÖS',
|
||||
am: 'ÖÖ',
|
||||
pm: 'ÖS',
|
||||
formats: {
|
||||
c: '%a %d %b %Y %X %Z',
|
||||
D: '%d-%m-%Y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y',
|
||||
X: '%T',
|
||||
x: '%D'
|
||||
}
|
||||
},
|
||||
|
||||
// By michaeljayt<michaeljayt@gmail.com>
|
||||
// https://github.com/michaeljayt/strftime/commit/bcb4c12743811d51e568175aa7bff3fd2a77cef3
|
||||
zh_CN: {
|
||||
identifier: 'zh-CN',
|
||||
days: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
|
||||
shortDays: ['日', '一', '二', '三', '四', '五', '六'],
|
||||
months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
|
||||
shortMonths: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
|
||||
AM: '上午',
|
||||
PM: '下午',
|
||||
am: '上午',
|
||||
pm: '下午',
|
||||
formats: {
|
||||
c: '%a %d %b %Y %X %Z',
|
||||
D: '%d/%m/%y',
|
||||
F: '%Y-%m-%d',
|
||||
R: '%H:%M',
|
||||
r: '%I:%M:%S %p',
|
||||
T: '%H:%M:%S',
|
||||
v: '%e-%b-%Y',
|
||||
X: '%r',
|
||||
x: '%D'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var DefaultLocale = Locales['en_US'],
|
||||
defaultStrftime = new Strftime(DefaultLocale, 0, false),
|
||||
isCommonJS = typeof module !== 'undefined',
|
||||
namespace;
|
||||
|
||||
// CommonJS / Node module
|
||||
if (isCommonJS) {
|
||||
namespace = module.exports = adaptedStrftime;
|
||||
namespace.strftime = deprecatedStrftime;
|
||||
namespace = module.exports = defaultStrftime;
|
||||
}
|
||||
// Browsers and other environments
|
||||
else {
|
||||
// Get the global object. Works in ES3, ES5, and ES5 strict mode.
|
||||
namespace = (function() { return this || (1,eval)('this'); }());
|
||||
namespace.strftime = adaptedStrftime;
|
||||
namespace = (function () { return this || (1, eval)('this'); }());
|
||||
namespace.strftime = defaultStrftime;
|
||||
}
|
||||
|
||||
// Deprecated API, to be removed in v1.0
|
||||
var _require = isCommonJS ? "require('strftime')" : "strftime";
|
||||
var _deprecationWarnings = {};
|
||||
function deprecationWarning(name, instead) {
|
||||
if (!_deprecationWarnings[name]) {
|
||||
if (typeof console !== 'undefined' && typeof console.warn == 'function') {
|
||||
console.warn("[WARNING] " + name + " is deprecated and will be removed in version 1.0. Instead, use `" + instead + "`.");
|
||||
}
|
||||
_deprecationWarnings[name] = true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace.strftimeTZ = deprecatedStrftimeTZ;
|
||||
namespace.strftimeUTC = deprecatedStrftimeUTC;
|
||||
namespace.localizedStrftime = deprecatedStrftimeLocalized;
|
||||
|
||||
// Adapt the old API while preserving the new API.
|
||||
function adaptForwards(fn) {
|
||||
fn.localize = defaultStrftime.localize.bind(defaultStrftime);
|
||||
fn.timezone = defaultStrftime.timezone.bind(defaultStrftime);
|
||||
fn.utc = defaultStrftime.utc.bind(defaultStrftime);
|
||||
}
|
||||
|
||||
adaptForwards(adaptedStrftime);
|
||||
function adaptedStrftime(fmt, d, locale) {
|
||||
// d and locale are optional, check if this is (format, locale)
|
||||
if (d && d.days) {
|
||||
locale = d;
|
||||
d = undefined;
|
||||
}
|
||||
if (locale) {
|
||||
deprecationWarning("`" + _require + "(format, [date], [locale])`", "var s = " + _require + ".localize(locale); s(format, [date])");
|
||||
}
|
||||
var strftime = locale ? defaultStrftime.localize(locale) : defaultStrftime;
|
||||
return strftime(fmt, d);
|
||||
}
|
||||
|
||||
adaptForwards(deprecatedStrftime);
|
||||
function deprecatedStrftime(fmt, d, locale) {
|
||||
if (locale) {
|
||||
deprecationWarning("`" + _require + ".strftime(format, [date], [locale])`", "var s = " + _require + ".localize(locale); s(format, [date])");
|
||||
}
|
||||
else {
|
||||
deprecationWarning("`" + _require + ".strftime(format, [date])`", _require + "(format, [date])");
|
||||
}
|
||||
var strftime = locale ? defaultStrftime.localize(locale) : defaultStrftime;
|
||||
return strftime(fmt, d);
|
||||
}
|
||||
|
||||
function deprecatedStrftimeTZ(fmt, d, locale, timezone) {
|
||||
// locale is optional, check if this is (format, date, timezone)
|
||||
if ((typeof locale == 'number' || typeof locale == 'string') && timezone == null) {
|
||||
timezone = locale;
|
||||
locale = undefined;
|
||||
}
|
||||
|
||||
if (locale) {
|
||||
deprecationWarning("`" + _require + ".strftimeTZ(format, date, locale, tz)`", "var s = " + _require + ".localize(locale).timezone(tz); s(format, [date])` or `var s = " + _require + ".localize(locale); s.timezone(tz)(format, [date])");
|
||||
}
|
||||
else {
|
||||
deprecationWarning("`" + _require + ".strftimeTZ(format, date, tz)`", "var s = " + _require + ".timezone(tz); s(format, [date])` or `" + _require + ".timezone(tz)(format, [date])");
|
||||
}
|
||||
|
||||
var strftime = (locale ? defaultStrftime.localize(locale) : defaultStrftime).timezone(timezone);
|
||||
return strftime(fmt, d);
|
||||
};
|
||||
|
||||
var utcStrftime = defaultStrftime.utc();
|
||||
function deprecatedStrftimeUTC(fmt, d, locale) {
|
||||
if (locale) {
|
||||
deprecationWarning("`" + _require + ".strftimeUTC(format, date, locale)`", "var s = " + _require + ".localize(locale).utc(); s(format, [date])");
|
||||
}
|
||||
else {
|
||||
deprecationWarning("`" + _require + ".strftimeUTC(format, [date])`", "var s = " + _require + ".utc(); s(format, [date])");
|
||||
}
|
||||
var strftime = locale ? utcStrftime.localize(locale) : utcStrftime;
|
||||
return strftime(fmt, d);
|
||||
};
|
||||
|
||||
function deprecatedStrftimeLocalized(locale) {
|
||||
deprecationWarning("`" + _require + ".localizedStrftime(locale)`", _require + ".localize(locale)");
|
||||
return defaultStrftime.localize(locale);
|
||||
};
|
||||
// End of deprecated API
|
||||
|
||||
// Polyfill Date.now for old browsers.
|
||||
if (typeof Date.now !== 'function') {
|
||||
Date.now = function() {
|
||||
return +new Date();
|
||||
Date.now = function () {
|
||||
return +new Date();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -169,13 +332,23 @@
|
|||
_cachedDate = new Date(_cachedDateTimestamp + getTimestampToUtcOffsetFor(_cachedDate) + _customTimezoneOffset);
|
||||
}
|
||||
}
|
||||
else {
|
||||
timestamp = _cachedDateTimestamp;
|
||||
}
|
||||
date = _cachedDate;
|
||||
}
|
||||
else {
|
||||
timestamp = date.getTime();
|
||||
|
||||
if (_useUtcBasedDate) {
|
||||
date = new Date(date.getTime() + getTimestampToUtcOffsetFor(date) + _customTimezoneOffset);
|
||||
var utcOffset = getTimestampToUtcOffsetFor(date);
|
||||
date = new Date(timestamp + utcOffset + _customTimezoneOffset);
|
||||
// If we've crossed a DST boundary with this calculation we need to
|
||||
// adjust the new date accordingly or it will be off by an hour in UTC.
|
||||
if (getTimestampToUtcOffsetFor(date) !== utcOffset) {
|
||||
var newUTCOffset = getTimestampToUtcOffsetFor(date);
|
||||
date = new Date(timestamp + newUTCOffset + _customTimezoneOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -211,14 +384,23 @@
|
|||
}
|
||||
// ':'
|
||||
else if (currentCharCode === 58) {
|
||||
extendedTZ = true;
|
||||
continue;
|
||||
if (extendedTZ) {
|
||||
warn("[WARNING] detected use of unsupported %:: or %::: modifiers to strftime");
|
||||
}
|
||||
extendedTZ = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (currentCharCode) {
|
||||
|
||||
// Examples for new Date(0) in GMT
|
||||
|
||||
// '%'
|
||||
// case '%':
|
||||
case 37:
|
||||
resultString += '%';
|
||||
break;
|
||||
|
||||
// 'Thursday'
|
||||
// case 'A':
|
||||
case 65:
|
||||
|
|
@ -328,9 +510,8 @@
|
|||
resultString += "GMT";
|
||||
}
|
||||
else {
|
||||
// fixme optimize
|
||||
var tzString = date.toString().match(/\(([\w\s]+)\)/);
|
||||
resultString += tzString && tzString[1] || '';
|
||||
var tzName = getTimezoneName(date);
|
||||
resultString += tzName || '';
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -405,7 +586,15 @@
|
|||
// '1st'
|
||||
// case 'o':
|
||||
case 111:
|
||||
resultString += String(date.getDate()) + ordinal(date.getDate());
|
||||
// Try to use an ordinal suffix from the locale, but fall back to using the old
|
||||
// function for compatibility with old locales that lack them.
|
||||
var day = date.getDate();
|
||||
if (locale.ordinalSuffixes) {
|
||||
resultString += String(day) + (locale.ordinalSuffixes[day - 1] || ordinal(day));
|
||||
}
|
||||
else {
|
||||
resultString += String(day) + ordinal(day);
|
||||
}
|
||||
break;
|
||||
|
||||
// 'AM'
|
||||
|
|
@ -460,7 +649,7 @@
|
|||
// '70'
|
||||
// case 'y':
|
||||
case 121:
|
||||
resultString += ('' + date.getFullYear()).slice(2);
|
||||
resultString += padTill2(date.getFullYear() % 100, padding);
|
||||
break;
|
||||
|
||||
// '+0000'
|
||||
|
|
@ -486,6 +675,9 @@
|
|||
break;
|
||||
|
||||
default:
|
||||
if (isInScope) {
|
||||
resultString += '%';
|
||||
}
|
||||
resultString += format[i];
|
||||
break;
|
||||
}
|
||||
|
|
@ -509,11 +701,20 @@
|
|||
|
||||
var strftime = _strftime;
|
||||
|
||||
strftime.localize = function(locale) {
|
||||
strftime.localize = function (locale) {
|
||||
return new Strftime(locale || _locale, _customTimezoneOffset, _useUtcBasedDate);
|
||||
};
|
||||
|
||||
strftime.timezone = function(timezone) {
|
||||
strftime.localizeByIdentifier = function (localeIdentifier) {
|
||||
var locale = Locales[localeIdentifier];
|
||||
if (!locale) {
|
||||
warn('[WARNING] No locale found with identifier "' + localeIdentifier + '".');
|
||||
return strftime;
|
||||
}
|
||||
return strftime.localize(locale);
|
||||
};
|
||||
|
||||
strftime.timezone = function (timezone) {
|
||||
var customTimezoneOffset = _customTimezoneOffset;
|
||||
var useUtcBasedDate = _useUtcBasedDate;
|
||||
|
||||
|
|
@ -538,7 +739,7 @@
|
|||
return new Strftime(_locale, customTimezoneOffset, useUtcBasedDate);
|
||||
};
|
||||
|
||||
strftime.utc = function() {
|
||||
strftime.utc = function () {
|
||||
return new Strftime(_locale, _customTimezoneOffset, true);
|
||||
};
|
||||
|
||||
|
|
@ -547,7 +748,7 @@
|
|||
|
||||
function padTill2(numberToPad, paddingChar) {
|
||||
if (paddingChar === '' || numberToPad > 9) {
|
||||
return numberToPad;
|
||||
return '' + numberToPad;
|
||||
}
|
||||
if (paddingChar == null) {
|
||||
paddingChar = '0';
|
||||
|
|
@ -590,8 +791,10 @@
|
|||
else
|
||||
weekday--;
|
||||
}
|
||||
var firstDayOfYear = new Date(date.getFullYear(), 0, 1),
|
||||
yday = (date - firstDayOfYear) / 86400000,
|
||||
|
||||
var firstDayOfYearUtc = Date.UTC(date.getFullYear(), 0, 1),
|
||||
dateUtc = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()),
|
||||
yday = Math.floor((dateUtc - firstDayOfYearUtc) / 86400000),
|
||||
weekNum = (yday + 7 - weekday) / 7;
|
||||
|
||||
return Math.floor(weekNum);
|
||||
|
|
@ -616,4 +819,35 @@
|
|||
return (date.getTimezoneOffset() || 0) * 60000;
|
||||
}
|
||||
|
||||
// Tries to get a short timezone name using Date.toLocaleString, falling back on the platform default
|
||||
// using Date.toString if necessary.
|
||||
function getTimezoneName(date, localeIdentifier) {
|
||||
return getShortTimezoneName(date, localeIdentifier) || getDefaultTimezoneName(date);
|
||||
}
|
||||
|
||||
// Unfortunately this returns GMT+2 when running with `TZ=Europe/Amsterdam node test.js` so it's not
|
||||
// perfect.
|
||||
function getShortTimezoneName(date, localeIdentifier) {
|
||||
if (localeIdentifier == null) return null;
|
||||
|
||||
var tzString = date
|
||||
.toLocaleString(localeIdentifier, { timeZoneName: 'short' })
|
||||
.match(/\s([\w]+)$/);
|
||||
return tzString && tzString[1];
|
||||
}
|
||||
|
||||
// This varies by platform so it's not an ideal way to get the time zone name. On most platforms it's
|
||||
// a short name but in Node v10+ and Chrome 66+ it's a long name now. Prefer getShortTimezoneName(date)
|
||||
// where possible.
|
||||
function getDefaultTimezoneName(date) {
|
||||
var tzString = date.toString().match(/\(([\w\s]+)\)/);
|
||||
return tzString && tzString[1];
|
||||
}
|
||||
|
||||
function warn(message) {
|
||||
if (typeof console !== 'undefined' && typeof console.warn == 'function') {
|
||||
console.warn(message)
|
||||
}
|
||||
}
|
||||
|
||||
}());
|
||||
|
|
|
|||
75
test.js
75
test.js
|
|
@ -13,12 +13,12 @@ var assert = require('assert'),
|
|||
Time = new Date(1307472705067); // Tue, 07 Jun 2011 18:51:45 GMT
|
||||
|
||||
assert.fn = function(value, msg) {
|
||||
assert.equal('function', typeof value, msg);
|
||||
assert.equal(typeof value, 'function', msg);
|
||||
};
|
||||
|
||||
function assertFormat(time, format, expected, name, strftime) {
|
||||
var actual = strftime(format, time);
|
||||
assert.equal(expected, actual, name + '("' + format + '", ' + time + ') is ' + JSON.stringify(actual) + ', expected ' + JSON.stringify(expected));
|
||||
assert.equal(actual, expected, name + '("' + format + '", ' + time + ') is ' + JSON.stringify(actual) + ', expected ' + JSON.stringify(expected));
|
||||
}
|
||||
|
||||
assert.format = function(format, expected, expectedUTC, time) {
|
||||
|
|
@ -27,13 +27,6 @@ assert.format = function(format, expected, expectedUTC, time) {
|
|||
assertFormat(time, format, expectedUTC || expected, 'strftime.utc()', strftimeUTC);
|
||||
};
|
||||
|
||||
/// check deprecated exports
|
||||
assert.fn(strftime.strftime);
|
||||
assert.fn(strftime.strftimeTZ);
|
||||
assert.fn(strftime.strftimeUTC);
|
||||
assert.fn(strftime.localizedStrftime);
|
||||
ok('Deprecated exports');
|
||||
|
||||
/// check exports
|
||||
assert.fn(strftime.localize);
|
||||
assert.fn(strftime.timezone);
|
||||
|
|
@ -42,25 +35,45 @@ ok('Exports');
|
|||
|
||||
/// time zones
|
||||
if (process.env.TZ == 'America/Vancouver') {
|
||||
testTimezone('P[DS]T');
|
||||
testTimezone('America/Vancouver');
|
||||
assert.format('%C', '01', '01', new Date(100, 0, 1));
|
||||
assert.format('%X', '11:51:45', '18:51:45');
|
||||
assert.format('%c', 'Tue Jun 07 11:51:45 2011', 'Tue Jun 07 18:51:45 2011');
|
||||
assert.format('%X', '11:51:45 AM', '06:51:45 PM');
|
||||
assert.format('%c', 'Tue 07 Jun 2011 11:51:45 AM Pacific Daylight Saving Time', 'Tue 07 Jun 2011 06:51:45 PM GMT');
|
||||
assert.format('%j', '097', '098', new Date(1365390736236));
|
||||
assert.format('%x', '06/07/11');
|
||||
assert.format('%U', '12', null, new Date('2017-03-25 00:00:00 +0000'));
|
||||
assert.format('%U', '12', '13', new Date('2017-03-26 00:00:00 +0000'));
|
||||
assert.format('%U', '13', null, new Date('2017-03-27 00:00:00 +0000'));
|
||||
assert.format('%U', '13', '14', new Date('2017-04-02 00:00:00 +0000'));
|
||||
|
||||
// Test dates crossing a DST boundary.
|
||||
var dstStart = +new Date('2016-11-06 01:50:00');
|
||||
assert.format('%T', '01:50:00', '08:50:00', new Date(dstStart))
|
||||
assert.format('%T', '01:00:00', '09:00:00', new Date(dstStart + 10 * 60 * 1000))
|
||||
|
||||
ok('Time zones (' + process.env.TZ + ')');
|
||||
}
|
||||
else if (process.env.TZ == 'CET') {
|
||||
testTimezone('CES?T');
|
||||
else if (process.env.TZ == 'Europe/Amsterdam') {
|
||||
testTimezone('Europe/Amsterdam');
|
||||
assert.format('%C', '01', '00', new Date(100, 0, 1));
|
||||
assert.format('%X', '20:51:45', '18:51:45');
|
||||
assert.format('%c', 'Tue Jun 07 20:51:45 2011', 'Tue Jun 07 18:51:45 2011');
|
||||
assert.format('%X', '08:51:45 PM', '06:51:45 PM');
|
||||
assert.format('%c', 'Tue 07 Jun 2011 08:51:45 PM Central European Summer Time', 'Tue 07 Jun 2011 06:51:45 PM GMT');
|
||||
assert.format('%j', '098', '098', new Date(1365390736236));
|
||||
assert.format('%x', '06/07/11');
|
||||
assert.format('%U', '12', null, new Date('2017-03-25 00:00:00 +0000'));
|
||||
assert.format('%U', '13', null, new Date('2017-03-26 00:00:00 +0000'));
|
||||
assert.format('%U', '13', null, new Date('2017-03-27 00:00:00 +0000'));
|
||||
assert.format('%U', '14', null, new Date('2017-04-02 00:00:00 +0000'));
|
||||
|
||||
// Test dates crossing a DST boundary.
|
||||
var dstStart = +new Date('2016-10-30 02:50:00');
|
||||
assert.format('%T', '02:50:00', '00:50:00', new Date(dstStart))
|
||||
assert.format('%T', '02:00:00', '01:00:00', new Date(dstStart + 10 * 60 * 1000))
|
||||
|
||||
ok('Time zones (' + process.env.TZ + ')');
|
||||
}
|
||||
else {
|
||||
console.log('(Current timezone has no tests: ' + (process.env.TZ || 'none') + ')');
|
||||
assert(false, '(Current timezone has no tests: ' + (process.env.TZ || 'none') + ')');
|
||||
}
|
||||
|
||||
/// check all formats in GMT, most coverage
|
||||
|
|
@ -87,6 +100,8 @@ assert.format('%k', null, '18');
|
|||
assert.format('%L', '067');
|
||||
assert.format('%l', null, ' 6');
|
||||
assert.format('%-l', null, '6');
|
||||
assert.format("%-y", "1", null, new Date('2001-02-03T04:05:06'))
|
||||
assert.format("%-y", "23", null, new Date('2023-02-03T04:05:06'))
|
||||
assert.format('%_l', null, ' 6');
|
||||
assert.format('%0l', null, '06');
|
||||
assert.format('%M', null, '51');
|
||||
|
|
@ -113,8 +128,13 @@ assert.format('%y', '11');
|
|||
assert.format('%Z', null, 'GMT');
|
||||
assert.format('%z', null, '+0000');
|
||||
assert.format('%:z', null, '+00:00');
|
||||
assert.format('%%', '%'); // any other char
|
||||
assert.format('%%', '%'); // literal percent sign
|
||||
assert.format('%g', '%g'); // unrecognized directive
|
||||
assert.format('%F %T', null, '1970-01-01 00:00:00', new Date(0));
|
||||
assert.format('%U', null, '12', new Date('2017-03-25 00:00:00 +0000'));
|
||||
assert.format('%U', null, '13', new Date('2017-03-26 00:00:00 +0000'));
|
||||
assert.format('%U', null, '13', new Date('2017-03-27 00:00:00 +0000'));
|
||||
assert.format('%U', null, '14', new Date('2017-04-02 00:00:00 +0000'));
|
||||
ok('GMT');
|
||||
|
||||
|
||||
|
|
@ -183,6 +203,25 @@ assert.formatTZ('%F %r %z', '2011-06-07 11:21:45 AM -0730', '-0730');
|
|||
assert.formatTZ('%F %r %:z', '2011-06-07 11:21:45 AM -07:30', '-0730');
|
||||
ok('Time zone offset');
|
||||
|
||||
/// caching
|
||||
(function() {
|
||||
// this test fails when the 2 calls cross a millisecond boundary, so try a number of times
|
||||
var CacheAttempts = 10;
|
||||
var MaxFailures = 1;
|
||||
var failures = 0;
|
||||
for (var i = 0; i < CacheAttempts; ++i) {
|
||||
var expectedMillis = strftime('%L');
|
||||
var millis = strftime('%L');
|
||||
if (expectedMillis != millis) {
|
||||
++failures;
|
||||
}
|
||||
}
|
||||
if (failures > MaxFailures) {
|
||||
assert.fail('timestamp caching appears to be broken (' + failures + ' failed attempts out of ' + CacheAttempts + ')');
|
||||
}
|
||||
}());
|
||||
ok('Cached timestamps');
|
||||
|
||||
|
||||
/// helpers
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue