├── .coveralls.yml
├── .gitignore
├── .travis.yml
├── Gruntfile.js
├── LICENSE
├── README.md
├── _config.yml
├── package.json
├── protodate.js
├── protodate.min.js
├── protodate.tz.full.js
├── protodate.tz.full.min.js
├── protodate.tz.js
├── protodate.tz.min.js
├── src
├── constants.js
├── elapsedSince.js
├── export.js
├── format.js
├── fromDate.js
├── getUnixTimestamp.js
├── guessFormat.js
├── isDate.js
├── minus.js
├── parse.js
├── plus.js
├── timezones
│ ├── data
│ │ ├── timezonedb.sql
│ │ ├── tzdata-1835-2500.js
│ │ ├── tzdata-2012-2022.js
│ │ └── tzdata.sh
│ ├── getTZInfo.js
│ ├── getTimezone.js
│ ├── isDST.js
│ ├── isDSTObserved.js
│ └── setTimezone.js
├── toDate.js
└── validateFormat.js
└── test
└── test.js
/.coveralls.yml:
--------------------------------------------------------------------------------
1 |
2 | repo_token: l45g0zCqrDu1SAcTEAn84ArcW1DnbeKMl
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /test/prod.js
2 | /nbproject/
3 | package-lock.json
4 | node_modules
5 | coverage
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 |
2 | language: node_js
3 | node_js:
4 | - "node"
5 | script: npm run coverage
6 | after_success: 'npm run coveralls'
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | module.exports = function(grunt) {
2 |
3 | var pkg = grunt.file.readJSON('package.json');
4 | pkg.version = pkg.version.split(".");
5 | var subversion = pkg.version.pop();
6 | subversion++;
7 | pkg.version.push(subversion);
8 | pkg.version = pkg.version.join(".");
9 | grunt.file.write('package.json', JSON.stringify(pkg, null, 2));
10 |
11 | console.log("---------------------------------------");
12 | console.log(" Building protodate Version "+pkg.version);
13 | console.log("---------------------------------------");
14 |
15 | var src_files = [
16 | 'src/constants.js',
17 | 'src/getUnixTimestamp.js',
18 | 'src/isDate.js',
19 | 'src/format.js',
20 | 'src/validateFormat.js',
21 | 'src/parse.js',
22 | 'src/elapsedSince.js',
23 | 'src/minus.js',
24 | 'src/plus.js',
25 | 'src/guessFormat.js',
26 | 'src/toDate.js',
27 | 'src/fromDate.js'
28 | ];
29 |
30 | var ts_src_files = [
31 | 'src/timezones/getTZInfo.js',
32 | 'src/timezones/setTimezone.js',
33 | 'src/timezones/getTimezone.js',
34 | 'src/timezones/isDST.js',
35 | 'src/timezones/isDSTObserved.js'
36 | ];
37 |
38 | grunt.initConfig({
39 | pkg: pkg,
40 | concat: {
41 | lite: {
42 | options: {
43 | banner: '/**\n * <%= pkg.name %> (lite) - v<%= pkg.version %>' +
44 | '\n * <%= pkg.description %>' +
45 | '\n * @author <%= pkg.author %>' +
46 | '\n * @website <%= pkg.homepage %>' +
47 | '\n * @license <%= pkg.license %>' +
48 | '\n */\n\n'
49 | },
50 | src: [...src_files,'src/export.js'],
51 | dest: 'protodate.js',
52 | },
53 | tz1: {
54 | options: {
55 | banner: '/**\n * <%= pkg.name %> (timezones 2012-2022) - v<%= pkg.version %>' +
56 | '\n * <%= pkg.description %>' +
57 | '\n * @author <%= pkg.author %>' +
58 | '\n * @website <%= pkg.homepage %>' +
59 | '\n * @license <%= pkg.license %>' +
60 | '\n */\n\n'
61 | },
62 | src: [...src_files,'src/timezones/data/tzdata-2012-2022.js',...ts_src_files,'src/export.js'],
63 | dest: 'protodate.tz.js',
64 | },
65 | tz2: {
66 | options: {
67 | banner: '/**\n * <%= pkg.name %> (timezones 1835-2500) - v<%= pkg.version %>' +
68 | '\n * <%= pkg.description %>' +
69 | '\n * @author <%= pkg.author %>' +
70 | '\n * @website <%= pkg.homepage %>' +
71 | '\n * @license <%= pkg.license %>' +
72 | '\n */\n\n'
73 | },
74 | src: [...src_files,'src/timezones/data/tzdata-1835-2500.js',...ts_src_files,'src/export.js'],
75 | dest: 'protodate.tz.full.js',
76 | }
77 | },
78 | 'string-replace': {
79 | source: {
80 | files: {
81 | "protodate.js": "protodate.js",
82 | "protodate.tz.js": "protodate.tz.js",
83 | "protodate.tz.full.js": "protodate.tz.full.js"
84 | },
85 | options: {
86 | replacements: [{
87 | pattern: /{{ VERSION }}/g,
88 | replacement: '<%= pkg.version %>'
89 | }]
90 | }
91 | },
92 | readme: {
93 | files: {
94 | "README.md": "README.md"
95 | },
96 | options: {
97 | replacements: [{
98 | pattern: /v\d+.\d+.\d+/g,
99 | replacement: 'v<%= pkg.version %>'
100 | }]
101 | }
102 | }
103 | },
104 | uglify: {
105 | lite: {
106 | options: {
107 | banner: '/*! <%= pkg.name %> (lite) - v<%= pkg.version %> */'
108 | },
109 | src: 'protodate.js',
110 | dest: 'protodate.min.js'
111 | },
112 | tz1: {
113 | options: {
114 | banner: '/*! <%= pkg.name %> (+timezones) - v<%= pkg.version %> */'
115 | },
116 | src: 'protodate.tz.js',
117 | dest: 'protodate.tz.min.js'
118 | },
119 | tz2: {
120 | options: {
121 | banner: '/*! <%= pkg.name %> (+timezones) - v<%= pkg.version %> */'
122 | },
123 | src: 'protodate.tz.full.js',
124 | dest: 'protodate.tz.full.min.js'
125 | }
126 | }
127 | });
128 |
129 | grunt.loadNpmTasks('grunt-contrib-concat');
130 | grunt.loadNpmTasks('grunt-string-replace');
131 | grunt.loadNpmTasks('grunt-contrib-uglify-es');
132 |
133 | grunt.registerTask('default', [
134 | 'concat:lite',
135 | 'concat:tz1',
136 | 'concat:tz2',
137 | 'string-replace',
138 | 'uglify:lite',
139 | 'uglify:tz1',
140 | 'uglify:tz2'
141 | ]);
142 |
143 | };
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2018 Rob Parham
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | 
4 |
5 | [](https://badge.fury.io/js/protodate) [](https://travis-ci.org/Pamblam/protodate) [](https://coveralls.io/github/Pamblam/protodate) v3.0.8
6 |
7 | Better Javascript Dates.
8 |
9 | ## Contents
10 | - [**Intro**](#overview)
11 | - [**Choose Your File**](#choose-your-file)
12 | - [**Usage**](#usage)
13 | - [**Formatting Dates**](#formatting-dates)
14 | - [**Parsing Dates**](#parsing-dates)
15 | - [**Manipulating Dates**](#mainpulating-dates)
16 | - [**Converting Timezones**](#converting-timezones)
17 | - [**Type Conversion**](#type-conversion)
18 | - [**Formatting Characters**](#formatting-characters)
19 | - [**Timezone Reference**](#timezone-reference)
20 | - [**License**](#license)
21 |
22 | ## Intro
23 |
24 | ProtoDate is a very fast and lightweight solution for building, parsing, manipulating and formatting Javascript Dates. ProtoDate extends the native JS Date object (without modifying the original prototype) for ease of use and to keep the library light. By leveraging native, low-level code ProtoDate is able to achieve unprecedented speeds.
25 |
26 | Compare ProtoDate to Moment.js:
27 |
28 | | ProtoDate | Moment.js |
29 | | --- | --- |
30 | | Parses Dates more than **2x faster** | Slower |
31 | | Calculates elapsed time nearly **20x faster** | Much slower |
32 | | Base lib minified @ 9.6kb (**1/5th the size**) | Minified @ 50.43kb |
33 | | [**100% code coverage**](https://coveralls.io/github/Pamblam/protodate) | [only 94.6% code coverage](https://coveralls.io/github/moment/moment) |
34 | | Timezone support from 1835-2500 (**665yr Range**) | Timezone support from 2012-2022 (**10yr Range**) |
35 |
36 | [Check out the benchmarks](https://jsperf.com/protodate-v-moment-js/1).
37 |
38 | Also, if you happened to be a PHP developer, you're in luck because ProtoDate uses the same [date formatting](#formatting-characters) as PHP's native `date` function.
39 |
40 | ## Choose Your File
41 |
42 | ProtoDate has 6 different versions so you only have to download what you need.
43 |
44 | - [protodate.min.js](https://github.com/Pamblam/protodate/blob/master/protodate.min.js)
45 | - [protodate.js](https://github.com/Pamblam/protodate/blob/master/protodate.js)
46 | - [protodate.tz.min.js](https://github.com/Pamblam/protodate/blob/master/protodate.tz.min.js)
47 | - [protodate.tz.js](https://github.com/Pamblam/protodate/blob/master/protodate.tz.js)
48 | - [protodate.tz.full.js](https://github.com/Pamblam/protodate/blob/master/protodate.tz.full.js)
49 | - [protodate.tz.full.min.js](https://github.com/Pamblam/protodate/blob/master/protodate.tz.full.min.js)
50 |
51 | Here's a helpful flow chart to help you choose which file best fits your needs:
52 |
53 | 
54 |
55 | ## Usage
56 |
57 | #### Browsers:
58 |
59 | Download and include the js file that [best fits your needs](#choose-your-file) and include it in your markup.
60 |
61 |
62 |
63 | #### Node
64 |
65 | Install the library with `npm install protodate` and `require` the file that [best fits your needs](#choose-your-file) in your script.
66 |
67 | const ProtoDate = require('protodate.js');
68 |
69 | ## Formatting Dates
70 |
71 | Use the [`format(formatStr)`](https://github.com/Pamblam/protodate/wiki#new-dateformatformatstr) method to format dates as strings. Use the [Formatting Characters Table](#formatting-characters) to build your format string.
72 |
73 | **Example**: `new ProtoDate().format("m/d/y g:i a")`
74 |
75 | ## Parsing Dates
76 |
77 | Use the [`parse(dateStr[, formatStr])`](https://github.com/Pamblam/protodate/wiki#dateparsedatestr-formatstr) method to create a ProtoDate object from a string. If you provide a format string to the method, parsing will be much faster, but ProtoDate is smart enough to guess just about any format without it. Use any of the parsable formatting characters to create a [format string](#formatting-characters).
78 |
79 | **Example**: `Protodate.parse("January 3rd 2007 @ 4 o'clock")`
80 |
81 | ## Manipulating Dates
82 |
83 | Use the [`plus(quantity, period)`](https://github.com/Pamblam/protodate/wiki#new-dateplusquantity-period) and [`minus(quantity, period)`](https://github.com/Pamblam/protodate/wiki#new-dateminusquantity-period) methods to add and subtract time from a Date instance.
84 |
85 | The `period` parameter is the unit of time to add or subtract, and the quantity parameter is how many of them to add or subtract. Specify the period parameter with using one of the 6 [Date Period Constants](https://github.com/Pamblam/protodate/wiki#constants), (ie, [`ProtoDate.MILLISECOND`](https://github.com/Pamblam/protodate/wiki#datemillisecond), [`ProtoDate.SECOND`](https://github.com/Pamblam/protodate/wiki#datesecond), [`ProtoDate.MINUTE`](https://github.com/Pamblam/protodate/wiki#dateminute), [`ProtoDate.HOUR`](https://github.com/Pamblam/protodate/wiki#datehour), [`ProtoDate.DAY`](https://github.com/Pamblam/protodate/wiki#dateday), [`ProtoDate.YEAR`](https://github.com/Pamblam/protodate/wiki#dateyear)).
86 |
87 | **Example**: `new ProtoDate().add(3, ProtoDate.DAY) // 3 days from now`
88 |
89 | ## Converting Timezones
90 |
91 | *This functionality is only available in the `protodate.tz.*` files*
92 |
93 | You can convert dates to other timezones with the [`setTimezone(timezone)`](https://github.com/Pamblam/protodate/wiki#new-datesettimezonetimezone) method.
94 |
95 | **Example**: `new ProtoDate().setTimezone('Asia/Hong_Kong').toString() // Current time in Hong Kong`
96 |
97 | ## Type Conversion
98 |
99 | Generally, you should never need to convert a ProtoDate object to a native Date object since ProtoDate extends Date - it has all the same methods, but these functions are provided as a convenience.
100 |
101 | ### Converting ProtoDate to native Date
102 |
103 | **Example**: `const date = protodate.toDate();`
104 |
105 | ### Converting Date to ProtoDate
106 |
107 | **Example**: `const protodate = ProtoDate.fromDate(date);`
108 |
109 | ## Formatting Characters
110 |
111 | Each character represents part of a date format string. Characters listed as *Parsable* are understood by the `parse` method. All other characters, as well as characters escaped with a `\` in the format string will be printed as-is.
112 |
113 | | format character | Description | Example returned values | Parsable |
114 | | ------------- | ------------- | -------------- | -------------- |
115 | | **Day** | **--** | **--** | **--** |
116 | | *d* | Day of the month, 2 digits with leading zeros | 01 to 31 | ✔ |
117 | | *D* | A textual representation of a day, three letters | Mon through Sun | ✔ |
118 | | *j* | Day of the month without leading zeros | 1 to 31 | ✔ |
119 | | *l* (lowercase 'L') | A full textual representation of the day of the week | Sunday through Saturday | ✔ |
120 | | *N* | ISO-8601 numeric representation of the day of the week | 1 (for Monday) through 7 (for Sunday) | ✕ |
121 | | *S* | English ordinal suffix for the day of the month, 2 characters | st, nd, rd or th. Works well with j | ✔ |
122 | | *w* | Numeric representation of the day of the week | 0 (for Sunday) through 6 (for Saturday) | ✕ |
123 | | *z* | The day of the year (starting from 0) | 0 through 365 |
124 | | **Week** | **--** | **--** | **--** |
125 | | *W* | ISO-8601 week number of year, weeks starting on Monday | Example: 42 (the 42nd week in the year) | ✕ |
126 | | **Month** | **--** | **--** | **--** |
127 | | *F* | A full textual representation of a month, such as January or March | January through December | ✔ |
128 | | *m* | Numeric representation of a month, with leading zeros | 01 through 12 | ✔ |
129 | | *M* | A short textual representation of a month, three letters | Jan through Dec | ✔ |
130 | | *n* | Numeric representation of a month, without leading zeros | 1 through 12 | ✔ |
131 | | *t* | Number of days in the given month | 28 through 31 | ✕ |
132 | | **Year** | **--** | **--** | **--** |
133 | | *L* | Whether it's a leap year | 1 if it is a leap year, 0 otherwise. | ✕ |
134 | | *o* | ISO-8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. | Examples: 1999 or 2003 | ✕ |
135 | | *Y* | A full numeric representation of a year, 4 digits | Examples: 1999 or 2003 | ✔ |
136 | | *y* | A two digit representation of a year | Examples: 99 or 03 | ✔ |
137 | | **Time** | **--** | **--** | **--** |
138 | | *a* | Lowercase Ante meridiem and Post meridiem | am or pm | ✔ |
139 | | *A* | Uppercase Ante meridiem and Post meridiem | AM or PM | ✔ |
140 | | *B* | Swatch Internet time | 000 through 999 | ✕ |
141 | | *g* | 12-hour format of an hour without leading zeros | 1 through 12 | ✔ |
142 | | *G* | 24-hour format of an hour without leading zeros | 0 through 23 | ✔ |
143 | | *h* | 12-hour format of an hour with leading zeros | 01 through 12 | ✔ |
144 | | *H* | 24-hour format of an hour with leading zeros | 00 through 23 | ✔ |
145 | | *i* | Minutes with leading zeros | 00 to 59 | ✔ |
146 | | *s* | Seconds, with leading zeros | 00 through 59 | ✔ |
147 | | *v* | Milliseconds with leading zeros - 3 Digits. | Example: 654 | ✔ |
148 | | **Timezone** | **--** | **--** | **--** |
149 | | *Z* | Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. | -43200 through 50400 | ✕ |
150 | | **Full Date/Time** | **--** | **--** | **--** |
151 | | *c* | ISO 8601 date | 2004-02-12T15:19:21.990Z | ✕ |
152 | | *U* | Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) | 1533566318 | ✕ |
153 | | **Other** | **--** | **--** | **--** |
154 | | *J* | Count of days since since noon Universal Time on January 1, 4713 BC on the Julian calendar | 123412.5 | ✕ |
155 | | *P* | Moon Phase | Waning Crescent | ✕ |
156 |
157 |
158 | ## Timezone Reference
159 |
160 | A list of timezones and their corresponding countries:
161 |
162 | | Country | Timezone |
163 | |---------|----------|
164 | | **Afghanistan** | `Asia/Kabul` |
165 | | **Aland Islands** | `Europe/Mariehamn` |
166 | | **Albania** | `Europe/Tirane` |
167 | | **Algeria** | `Africa/Algiers` |
168 | | **American Samoa** | `Pacific/Pago_Pago` |
169 | | **Andorra** | `Europe/Andorra` |
170 | | **Angola** | `Africa/Luanda` |
171 | | **Anguilla** | `America/Anguilla` |
172 | | **Antarctica** | `Antarctica/Casey` |
173 | | **Antarctica** | `Antarctica/Davis` |
174 | | **Antarctica** | `Antarctica/DumontDUrville` |
175 | | **Antarctica** | `Antarctica/Mawson` |
176 | | **Antarctica** | `Antarctica/McMurdo` |
177 | | **Antarctica** | `Antarctica/Palmer` |
178 | | **Antarctica** | `Antarctica/Rothera` |
179 | | **Antarctica** | `Antarctica/Syowa` |
180 | | **Antarctica** | `Antarctica/Troll` |
181 | | **Antarctica** | `Antarctica/Vostok` |
182 | | **Antigua and Barbuda** | `America/Antigua` |
183 | | **Argentina** | `America/Argentina/Buenos_Aires` |
184 | | **Argentina** | `America/Argentina/Catamarca` |
185 | | **Argentina** | `America/Argentina/Cordoba` |
186 | | **Argentina** | `America/Argentina/Jujuy` |
187 | | **Argentina** | `America/Argentina/La_Rioja` |
188 | | **Argentina** | `America/Argentina/Mendoza` |
189 | | **Argentina** | `America/Argentina/Rio_Gallegos` |
190 | | **Argentina** | `America/Argentina/Salta` |
191 | | **Argentina** | `America/Argentina/San_Juan` |
192 | | **Argentina** | `America/Argentina/San_Luis` |
193 | | **Argentina** | `America/Argentina/Tucuman` |
194 | | **Argentina** | `America/Argentina/Ushuaia` |
195 | | **Armenia** | `Asia/Yerevan` |
196 | | **Aruba** | `America/Aruba` |
197 | | **Australia** | `Antarctica/Macquarie` |
198 | | **Australia** | `Australia/Adelaide` |
199 | | **Australia** | `Australia/Brisbane` |
200 | | **Australia** | `Australia/Broken_Hill` |
201 | | **Australia** | `Australia/Currie` |
202 | | **Australia** | `Australia/Darwin` |
203 | | **Australia** | `Australia/Eucla` |
204 | | **Australia** | `Australia/Hobart` |
205 | | **Australia** | `Australia/Lindeman` |
206 | | **Australia** | `Australia/Lord_Howe` |
207 | | **Australia** | `Australia/Melbourne` |
208 | | **Australia** | `Australia/Perth` |
209 | | **Australia** | `Australia/Sydney` |
210 | | **Austria** | `Europe/Vienna` |
211 | | **Azerbaijan** | `Asia/Baku` |
212 | | **Bahamas** | `America/Nassau` |
213 | | **Bahrain** | `Asia/Bahrain` |
214 | | **Bangladesh** | `Asia/Dhaka` |
215 | | **Barbados** | `America/Barbados` |
216 | | **Belarus** | `Europe/Minsk` |
217 | | **Belgium** | `Europe/Brussels` |
218 | | **Belize** | `America/Belize` |
219 | | **Benin** | `Africa/Porto-Novo` |
220 | | **Bermuda** | `Atlantic/Bermuda` |
221 | | **Bhutan** | `Asia/Thimphu` |
222 | | **Bolivia** | `America/La_Paz` |
223 | | **Bonaire, Saint Eustatius and Saba** | `America/Kralendijk` |
224 | | **Bosnia and Herzegovina** | `Europe/Sarajevo` |
225 | | **Botswana** | `Africa/Gaborone` |
226 | | **Brazil** | `America/Araguaina` |
227 | | **Brazil** | `America/Bahia` |
228 | | **Brazil** | `America/Belem` |
229 | | **Brazil** | `America/Boa_Vista` |
230 | | **Brazil** | `America/Campo_Grande` |
231 | | **Brazil** | `America/Cuiaba` |
232 | | **Brazil** | `America/Eirunepe` |
233 | | **Brazil** | `America/Fortaleza` |
234 | | **Brazil** | `America/Maceio` |
235 | | **Brazil** | `America/Manaus` |
236 | | **Brazil** | `America/Noronha` |
237 | | **Brazil** | `America/Porto_Velho` |
238 | | **Brazil** | `America/Recife` |
239 | | **Brazil** | `America/Rio_Branco` |
240 | | **Brazil** | `America/Santarem` |
241 | | **Brazil** | `America/Sao_Paulo` |
242 | | **British Indian Ocean Territory** | `Indian/Chagos` |
243 | | **British Virgin Islands** | `America/Tortola` |
244 | | **Brunei** | `Asia/Brunei` |
245 | | **Bulgaria** | `Europe/Sofia` |
246 | | **Burkina Faso** | `Africa/Ouagadougou` |
247 | | **Burundi** | `Africa/Bujumbura` |
248 | | **Cambodia** | `Asia/Phnom_Penh` |
249 | | **Cameroon** | `Africa/Douala` |
250 | | **Canada** | `America/Atikokan` |
251 | | **Canada** | `America/Blanc-Sablon` |
252 | | **Canada** | `America/Cambridge_Bay` |
253 | | **Canada** | `America/Creston` |
254 | | **Canada** | `America/Dawson` |
255 | | **Canada** | `America/Dawson_Creek` |
256 | | **Canada** | `America/Edmonton` |
257 | | **Canada** | `America/Fort_Nelson` |
258 | | **Canada** | `America/Glace_Bay` |
259 | | **Canada** | `America/Goose_Bay` |
260 | | **Canada** | `America/Halifax` |
261 | | **Canada** | `America/Inuvik` |
262 | | **Canada** | `America/Iqaluit` |
263 | | **Canada** | `America/Moncton` |
264 | | **Canada** | `America/Nipigon` |
265 | | **Canada** | `America/Pangnirtung` |
266 | | **Canada** | `America/Rainy_River` |
267 | | **Canada** | `America/Rankin_Inlet` |
268 | | **Canada** | `America/Regina` |
269 | | **Canada** | `America/Resolute` |
270 | | **Canada** | `America/St_Johns` |
271 | | **Canada** | `America/Swift_Current` |
272 | | **Canada** | `America/Thunder_Bay` |
273 | | **Canada** | `America/Toronto` |
274 | | **Canada** | `America/Vancouver` |
275 | | **Canada** | `America/Whitehorse` |
276 | | **Canada** | `America/Winnipeg` |
277 | | **Canada** | `America/Yellowknife` |
278 | | **Cape Verde** | `Atlantic/Cape_Verde` |
279 | | **Cayman Islands** | `America/Cayman` |
280 | | **Central African Republic** | `Africa/Bangui` |
281 | | **Chad** | `Africa/Ndjamena` |
282 | | **Chile** | `America/Punta_Arenas` |
283 | | **Chile** | `America/Santiago` |
284 | | **Chile** | `Pacific/Easter` |
285 | | **China** | `Asia/Shanghai` |
286 | | **China** | `Asia/Urumqi` |
287 | | **Christmas Island** | `Indian/Christmas` |
288 | | **Cocos Islands** | `Indian/Cocos` |
289 | | **Colombia** | `America/Bogota` |
290 | | **Comoros** | `Indian/Comoro` |
291 | | **Cook Islands** | `Pacific/Rarotonga` |
292 | | **Costa Rica** | `America/Costa_Rica` |
293 | | **Croatia** | `Europe/Zagreb` |
294 | | **Cuba** | `America/Havana` |
295 | | **Curaçao** | `America/Curacao` |
296 | | **Cyprus** | `Asia/Famagusta` |
297 | | **Cyprus** | `Asia/Nicosia` |
298 | | **Czech Republic** | `Europe/Prague` |
299 | | **Democratic Republic of the Congo** | `Africa/Kinshasa` |
300 | | **Democratic Republic of the Congo** | `Africa/Lubumbashi` |
301 | | **Denmark** | `Europe/Copenhagen` |
302 | | **Djibouti** | `Africa/Djibouti` |
303 | | **Dominica** | `America/Dominica` |
304 | | **Dominican Republic** | `America/Santo_Domingo` |
305 | | **East Timor** | `Asia/Dili` |
306 | | **Ecuador** | `America/Guayaquil` |
307 | | **Ecuador** | `Pacific/Galapagos` |
308 | | **Egypt** | `Africa/Cairo` |
309 | | **El Salvador** | `America/El_Salvador` |
310 | | **Equatorial Guinea** | `Africa/Malabo` |
311 | | **Eritrea** | `Africa/Asmara` |
312 | | **Estonia** | `Europe/Tallinn` |
313 | | **Ethiopia** | `Africa/Addis_Ababa` |
314 | | **Falkland Islands** | `Atlantic/Stanley` |
315 | | **Faroe Islands** | `Atlantic/Faroe` |
316 | | **Fiji** | `Pacific/Fiji` |
317 | | **Finland** | `Europe/Helsinki` |
318 | | **France** | `Europe/Paris` |
319 | | **French Guiana** | `America/Cayenne` |
320 | | **French Polynesia** | `Pacific/Gambier` |
321 | | **French Polynesia** | `Pacific/Marquesas` |
322 | | **French Polynesia** | `Pacific/Tahiti` |
323 | | **French Southern Territories** | `Indian/Kerguelen` |
324 | | **Gabon** | `Africa/Libreville` |
325 | | **Gambia** | `Africa/Banjul` |
326 | | **Georgia** | `Asia/Tbilisi` |
327 | | **Germany** | `Europe/Berlin` |
328 | | **Germany** | `Europe/Busingen` |
329 | | **Ghana** | `Africa/Accra` |
330 | | **Gibraltar** | `Europe/Gibraltar` |
331 | | **Greece** | `Europe/Athens` |
332 | | **Greenland** | `America/Danmarkshavn` |
333 | | **Greenland** | `America/Godthab` |
334 | | **Greenland** | `America/Scoresbysund` |
335 | | **Greenland** | `America/Thule` |
336 | | **Grenada** | `America/Grenada` |
337 | | **Guadeloupe** | `America/Guadeloupe` |
338 | | **Guam** | `Pacific/Guam` |
339 | | **Guatemala** | `America/Guatemala` |
340 | | **Guernsey** | `Europe/Guernsey` |
341 | | **Guinea** | `Africa/Conakry` |
342 | | **Guinea-Bissau** | `Africa/Bissau` |
343 | | **Guyana** | `America/Guyana` |
344 | | **Haiti** | `America/Port-au-Prince` |
345 | | **Honduras** | `America/Tegucigalpa` |
346 | | **Hong Kong** | `Asia/Hong_Kong` |
347 | | **Hungary** | `Europe/Budapest` |
348 | | **Iceland** | `Atlantic/Reykjavik` |
349 | | **India** | `Asia/Kolkata` |
350 | | **Indonesia** | `Asia/Jakarta` |
351 | | **Indonesia** | `Asia/Jayapura` |
352 | | **Indonesia** | `Asia/Makassar` |
353 | | **Indonesia** | `Asia/Pontianak` |
354 | | **Iran** | `Asia/Tehran` |
355 | | **Iraq** | `Asia/Baghdad` |
356 | | **Ireland** | `Europe/Dublin` |
357 | | **Isle of Man** | `Europe/Isle_of_Man` |
358 | | **Israel** | `Asia/Jerusalem` |
359 | | **Italy** | `Europe/Rome` |
360 | | **Ivory Coast** | `Africa/Abidjan` |
361 | | **Jamaica** | `America/Jamaica` |
362 | | **Japan** | `Asia/Tokyo` |
363 | | **Jersey** | `Europe/Jersey` |
364 | | **Jordan** | `Asia/Amman` |
365 | | **Kazakhstan** | `Asia/Almaty` |
366 | | **Kazakhstan** | `Asia/Aqtau` |
367 | | **Kazakhstan** | `Asia/Aqtobe` |
368 | | **Kazakhstan** | `Asia/Atyrau` |
369 | | **Kazakhstan** | `Asia/Oral` |
370 | | **Kazakhstan** | `Asia/Qyzylorda` |
371 | | **Kenya** | `Africa/Nairobi` |
372 | | **Kiribati** | `Pacific/Enderbury` |
373 | | **Kiribati** | `Pacific/Kiritimati` |
374 | | **Kiribati** | `Pacific/Tarawa` |
375 | | **Kuwait** | `Asia/Kuwait` |
376 | | **Kyrgyzstan** | `Asia/Bishkek` |
377 | | **Laos** | `Asia/Vientiane` |
378 | | **Latvia** | `Europe/Riga` |
379 | | **Lebanon** | `Asia/Beirut` |
380 | | **Lesotho** | `Africa/Maseru` |
381 | | **Liberia** | `Africa/Monrovia` |
382 | | **Libya** | `Africa/Tripoli` |
383 | | **Liechtenstein** | `Europe/Vaduz` |
384 | | **Lithuania** | `Europe/Vilnius` |
385 | | **Luxembourg** | `Europe/Luxembourg` |
386 | | **Macao** | `Asia/Macau` |
387 | | **Macedonia** | `Europe/Skopje` |
388 | | **Madagascar** | `Indian/Antananarivo` |
389 | | **Malawi** | `Africa/Blantyre` |
390 | | **Malaysia** | `Asia/Kuala_Lumpur` |
391 | | **Malaysia** | `Asia/Kuching` |
392 | | **Maldives** | `Indian/Maldives` |
393 | | **Mali** | `Africa/Bamako` |
394 | | **Malta** | `Europe/Malta` |
395 | | **Marshall Islands** | `Pacific/Kwajalein` |
396 | | **Marshall Islands** | `Pacific/Majuro` |
397 | | **Martinique** | `America/Martinique` |
398 | | **Mauritania** | `Africa/Nouakchott` |
399 | | **Mauritius** | `Indian/Mauritius` |
400 | | **Mayotte** | `Indian/Mayotte` |
401 | | **Mexico** | `America/Bahia_Banderas` |
402 | | **Mexico** | `America/Cancun` |
403 | | **Mexico** | `America/Chihuahua` |
404 | | **Mexico** | `America/Hermosillo` |
405 | | **Mexico** | `America/Matamoros` |
406 | | **Mexico** | `America/Mazatlan` |
407 | | **Mexico** | `America/Merida` |
408 | | **Mexico** | `America/Mexico_City` |
409 | | **Mexico** | `America/Monterrey` |
410 | | **Mexico** | `America/Ojinaga` |
411 | | **Mexico** | `America/Tijuana` |
412 | | **Micronesia** | `Pacific/Chuuk` |
413 | | **Micronesia** | `Pacific/Kosrae` |
414 | | **Micronesia** | `Pacific/Pohnpei` |
415 | | **Moldova** | `Europe/Chisinau` |
416 | | **Monaco** | `Europe/Monaco` |
417 | | **Mongolia** | `Asia/Choibalsan` |
418 | | **Mongolia** | `Asia/Hovd` |
419 | | **Mongolia** | `Asia/Ulaanbaatar` |
420 | | **Montenegro** | `Europe/Podgorica` |
421 | | **Montserrat** | `America/Montserrat` |
422 | | **Morocco** | `Africa/Casablanca` |
423 | | **Mozambique** | `Africa/Maputo` |
424 | | **Myanmar** | `Asia/Yangon` |
425 | | **Namibia** | `Africa/Windhoek` |
426 | | **Nauru** | `Pacific/Nauru` |
427 | | **Nepal** | `Asia/Kathmandu` |
428 | | **Netherlands** | `Europe/Amsterdam` |
429 | | **New Caledonia** | `Pacific/Noumea` |
430 | | **New Zealand** | `Pacific/Auckland` |
431 | | **New Zealand** | `Pacific/Chatham` |
432 | | **Nicaragua** | `America/Managua` |
433 | | **Niger** | `Africa/Niamey` |
434 | | **Nigeria** | `Africa/Lagos` |
435 | | **Niue** | `Pacific/Niue` |
436 | | **Norfolk Island** | `Pacific/Norfolk` |
437 | | **North Korea** | `Asia/Pyongyang` |
438 | | **Northern Mariana Islands** | `Pacific/Saipan` |
439 | | **Norway** | `Europe/Oslo` |
440 | | **Oman** | `Asia/Muscat` |
441 | | **Pakistan** | `Asia/Karachi` |
442 | | **Palau** | `Pacific/Palau` |
443 | | **Palestinian Territory** | `Asia/Gaza` |
444 | | **Palestinian Territory** | `Asia/Hebron` |
445 | | **Panama** | `America/Panama` |
446 | | **Papua New Guinea** | `Pacific/Bougainville` |
447 | | **Papua New Guinea** | `Pacific/Port_Moresby` |
448 | | **Paraguay** | `America/Asuncion` |
449 | | **Peru** | `America/Lima` |
450 | | **Philippines** | `Asia/Manila` |
451 | | **Pitcairn** | `Pacific/Pitcairn` |
452 | | **Poland** | `Europe/Warsaw` |
453 | | **Portugal** | `Atlantic/Azores` |
454 | | **Portugal** | `Atlantic/Madeira` |
455 | | **Portugal** | `Europe/Lisbon` |
456 | | **Puerto Rico** | `America/Puerto_Rico` |
457 | | **Qatar** | `Asia/Qatar` |
458 | | **Republic of the Congo** | `Africa/Brazzaville` |
459 | | **Reunion** | `Indian/Reunion` |
460 | | **Romania** | `Europe/Bucharest` |
461 | | **Russia** | `Asia/Anadyr` |
462 | | **Russia** | `Asia/Barnaul` |
463 | | **Russia** | `Asia/Chita` |
464 | | **Russia** | `Asia/Irkutsk` |
465 | | **Russia** | `Asia/Kamchatka` |
466 | | **Russia** | `Asia/Khandyga` |
467 | | **Russia** | `Asia/Krasnoyarsk` |
468 | | **Russia** | `Asia/Magadan` |
469 | | **Russia** | `Asia/Novokuznetsk` |
470 | | **Russia** | `Asia/Novosibirsk` |
471 | | **Russia** | `Asia/Omsk` |
472 | | **Russia** | `Asia/Sakhalin` |
473 | | **Russia** | `Asia/Srednekolymsk` |
474 | | **Russia** | `Asia/Tomsk` |
475 | | **Russia** | `Asia/Ust-Nera` |
476 | | **Russia** | `Asia/Vladivostok` |
477 | | **Russia** | `Asia/Yakutsk` |
478 | | **Russia** | `Asia/Yekaterinburg` |
479 | | **Russia** | `Europe/Astrakhan` |
480 | | **Russia** | `Europe/Kaliningrad` |
481 | | **Russia** | `Europe/Kirov` |
482 | | **Russia** | `Europe/Moscow` |
483 | | **Russia** | `Europe/Samara` |
484 | | **Russia** | `Europe/Saratov` |
485 | | **Russia** | `Europe/Simferopol` |
486 | | **Russia** | `Europe/Ulyanovsk` |
487 | | **Russia** | `Europe/Volgograd` |
488 | | **Rwanda** | `Africa/Kigali` |
489 | | **Saint Barthélemy** | `America/St_Barthelemy` |
490 | | **Saint Helena** | `Atlantic/St_Helena` |
491 | | **Saint Kitts and Nevis** | `America/St_Kitts` |
492 | | **Saint Lucia** | `America/St_Lucia` |
493 | | **Saint Martin** | `America/Marigot` |
494 | | **Saint Pierre and Miquelon** | `America/Miquelon` |
495 | | **Saint Vincent and the Grenadines** | `America/St_Vincent` |
496 | | **Samoa** | `Pacific/Apia` |
497 | | **San Marino** | `Europe/San_Marino` |
498 | | **Sao Tome and Principe** | `Africa/Sao_Tome` |
499 | | **Saudi Arabia** | `Asia/Riyadh` |
500 | | **Senegal** | `Africa/Dakar` |
501 | | **Serbia** | `Europe/Belgrade` |
502 | | **Seychelles** | `Indian/Mahe` |
503 | | **Sierra Leone** | `Africa/Freetown` |
504 | | **Singapore** | `Asia/Singapore` |
505 | | **Sint Maarten** | `America/Lower_Princes` |
506 | | **Slovakia** | `Europe/Bratislava` |
507 | | **Slovenia** | `Europe/Ljubljana` |
508 | | **Solomon Islands** | `Pacific/Guadalcanal` |
509 | | **Somalia** | `Africa/Mogadishu` |
510 | | **South Africa** | `Africa/Johannesburg` |
511 | | **South Georgia and the South Sandwich Islands** | `Atlantic/South_Georgia` |
512 | | **South Korea** | `Asia/Seoul` |
513 | | **South Sudan** | `Africa/Juba` |
514 | | **Spain** | `Africa/Ceuta` |
515 | | **Spain** | `Atlantic/Canary` |
516 | | **Spain** | `Europe/Madrid` |
517 | | **Sri Lanka** | `Asia/Colombo` |
518 | | **Sudan** | `Africa/Khartoum` |
519 | | **Suriname** | `America/Paramaribo` |
520 | | **Svalbard and Jan Mayen** | `Arctic/Longyearbyen` |
521 | | **Swaziland** | `Africa/Mbabane` |
522 | | **Sweden** | `Europe/Stockholm` |
523 | | **Switzerland** | `Europe/Zurich` |
524 | | **Syria** | `Asia/Damascus` |
525 | | **Taiwan** | `Asia/Taipei` |
526 | | **Tajikistan** | `Asia/Dushanbe` |
527 | | **Tanzania** | `Africa/Dar_es_Salaam` |
528 | | **Thailand** | `Asia/Bangkok` |
529 | | **Togo** | `Africa/Lome` |
530 | | **Tokelau** | `Pacific/Fakaofo` |
531 | | **Tonga** | `Pacific/Tongatapu` |
532 | | **Trinidad and Tobago** | `America/Port_of_Spain` |
533 | | **Tunisia** | `Africa/Tunis` |
534 | | **Turkey** | `Europe/Istanbul` |
535 | | **Turkmenistan** | `Asia/Ashgabat` |
536 | | **Turks and Caicos Islands** | `America/Grand_Turk` |
537 | | **Tuvalu** | `Pacific/Funafuti` |
538 | | **U.S. Virgin Islands** | `America/St_Thomas` |
539 | | **Uganda** | `Africa/Kampala` |
540 | | **Ukraine** | `Europe/Kiev` |
541 | | **Ukraine** | `Europe/Uzhgorod` |
542 | | **Ukraine** | `Europe/Zaporozhye` |
543 | | **United Arab Emirates** | `Asia/Dubai` |
544 | | **United Kingdom** | `Europe/London` |
545 | | **United States** | `America/Adak` |
546 | | **United States** | `America/Anchorage` |
547 | | **United States** | `America/Boise` |
548 | | **United States** | `America/Chicago` |
549 | | **United States** | `America/Denver` |
550 | | **United States** | `America/Detroit` |
551 | | **United States** | `America/Indiana/Indianapolis` |
552 | | **United States** | `America/Indiana/Knox` |
553 | | **United States** | `America/Indiana/Marengo` |
554 | | **United States** | `America/Indiana/Petersburg` |
555 | | **United States** | `America/Indiana/Tell_City` |
556 | | **United States** | `America/Indiana/Vevay` |
557 | | **United States** | `America/Indiana/Vincennes` |
558 | | **United States** | `America/Indiana/Winamac` |
559 | | **United States** | `America/Juneau` |
560 | | **United States** | `America/Kentucky/Louisville` |
561 | | **United States** | `America/Kentucky/Monticello` |
562 | | **United States** | `America/Los_Angeles` |
563 | | **United States** | `America/Menominee` |
564 | | **United States** | `America/Metlakatla` |
565 | | **United States** | `America/New_York` |
566 | | **United States** | `America/Nome` |
567 | | **United States** | `America/North_Dakota/Beulah` |
568 | | **United States** | `America/North_Dakota/Center` |
569 | | **United States** | `America/North_Dakota/New_Salem` |
570 | | **United States** | `America/Phoenix` |
571 | | **United States** | `America/Sitka` |
572 | | **United States** | `America/Yakutat` |
573 | | **United States** | `Pacific/Honolulu` |
574 | | **United States Minor Outlying Islands** | `Pacific/Midway` |
575 | | **United States Minor Outlying Islands** | `Pacific/Wake` |
576 | | **Uruguay** | `America/Montevideo` |
577 | | **Uzbekistan** | `Asia/Samarkand` |
578 | | **Uzbekistan** | `Asia/Tashkent` |
579 | | **Vanuatu** | `Pacific/Efate` |
580 | | **Vatican** | `Europe/Vatican` |
581 | | **Venezuela** | `America/Caracas` |
582 | | **Vietnam** | `Asia/Ho_Chi_Minh` |
583 | | **Wallis and Futuna** | `Pacific/Wallis` |
584 | | **Western Sahara** | `Africa/El_Aaiun` |
585 | | **Yemen** | `Asia/Aden` |
586 | | **Zambia** | `Africa/Lusaka` |
587 | | **Zimbabwe** | `Africa/Harare` |
588 |
589 | ## License
590 |
591 | ProtoDate comes with an Apache 2.0 license. [Read the license here](https://github.com/Pamblam/protodate/blob/master/LICENSE).
592 |
593 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-dinky
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "protodate",
3 | "version": "3.0.8",
4 | "description": "Better Javascript Dates.",
5 | "main": "protodate.tz.min.js",
6 | "scripts": {
7 | "test": "node node_modules/.bin/mocha",
8 | "coverage": "node node_modules/.bin/istanbul cover _mocha -- -R spec",
9 | "coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls",
10 | "build": "./node_modules/.bin/grunt"
11 | },
12 | "keywords": [
13 | "date",
14 | "time",
15 | "moment",
16 | "protodate",
17 | "timezone"
18 | ],
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://Pamblam@github.com/Pamblam/protodate.git"
22 | },
23 | "bugs": {
24 | "url": "https://github.com/Pamblam/protodate/issues"
25 | },
26 | "author": "Rob Parham",
27 | "license": "Apache-2.0",
28 | "homepage": "https://github.com/Pamblam/protodate",
29 | "devDependencies": {
30 | "chai": "^4.1.2",
31 | "coveralls": "^3.0.0",
32 | "grunt": "^1.0.1",
33 | "grunt-contrib-concat": "^1.0.1",
34 | "grunt-contrib-uglify-es": "^3.3.0",
35 | "grunt-string-replace": "^1.3.1",
36 | "istanbul": "^0.4.5",
37 | "mocha": "^4.0.1"
38 | }
39 | }
--------------------------------------------------------------------------------
/protodate.js:
--------------------------------------------------------------------------------
1 | /**
2 | * protodate (lite) - v3.0.8
3 | * Better Javascript Dates.
4 | * @author Rob Parham
5 | * @website https://github.com/Pamblam/protodate
6 | * @license Apache-2.0
7 | */
8 |
9 |
10 | class ProtoDate extends Date{}
11 |
12 | (function(){
13 | "use strict";
14 | ProtoDate.MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
15 | ProtoDate.DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
16 | ProtoDate.PROTODATE_VERSION = '3.0.8';
17 | ProtoDate.MILLISECOND = 1;
18 | ProtoDate.SECOND = 1000;
19 | ProtoDate.MINUTE = 60000;
20 | ProtoDate.HOUR = 3600000;
21 | ProtoDate.DAY = 86400000;
22 | ProtoDate.YEAR = 31536000000;
23 | ProtoDate.TIME_FORMATS = [
24 | "G00 \\h\\o\\u\\r\\s", "g \\o\\c\\l\\o\\c\\k", "g \\o \\c\\l\\o\\c\\k",
25 | "g i", "g i a", "g i A", "g i s", "g i s a", "g i s A", "h i", "h i a",
26 | "h i A", "h i s", "h i s a", "h i s A", "H i", "H i a", "H i A", "H i s",
27 | "G i", "G i a", "G i A", "G i s", "g i s v", "g i s a v", "g i s A v",
28 | "h i s v", "h i s a v", "h i s A v", "H i s v", "G i s v"
29 | ];
30 | ProtoDate.DATE_FORMATS = [
31 | "y", "Y", "F", "M", "F Y", "F y", "M Y", "M y", "F jS Y", "F jS",
32 | "M jS Y", "M jS", "F j Y", "F j", "M j Y", "M j", "jS F Y", "jS F",
33 | "jS M Y", "jS M", "j F Y", "j F", "j M Y", "j M", "Y m d", "m d y",
34 | "m d Y", "Y n d", "n d y", "n d Y", "Y m j", "m j y", "m j Y", "Y n j",
35 | "n j y", "n j Y", "D Y m d", "D m d y", "D m d Y", "D Y n d", "D n d y",
36 | "D n d Y", "D Y m j", "D m j y", "D m j Y", "D Y n j", "D n j y",
37 | "D n j Y", "l Y m d", "l m d y", "l m d Y", "l Y n d", "l n d y",
38 | "l n d Y", "l Y m j", "l m j y", "l m j Y", "l Y n j", "l n j y",
39 | "l n j Y"
40 | ];
41 | })();
42 |
43 | /**
44 | * Return a unix timestamp for the given date
45 | * @returns {undefined}
46 | */
47 | (function(){
48 | ProtoDate.prototype.getUnixTimestamp = function(){
49 | return ~~(this.getTime()/1000);
50 | };
51 | })();
52 |
53 | /**
54 | * Determine if a thing is a date
55 | * @returns {bool}
56 | */
57 | (function(){
58 | "use strict";
59 | ProtoDate.isDate = function(date){
60 | return 'function' === typeof date.getTime && !isNaN(date.getTime());
61 | };
62 | })();
63 |
64 | /**
65 | * Format a date
66 | * @param {Date} date - A Javascript Date object
67 | * @param {String} format - The format of the outputted date
68 | * @returns {String} - The formatted date
69 | */
70 | (function(){
71 | "use strict";
72 | ProtoDate.prototype.format = function(format) {
73 | if (!ProtoDate.isDate(this)) return false;
74 | var buffer = [];
75 | for(var i=0; i 12 ? this.getHours() - 12 : this.getHours())); break;
90 | case "G": buffer.push("" + (this.getHours())); break;
91 | case "h": buffer.push(("0" + (this.getHours() > 12 ? this.getHours() - 12 : this.getHours())).substr(-2, 2)); break;
92 | case "H": buffer.push(("0" + (this.getHours()+"")).substr(-2, 2)); break;
93 | case "i": buffer.push(("0" + this.getMinutes()).substr(-2, 2)); break;
94 | case "s": buffer.push(("0" + this.getSeconds()).substr(-2, 2)); break;
95 | case "N": buffer.push(this.getDay()==0?7:this.getDay()); break;
96 | case "L": buffer.push((this.getFullYear() % 4 == 0 && this.getFullYear() % 100 != 0) || this.getFullYear() % 400 == 0 ? "1" : "0"); break;
97 | case "o": buffer.push(this.getMonth()==0&&this.getDate()<6&&this.getDay()<4?this.getFullYear()-1:this.getFullYear()); break;
98 | case "B": buffer.push(Math.floor((((this.getUTCHours() + 1) % 24) + this.getUTCMinutes() / 60 + this.getUTCSeconds() / 3600) * 1000 / 24)); break;
99 | case "v": buffer.push((this.getTime()+"").substr(-3)); break;
100 | case "Z": buffer.push(this.getTimezoneOffset()*60); break;
101 | case "U": buffer.push(Math.floor(this.getTime()/1000)); break;
102 |
103 | // Symbols that represent text
104 | case "a": buffer.push(this.getHours() > 11 ? "pm" : "am"); break;
105 | case "A": buffer.push(this.getHours() > 11 ? "PM" : "AM"); break;
106 | case "l": buffer.push(ProtoDate.DAYS[this.getDay()]); break;
107 | case "D": buffer.push(ProtoDate.DAYS[this.getDay()].substr(0, 3)); break;
108 | case "F": buffer.push(ProtoDate.MONTHS[this.getMonth()]); break;
109 | case "M": buffer.push(ProtoDate.MONTHS[this.getMonth()].substring(0, 3)); break;
110 | case "c": buffer.push(this.toISOString()); break;
111 |
112 | // Ordinal suffix
113 | case "S":
114 | var suffix = false;
115 | var ones = buffer[buffer.length-1].toString()[1];
116 | var tens = buffer[buffer.length-1].toString()[0];
117 | if(undefined === ones){
118 | ones = tens;
119 | tens = null;
120 | }
121 | if(ones == "1") suffix = "st";
122 | if(ones == "2") suffix = "nd";
123 | if(ones == "3") suffix = "rd";
124 | if(tens == "1" || !suffix) suffix = "th";
125 | buffer.push(suffix);
126 | break;
127 |
128 | // ISO-8601 Week number
129 | case "W":
130 | var startDate = new ProtoDate(this.getFullYear(), 0);
131 | var endDate = new ProtoDate(this.getFullYear(), this.getMonth(), this.getDate());
132 | while(endDate.getDay() < 6) endDate.setDate(endDate.getDate()+1);
133 | endDate = endDate.getTime();
134 | var weekNo = 0;
135 | while(startDate.getTime() < endDate){
136 | if(startDate.getDay() == 4) weekNo++;
137 | startDate.setDate(startDate.getDate()+1);
138 | }
139 | buffer.push(weekNo);
140 | break;
141 |
142 | // Day of the year
143 | case "z":
144 | var startDate = new ProtoDate(this.getFullYear(), 0, 1, 0, 0, 0, 0);
145 | var dayNo = 0;
146 | while(startDate.getTime() < this.getTime()){
147 | dayNo++;
148 | startDate.setDate(startDate.getDate()+1);
149 | }
150 | buffer.push(dayNo);
151 | break;
152 |
153 | // Julian Day
154 | case "J":
155 | var y = parseInt(this.format("Y"));
156 | var m = parseInt(this.format("n"));
157 | if(m === 1 || m === 2){
158 | y -= 1;
159 | m += 12;
160 | }
161 | var d = parseInt(this.format("j"));
162 | var a = Math.floor(y/100);
163 | var b = Math.floor(a/4);
164 | var c = 2-a+b;
165 | var e = Math.floor(365.25*(y+4716));
166 | var f = Math.floor(30.6001*(m+1));
167 | buffer.push(c+d+e+f-1524.5);
168 | break;
169 |
170 | // Moon Phase
171 | case "P":
172 | var jd = this.format("J");
173 | var dsn = jd - 2451549.5;
174 | var nm = dsn / 29.53;
175 | var dic = parseFloat("0."+((nm+"").split(".")[1])) * 29.53;
176 | if(dic > 27.65625) return "New Moon";
177 | if(dic > 23.96875) return "Waning Crescent";
178 | if(dic > 20.28125) return "Third Quarter";
179 | if(dic > 16.59375) return "Waning Gibbous";
180 | if(dic > 12.90625) return "Full Moon";
181 | if(dic > 9.21875) return "Waxing Gibbous";
182 | if(dic > 5.53125) return "First Quarter";
183 | if(dic > 1.84375) return "Waxing Crescent";
184 | return "New Moon";
185 | break;
186 |
187 | default: buffer.push(format[i]); break;
188 | }
189 | }
190 | return buffer.join('');
191 | };
192 | })();
193 |
194 | /**
195 | * Validate a date string against a format string
196 | * @returns {bool}
197 | */
198 | (function(){
199 | "use strict";
200 | ProtoDate.validateFormat = function(dateStr, formatStr){
201 | for(var i=0; i12 || !+dateStr.substr(0,2)) return false;
218 | dateStr = dateStr.substr(2);
219 | break;
220 | case "n":
221 | case "g":
222 | var m = dateStr.match(/^(\d){1,2}/)||[];
223 | if(!m.length || +m[0]>12 || !+m[0]) return false;
224 | dateStr = dateStr.substr(m[0].length);
225 | break;
226 | case "d":
227 | if(!/^(\d){2}/.test(dateStr) || +dateStr.substr(0,2)>31 || !+dateStr.substr(0,2)) return false;
228 | dateStr = dateStr.substr(2);
229 | break;
230 | case "j":
231 | var m = dateStr.match(/^(\d){1,2}/)||[];
232 | if(!m.length || +m[0]>31 || !+m[0]) return false;
233 | dateStr = dateStr.substr(m[0].length);
234 | break;
235 | case "G":
236 | var m = dateStr.match(/^(\d){1,2}/)||[];
237 | if(!m.length || +m[0]>23) return false;
238 | dateStr = dateStr.substr(m[0].length);
239 | break;
240 | case "H":
241 | if(!/^(\d){2}/.test(dateStr) || +dateStr.substr(0,2)>23) return false;
242 | dateStr = dateStr.substr(2);
243 | break;
244 | case "i":
245 | case "s":
246 | if(!/^(\d){2}/.test(dateStr) || +dateStr.substr(0,2)>59) return false;
247 | dateStr = dateStr.substr(2);
248 | break;
249 | case "v":
250 | if(!/^(\d){3}/.test(dateStr)) return false;
251 | dateStr = dateStr.substr(3);
252 | break;
253 | case "a":
254 | case "A":
255 | var m = dateStr.substr(0,2).toLowerCase();
256 | if(!~['am','pm'].indexOf(m)) return false;
257 | dateStr = dateStr.substr(2);
258 | break;
259 | case "l":
260 | var d = dateStr.toLowerCase(), day=false;
261 | for(var n=0; n6 && !d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,6))){
274 | abrlen = 6; break;
275 | }
276 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,5))){
277 | abrlen = 5; break;
278 | }
279 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,4))){
280 | abrlen = 4; break;
281 | }
282 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,3))){
283 | abrlen = 3; break;
284 | }
285 | }
286 | if(!abrlen) return false;
287 | dateStr = dateStr.substr(abrlen);
288 | break;
289 | case "F":
290 | var m = dateStr.toLowerCase(), mm=false;
291 | for(var n=0; ncy?"19":"20")+y;
355 | dateStr = dateStr.substr(2);
356 | break;
357 | case "m":
358 | month = dateStr.substr(0,2)-1;
359 | dateStr = dateStr.substr(2);
360 | break;
361 | case "n":
362 | var m = dateStr.match(/^(\d){1,2}/)[0];
363 | month = m-1;
364 | dateStr = dateStr.substr(m.length);
365 | break;
366 | case "d":
367 | day = +dateStr.substr(0,2);
368 | dateStr = dateStr.substr(2);
369 | break;
370 | case "j":
371 | var m = dateStr.match(/^(\d){1,2}/)[0];
372 | day = +m;
373 | dateStr = dateStr.substr(m.length);
374 | break;
375 | case "g":
376 | var h = dateStr.match(/^(\d){1,2}/)[0];
377 | hours = h == 12 ? 0 : +h;
378 | dateStr = dateStr.substr(h.length);
379 | break;
380 | case "G":
381 | hr24 = true;
382 | var h = dateStr.match(/^(\d){1,2}/)[0];
383 | hours = +h;
384 | dateStr = dateStr.substr(h.length);
385 | break;
386 | case "h":
387 | var h = dateStr.substr(0,2);
388 | hours = h == 12 ? 0 : +h;
389 | dateStr = dateStr.substr(2);
390 | break;
391 | case "H":
392 | hr24 = true;
393 | hours = +dateStr.substr(0,2);
394 | dateStr = dateStr.substr(2);
395 | break;
396 | case "i":
397 | minutes = +dateStr.substr(0,2);
398 | dateStr = dateStr.substr(2);
399 | break;
400 | case "s":
401 | seconds = +dateStr.substr(0,2);
402 | dateStr = dateStr.substr(2);
403 | break;
404 | case "v":
405 | milliseconds = +dateStr.substr(0,3);
406 | dateStr = dateStr.substr(3);
407 | break;
408 | case "a":
409 | case "A":
410 | if("pm" == dateStr.substr(0,2).toLowerCase()) am=false;
411 | break;
412 | case "l":
413 | var d = dateStr.toLowerCase(), dd=false;
414 | for(var n=0; n6 && !d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,6))){
424 | abrlen = 6; break;
425 | }
426 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,5))){
427 | abrlen = 5; break;
428 | }
429 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,4))){
430 | abrlen = 4; break;
431 | }
432 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,3))){
433 | abrlen = 3; break;
434 | }
435 | }
436 | dateStr = dateStr.substr(abrlen);
437 | break;
438 | case "F":
439 | var m = dateStr.toLowerCase(), mm=false, idx=0;
440 | for(var n=0; n 1 ? "s" : ""));
495 | if (o.d) str.push(o.d + " day" + (o.d > 1 ? "s" : ""));
496 | if (o.h) str.push(o.h + " hour" + (o.h > 1 ? "s" : ""));
497 | if (o.m) str.push(o.m + " minute" + (o.m > 1 ? "s" : ""));
498 | if (o.s) str.push(o.s + " second" + (o.s > 1 ? "s" : ""));
499 | if (str.length > 1) str[str.length - 1] = "and " + str[str.length - 1];
500 | return str.join(', ');
501 | };
502 | o.clock = function(ms){ return [o.h, o.m, ms ? o.s+"."+(("00" + o.ms).substr(-3)):+o.s].join(':') };
503 | return o;
504 | };
505 | })();
506 |
507 | /**
508 | * Add a period of time
509 | * @returns {Date}
510 | */
511 | (function(){
512 | "use strict";
513 | ProtoDate.prototype.minus = function(quantity, period){
514 | this.setTime(this.getTime() - (quantity * period));
515 | return this;
516 | };
517 | })();
518 |
519 | /**
520 | * Add a period of time
521 | * @returns {Date}
522 | */
523 | (function(){
524 | "use strict";
525 | ProtoDate.prototype.plus = function(quantity, period){
526 | this.setTime(this.getTime() + (quantity * period));
527 | return this;
528 | };
529 | })();
530 |
531 | /**
532 | * Guess the format string belonging to a date string
533 | * @returns {string|false}
534 | */
535 | (function(){
536 | "use strict";
537 | ProtoDate.guessFormat = function(dateStr){
538 | var tf, df, i, n;
539 | for(n=0; n12?this.getHours()-12:this.getHours()));break;case"G":e.push(""+this.getHours());break;case"h":e.push(("0"+(this.getHours()>12?this.getHours()-12:this.getHours())).substr(-2,2));break;case"H":e.push(("0"+this.getHours()).substr(-2,2));break;case"i":e.push(("0"+this.getMinutes()).substr(-2,2));break;case"s":e.push(("0"+this.getSeconds()).substr(-2,2));break;case"N":e.push(0==this.getDay()?7:this.getDay());break;case"L":e.push(this.getFullYear()%4==0&&this.getFullYear()%100!=0||this.getFullYear()%400==0?"1":"0");break;case"o":e.push(0==this.getMonth()&&this.getDate()<6&&this.getDay()<4?this.getFullYear()-1:this.getFullYear());break;case"B":e.push(Math.floor(1e3*((this.getUTCHours()+1)%24+this.getUTCMinutes()/60+this.getUTCSeconds()/3600)/24));break;case"v":e.push((this.getTime()+"").substr(-3));break;case"Z":e.push(60*this.getTimezoneOffset());break;case"U":e.push(Math.floor(this.getTime()/1e3));break;case"a":e.push(this.getHours()>11?"pm":"am");break;case"A":e.push(this.getHours()>11?"PM":"AM");break;case"l":e.push(ProtoDate.DAYS[this.getDay()]);break;case"D":e.push(ProtoDate.DAYS[this.getDay()].substr(0,3));break;case"F":e.push(ProtoDate.MONTHS[this.getMonth()]);break;case"M":e.push(ProtoDate.MONTHS[this.getMonth()].substring(0,3));break;case"c":e.push(this.toISOString());break;case"S":var s=!1,a=e[e.length-1].toString()[1],o=e[e.length-1].toString()[0];void 0===a&&(a=o,o=null),"1"==a&&(s="st"),"2"==a&&(s="nd"),"3"==a&&(s="rd"),"1"!=o&&s||(s="th"),e.push(s);break;case"W":for(var i=new ProtoDate(this.getFullYear(),0),u=new ProtoDate(this.getFullYear(),this.getMonth(),this.getDate());u.getDay()<6;)u.setDate(u.getDate()+1);u=u.getTime();for(var n=0;i.getTime()27.65625?"New Moon":k>23.96875?"Waning Crescent":k>20.28125?"Third Quarter":k>16.59375?"Waning Gibbous":k>12.90625?"Full Moon":k>9.21875?"Waxing Gibbous":k>5.53125?"First Quarter":k>1.84375?"Waxing Crescent":"New Moon";default:e.push(t[r])}return e.join("")}}(),function(){"use strict";ProtoDate.validateFormat=function(t,e){for(var r=0;r12||!+t.substr(0,2))return!1;t=t.substr(2);break;case"n":case"g":if(!(s=t.match(/^(\d){1,2}/)||[]).length||+s[0]>12||!+s[0])return!1;t=t.substr(s[0].length);break;case"d":if(!/^(\d){2}/.test(t)||+t.substr(0,2)>31||!+t.substr(0,2))return!1;t=t.substr(2);break;case"j":if(!(s=t.match(/^(\d){1,2}/)||[]).length||+s[0]>31||!+s[0])return!1;t=t.substr(s[0].length);break;case"G":if(!(s=t.match(/^(\d){1,2}/)||[]).length||+s[0]>23)return!1;t=t.substr(s[0].length);break;case"H":if(!/^(\d){2}/.test(t)||+t.substr(0,2)>23)return!1;t=t.substr(2);break;case"i":case"s":if(!/^(\d){2}/.test(t)||+t.substr(0,2)>59)return!1;t=t.substr(2);break;case"v":if(!/^(\d){3}/.test(t))return!1;t=t.substr(3);break;case"a":case"A":var s=t.substr(0,2).toLowerCase();if(!~["am","pm"].indexOf(s))return!1;t=t.substr(2);break;case"l":for(var a=t.toLowerCase(),o=!1,i=0;i6&&!a.indexOf(ProtoDate.DAYS[i].toLowerCase().substr(0,6))){u=6;break}if(!a.indexOf(ProtoDate.DAYS[i].toLowerCase().substr(0,5))){u=5;break}if(!a.indexOf(ProtoDate.DAYS[i].toLowerCase().substr(0,4))){u=4;break}if(!a.indexOf(ProtoDate.DAYS[i].toLowerCase().substr(0,3))){u=3;break}}if(!u)return!1;t=t.substr(u);break;case"F":s=t.toLowerCase();var n=!1;for(i=0;ig?"19":"20")+f,t=t.substr(2);break;case"m":a=t.substr(0,2)-1,t=t.substr(2);break;case"n":a=(Y=t.match(/^(\d){1,2}/)[0])-1,t=t.substr(Y.length);break;case"d":o=+t.substr(0,2),t=t.substr(2);break;case"j":o=+(Y=t.match(/^(\d){1,2}/)[0]),t=t.substr(Y.length);break;case"g":i=12==(l=t.match(/^(\d){1,2}/)[0])?0:+l,t=t.substr(l.length);break;case"G":D=!0,i=+(l=t.match(/^(\d){1,2}/)[0]),t=t.substr(l.length);break;case"h":var l;i=12==(l=t.substr(0,2))?0:+l,t=t.substr(2);break;case"H":D=!0,i=+t.substr(0,2),t=t.substr(2);break;case"i":u=+t.substr(0,2),t=t.substr(2);break;case"s":n=+t.substr(0,2),t=t.substr(2);break;case"v":h=+t.substr(0,3),t=t.substr(3);break;case"a":case"A":"pm"==t.substr(0,2).toLowerCase()&&(b=!1);break;case"l":for(var d=t.toLowerCase(),P=!1,k=0;k6&&!d.indexOf(ProtoDate.DAYS[k].toLowerCase().substr(0,6))){m=6;break}if(!d.indexOf(ProtoDate.DAYS[k].toLowerCase().substr(0,5))){m=5;break}if(!d.indexOf(ProtoDate.DAYS[k].toLowerCase().substr(0,4))){m=4;break}if(!d.indexOf(ProtoDate.DAYS[k].toLowerCase().substr(0,3))){m=3;break}}t=t.substr(m);break;case"F":var Y=t.toLowerCase(),M=!1,p=0;for(k=0;k1?"s":"")),r.d&&t.push(r.d+" day"+(r.d>1?"s":"")),r.h&&t.push(r.h+" hour"+(r.h>1?"s":"")),r.m&&t.push(r.m+" minute"+(r.m>1?"s":"")),r.s&&t.push(r.s+" second"+(r.s>1?"s":"")),t.length>1&&(t[t.length-1]="and "+t[t.length-1]),t.join(", ")},r.clock=function(t){return[r.h,r.m,t?r.s+"."+("00"+r.ms).substr(-3):+r.s].join(":")},r}}(),function(){"use strict";ProtoDate.prototype.minus=function(t,e){return this.setTime(this.getTime()-t*e),this}}(),function(){"use strict";ProtoDate.prototype.plus=function(t,e){return this.setTime(this.getTime()+t*e),this}}(),function(){"use strict";ProtoDate.guessFormat=function(t){var e,r,s,a;for(a=0;a 1 ? "s" : ""));
25 | if (o.d) str.push(o.d + " day" + (o.d > 1 ? "s" : ""));
26 | if (o.h) str.push(o.h + " hour" + (o.h > 1 ? "s" : ""));
27 | if (o.m) str.push(o.m + " minute" + (o.m > 1 ? "s" : ""));
28 | if (o.s) str.push(o.s + " second" + (o.s > 1 ? "s" : ""));
29 | if (str.length > 1) str[str.length - 1] = "and " + str[str.length - 1];
30 | return str.join(', ');
31 | };
32 | o.clock = function(ms){ return [o.h, o.m, ms ? o.s+"."+(("00" + o.ms).substr(-3)):+o.s].join(':') };
33 | return o;
34 | };
35 | })();
--------------------------------------------------------------------------------
/src/export.js:
--------------------------------------------------------------------------------
1 |
2 | /* istanbul ignore next */
3 | if(!!(typeof module !== 'undefined' && module.exports)) module.exports = ProtoDate;
--------------------------------------------------------------------------------
/src/format.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Format a date
4 | * @param {Date} date - A Javascript Date object
5 | * @param {String} format - The format of the outputted date
6 | * @returns {String} - The formatted date
7 | */
8 | (function(){
9 | "use strict";
10 | ProtoDate.prototype.format = function(format) {
11 | if (!ProtoDate.isDate(this)) return false;
12 | var buffer = [];
13 | for(var i=0; i 12 ? this.getHours() - 12 : this.getHours())); break;
28 | case "G": buffer.push("" + (this.getHours())); break;
29 | case "h": buffer.push(("0" + (this.getHours() > 12 ? this.getHours() - 12 : this.getHours())).substr(-2, 2)); break;
30 | case "H": buffer.push(("0" + (this.getHours()+"")).substr(-2, 2)); break;
31 | case "i": buffer.push(("0" + this.getMinutes()).substr(-2, 2)); break;
32 | case "s": buffer.push(("0" + this.getSeconds()).substr(-2, 2)); break;
33 | case "N": buffer.push(this.getDay()==0?7:this.getDay()); break;
34 | case "L": buffer.push((this.getFullYear() % 4 == 0 && this.getFullYear() % 100 != 0) || this.getFullYear() % 400 == 0 ? "1" : "0"); break;
35 | case "o": buffer.push(this.getMonth()==0&&this.getDate()<6&&this.getDay()<4?this.getFullYear()-1:this.getFullYear()); break;
36 | case "B": buffer.push(Math.floor((((this.getUTCHours() + 1) % 24) + this.getUTCMinutes() / 60 + this.getUTCSeconds() / 3600) * 1000 / 24)); break;
37 | case "v": buffer.push((this.getTime()+"").substr(-3)); break;
38 | case "Z": buffer.push(this.getTimezoneOffset()*60); break;
39 | case "U": buffer.push(Math.floor(this.getTime()/1000)); break;
40 |
41 | // Symbols that represent text
42 | case "a": buffer.push(this.getHours() > 11 ? "pm" : "am"); break;
43 | case "A": buffer.push(this.getHours() > 11 ? "PM" : "AM"); break;
44 | case "l": buffer.push(ProtoDate.DAYS[this.getDay()]); break;
45 | case "D": buffer.push(ProtoDate.DAYS[this.getDay()].substr(0, 3)); break;
46 | case "F": buffer.push(ProtoDate.MONTHS[this.getMonth()]); break;
47 | case "M": buffer.push(ProtoDate.MONTHS[this.getMonth()].substring(0, 3)); break;
48 | case "c": buffer.push(this.toISOString()); break;
49 |
50 | // Ordinal suffix
51 | case "S":
52 | var suffix = false;
53 | var ones = buffer[buffer.length-1].toString()[1];
54 | var tens = buffer[buffer.length-1].toString()[0];
55 | if(undefined === ones){
56 | ones = tens;
57 | tens = null;
58 | }
59 | if(ones == "1") suffix = "st";
60 | if(ones == "2") suffix = "nd";
61 | if(ones == "3") suffix = "rd";
62 | if(tens == "1" || !suffix) suffix = "th";
63 | buffer.push(suffix);
64 | break;
65 |
66 | // ISO-8601 Week number
67 | case "W":
68 | var startDate = new ProtoDate(this.getFullYear(), 0);
69 | var endDate = new ProtoDate(this.getFullYear(), this.getMonth(), this.getDate());
70 | while(endDate.getDay() < 6) endDate.setDate(endDate.getDate()+1);
71 | endDate = endDate.getTime();
72 | var weekNo = 0;
73 | while(startDate.getTime() < endDate){
74 | if(startDate.getDay() == 4) weekNo++;
75 | startDate.setDate(startDate.getDate()+1);
76 | }
77 | buffer.push(weekNo);
78 | break;
79 |
80 | // Day of the year
81 | case "z":
82 | var startDate = new ProtoDate(this.getFullYear(), 0, 1, 0, 0, 0, 0);
83 | var dayNo = 0;
84 | while(startDate.getTime() < this.getTime()){
85 | dayNo++;
86 | startDate.setDate(startDate.getDate()+1);
87 | }
88 | buffer.push(dayNo);
89 | break;
90 |
91 | // Julian Day
92 | case "J":
93 | var y = parseInt(this.format("Y"));
94 | var m = parseInt(this.format("n"));
95 | if(m === 1 || m === 2){
96 | y -= 1;
97 | m += 12;
98 | }
99 | var d = parseInt(this.format("j"));
100 | var a = Math.floor(y/100);
101 | var b = Math.floor(a/4);
102 | var c = 2-a+b;
103 | var e = Math.floor(365.25*(y+4716));
104 | var f = Math.floor(30.6001*(m+1));
105 | buffer.push(c+d+e+f-1524.5);
106 | break;
107 |
108 | // Moon Phase
109 | case "P":
110 | var jd = this.format("J");
111 | var dsn = jd - 2451549.5;
112 | var nm = dsn / 29.53;
113 | var dic = parseFloat("0."+((nm+"").split(".")[1])) * 29.53;
114 | if(dic > 27.65625) return "New Moon";
115 | if(dic > 23.96875) return "Waning Crescent";
116 | if(dic > 20.28125) return "Third Quarter";
117 | if(dic > 16.59375) return "Waning Gibbous";
118 | if(dic > 12.90625) return "Full Moon";
119 | if(dic > 9.21875) return "Waxing Gibbous";
120 | if(dic > 5.53125) return "First Quarter";
121 | if(dic > 1.84375) return "Waxing Crescent";
122 | return "New Moon";
123 | break;
124 |
125 | default: buffer.push(format[i]); break;
126 | }
127 | }
128 | return buffer.join('');
129 | };
130 | })();
--------------------------------------------------------------------------------
/src/fromDate.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Get a native Date object from the ProtoDate object
4 | * @returns {object}
5 | */
6 | (function(){
7 | "use strict";
8 | ProtoDate.fromDate = function (date) {
9 | if(!ProtoDate.isDate(date)) throw new Error("ProtoDate.fromDate expects a Date object.");
10 | return new ProtoDate(date.getTime());
11 | };
12 | })();
--------------------------------------------------------------------------------
/src/getUnixTimestamp.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Return a unix timestamp for the given date
4 | * @returns {undefined}
5 | */
6 | (function(){
7 | ProtoDate.prototype.getUnixTimestamp = function(){
8 | return ~~(this.getTime()/1000);
9 | };
10 | })();
--------------------------------------------------------------------------------
/src/guessFormat.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Guess the format string belonging to a date string
4 | * @returns {string|false}
5 | */
6 | (function(){
7 | "use strict";
8 | ProtoDate.guessFormat = function(dateStr){
9 | var tf, df, i, n;
10 | for(n=0; ncy?"19":"20")+y;
32 | dateStr = dateStr.substr(2);
33 | break;
34 | case "m":
35 | month = dateStr.substr(0,2)-1;
36 | dateStr = dateStr.substr(2);
37 | break;
38 | case "n":
39 | var m = dateStr.match(/^(\d){1,2}/)[0];
40 | month = m-1;
41 | dateStr = dateStr.substr(m.length);
42 | break;
43 | case "d":
44 | day = +dateStr.substr(0,2);
45 | dateStr = dateStr.substr(2);
46 | break;
47 | case "j":
48 | var m = dateStr.match(/^(\d){1,2}/)[0];
49 | day = +m;
50 | dateStr = dateStr.substr(m.length);
51 | break;
52 | case "g":
53 | var h = dateStr.match(/^(\d){1,2}/)[0];
54 | hours = h == 12 ? 0 : +h;
55 | dateStr = dateStr.substr(h.length);
56 | break;
57 | case "G":
58 | hr24 = true;
59 | var h = dateStr.match(/^(\d){1,2}/)[0];
60 | hours = +h;
61 | dateStr = dateStr.substr(h.length);
62 | break;
63 | case "h":
64 | var h = dateStr.substr(0,2);
65 | hours = h == 12 ? 0 : +h;
66 | dateStr = dateStr.substr(2);
67 | break;
68 | case "H":
69 | hr24 = true;
70 | hours = +dateStr.substr(0,2);
71 | dateStr = dateStr.substr(2);
72 | break;
73 | case "i":
74 | minutes = +dateStr.substr(0,2);
75 | dateStr = dateStr.substr(2);
76 | break;
77 | case "s":
78 | seconds = +dateStr.substr(0,2);
79 | dateStr = dateStr.substr(2);
80 | break;
81 | case "v":
82 | milliseconds = +dateStr.substr(0,3);
83 | dateStr = dateStr.substr(3);
84 | break;
85 | case "a":
86 | case "A":
87 | if("pm" == dateStr.substr(0,2).toLowerCase()) am=false;
88 | break;
89 | case "l":
90 | var d = dateStr.toLowerCase(), dd=false;
91 | for(var n=0; n6 && !d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,6))){
101 | abrlen = 6; break;
102 | }
103 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,5))){
104 | abrlen = 5; break;
105 | }
106 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,4))){
107 | abrlen = 4; break;
108 | }
109 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,3))){
110 | abrlen = 3; break;
111 | }
112 | }
113 | dateStr = dateStr.substr(abrlen);
114 | break;
115 | case "F":
116 | var m = dateStr.toLowerCase(), mm=false, idx=0;
117 | for(var n=0; n> $jsfileall
27 | echo " " >> $jsfileltd
28 | echo "(function(){" >> $jsfileall
29 | echo "(function(){" >> $jsfileltd
30 | echo " ProtoDate.TZData = {" >> $jsfileall
31 | echo " ProtoDate.TZData = {" >> $jsfileltd
32 | echo " // \"zone_name\": [[\"abbreviation\", \"time_start\", \"gmt_offset\", \"dst\"],...]" >> $jsfileall
33 | echo " // \"zone_name\": [[\"abbreviation\", \"time_start\", \"gmt_offset\", \"dst\"],...]" >> $jsfileltd
34 |
35 | mysql --user="$user" --password="$password" --database="$database" --skip-column-names --execute="SELECT DISTINCT zone_name zn FROM timezonedb.zone ORDER BY zone_name ASC" | while read zn; do
36 |
37 | echo " \"$zn\": [" >> $jsfileall
38 | echo " \"$zn\": [" >> $jsfileltd
39 |
40 | echo $zn
41 |
42 | mysql --user="$user" --password="$password" --database="$database" --skip-column-names --execute="SELECT tz.abbreviation, tz.time_start, tz.gmt_offset, tz.dst, z.zone_name FROM timezone tz JOIN zone z ON tz.zone_id = z.zone_id WHERE z.zone_name = \"$zn\" ORDER BY tz.time_start ASC" | while read abbreviation time_start gmt_offset dst zone_name; do
43 | echo " [\"$abbreviation\", $time_start, $gmt_offset, $dst]," >> $jsfileall
44 | done
45 |
46 | FOUND=$(mysql --user="$user" --password="$password" --database="$database" --skip-column-names --execute="SELECT tz.abbreviation, tz.time_start, tz.gmt_offset, tz.dst, z.zone_name FROM timezone tz JOIN zone z ON tz.zone_id = z.zone_id WHERE z.zone_name = \"$zn\" AND tz.time_start > 1325375999 AND tz.time_start < 1672531200 ORDER BY tz.time_start ASC" | while read abbreviation time_start gmt_offset dst zone_name; do
47 | echo " [\"$abbreviation\", $time_start, $gmt_offset, $dst]," >> $jsfileltd
48 | echo "1"
49 | done)
50 |
51 | if [ "$FOUND" = "" ]; then
52 | mysql --user="$user" --password="$password" --database="$database" --skip-column-names --execute="SELECT tz.abbreviation, tz.time_start, tz.gmt_offset, tz.dst, z.zone_name FROM timezone tz JOIN zone z ON tz.zone_id = z.zone_id WHERE tz.abbreviation != \"LMT\" AND z.zone_name = \"$zn\" ORDER BY tz.time_start ASC LIMIT 1" | while read abbreviation time_start gmt_offset dst zone_name; do
53 | echo " [\"$abbreviation\", -4260211200, $gmt_offset, $dst]," >> $jsfileltd
54 | done
55 | fi
56 |
57 | echo " ]," >> $jsfileall
58 | echo " ]," >> $jsfileltd
59 | done
60 |
61 | echo " };" >> $jsfileall
62 | echo " };" >> $jsfileltd
63 | echo "})();" >> $jsfileall
64 | echo "})();" >> $jsfileltd
65 | mysql --user="$user" --password="$password" --execute="DROP DATABASE IF EXISTS $database;"
66 | echo "All done."
--------------------------------------------------------------------------------
/src/timezones/getTZInfo.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Get information about a specific timezone
4 | * @returns {Object}
5 | */
6 | (function(){
7 | ProtoDate.getTZInfo = function(unix_timestamp, timezone){
8 | var row;
9 | if(undefined === ProtoDate.TZData[timezone]) throw new Error("No such timezone: "+timezone);
10 | var data = ProtoDate.TZData[timezone];
11 | var l = data.length;
12 | var row;
13 | for(var i=l; i--;){
14 | if(data[i][1] > unix_timestamp) continue;
15 | row = data[i];
16 | break;
17 | }
18 | return {abbr:row[0], time_start:row[1], gmt_offset:row[2], dst:row[3]};
19 | };
20 | })();
--------------------------------------------------------------------------------
/src/timezones/getTimezone.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Get the timezone of the date
4 | * @returns {String}
5 | */
6 | (function(){
7 | ProtoDate.prototype.getTimezone = function(){
8 | return this._timezone || Intl.DateTimeFormat().resolvedOptions().timeZone;
9 | };
10 | })();
--------------------------------------------------------------------------------
/src/timezones/isDST.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Is the given date currently observing DST
4 | * @returns {undefined}
5 | */
6 | (function(){
7 | ProtoDate.prototype.isDST = function(){
8 | var timezone = this.getTimezone();
9 | var timestamp = this.getUnixTimestamp();
10 | var tzdata = ProtoDate.getTZInfo(timestamp, timezone);
11 | return tzdata.dst == 1;
12 | };
13 | })();
--------------------------------------------------------------------------------
/src/timezones/isDSTObserved.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Is DST observed in the given timezone
4 | * @returns {undefined}
5 | */
6 | (function(){
7 | ProtoDate.isDSTObserved = function(timezone){
8 | if(undefined === ProtoDate.TZData[timezone]) throw new Error("No such timezone: "+timezone);
9 | var data = ProtoDate.TZData[timezone];
10 | var l = data.length;
11 | for(var i=l; i--;){
12 | if(data[i][3] == 0) continue;
13 | DSTObserved = true;
14 | break;
15 | }
16 | return DSTObserved;
17 | };
18 | })();
--------------------------------------------------------------------------------
/src/timezones/setTimezone.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Set the timezone of a given date
4 | * @returns {Date}
5 | */
6 | (function(){
7 | ProtoDate.prototype.setTimezone = function(timezone){
8 | var timestamp = this.getUnixTimestamp();
9 | var tzdata = ProtoDate.getTZInfo(timestamp, timezone);
10 | var date = new ProtoDate((timestamp+tzdata.gmt_offset)*1000);
11 | this.getFullYear=function(){return date.getUTCFullYear();};
12 | this.getMonth=function(){return date.getUTCMonth();};
13 | this.getDate=function(){return date.getUTCDate();};
14 | this.getHours=function(){return date.getUTCHours();};
15 | this.getMinutes=function(){return date.getUTCMinutes();};
16 | this.getSeconds=function(){return date.getUTCSeconds();};
17 | this.getMilliseconds=function(){return date.getUTCMilliseconds();};
18 | this.getTimezoneOffset=function(){return tzdata.gmt_offset/60;};
19 | this.toString = function(){
20 | var s = tzdata.gmt_offset < 0 ? "-" : "+";
21 | var offset = "GMT"+s+(("0"+Math.abs(tzdata.gmt_offset/3600)).substr(-2))+"00";
22 | return this.format("D M d Y H:i:s")+" "+offset+" ("+tzdata.abbr+")";
23 | };
24 | this.toDateString=function(){return this.format("D M d Y");};
25 | this._timezone = timezone;
26 | return this;
27 | };
28 | })();
--------------------------------------------------------------------------------
/src/toDate.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Get a native Date object from the ProtoDate object
4 | * @returns {object}
5 | */
6 | (function(){
7 | "use strict";
8 | ProtoDate.prototype.toDate = function () {
9 | return new Date(this.getTime())
10 | };
11 | })();
--------------------------------------------------------------------------------
/src/validateFormat.js:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | * Validate a date string against a format string
4 | * @returns {bool}
5 | */
6 | (function(){
7 | "use strict";
8 | ProtoDate.validateFormat = function(dateStr, formatStr){
9 | for(var i=0; i12 || !+dateStr.substr(0,2)) return false;
26 | dateStr = dateStr.substr(2);
27 | break;
28 | case "n":
29 | case "g":
30 | var m = dateStr.match(/^(\d){1,2}/)||[];
31 | if(!m.length || +m[0]>12 || !+m[0]) return false;
32 | dateStr = dateStr.substr(m[0].length);
33 | break;
34 | case "d":
35 | if(!/^(\d){2}/.test(dateStr) || +dateStr.substr(0,2)>31 || !+dateStr.substr(0,2)) return false;
36 | dateStr = dateStr.substr(2);
37 | break;
38 | case "j":
39 | var m = dateStr.match(/^(\d){1,2}/)||[];
40 | if(!m.length || +m[0]>31 || !+m[0]) return false;
41 | dateStr = dateStr.substr(m[0].length);
42 | break;
43 | case "G":
44 | var m = dateStr.match(/^(\d){1,2}/)||[];
45 | if(!m.length || +m[0]>23) return false;
46 | dateStr = dateStr.substr(m[0].length);
47 | break;
48 | case "H":
49 | if(!/^(\d){2}/.test(dateStr) || +dateStr.substr(0,2)>23) return false;
50 | dateStr = dateStr.substr(2);
51 | break;
52 | case "i":
53 | case "s":
54 | if(!/^(\d){2}/.test(dateStr) || +dateStr.substr(0,2)>59) return false;
55 | dateStr = dateStr.substr(2);
56 | break;
57 | case "v":
58 | if(!/^(\d){3}/.test(dateStr)) return false;
59 | dateStr = dateStr.substr(3);
60 | break;
61 | case "a":
62 | case "A":
63 | var m = dateStr.substr(0,2).toLowerCase();
64 | if(!~['am','pm'].indexOf(m)) return false;
65 | dateStr = dateStr.substr(2);
66 | break;
67 | case "l":
68 | var d = dateStr.toLowerCase(), day=false;
69 | for(var n=0; n6 && !d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,6))){
82 | abrlen = 6; break;
83 | }
84 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,5))){
85 | abrlen = 5; break;
86 | }
87 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,4))){
88 | abrlen = 4; break;
89 | }
90 | if(!d.indexOf(ProtoDate.DAYS[n].toLowerCase().substr(0,3))){
91 | abrlen = 3; break;
92 | }
93 | }
94 | if(!abrlen) return false;
95 | dateStr = dateStr.substr(abrlen);
96 | break;
97 | case "F":
98 | var m = dateStr.toLowerCase(), mm=false;
99 | for(var n=0; n