date-format 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -2
- package/.eslintrc +0 -12
- package/.github/workflows/codeql-analysis.yml +0 -70
- package/.github/workflows/node.js.yml +0 -31
- package/.github/workflows/npm-publish.yml +0 -38
- package/.travis.yml +0 -6
- package/CHANGELOG.md +0 -16
- package/test/date_format-test.js +0 -61
- package/test/parse-test.js +0 -220
package/package.json
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "date-format",
|
3
|
-
"version": "4.0.
|
3
|
+
"version": "4.0.2",
|
4
4
|
"description": "Formatting Date objects as strings since 2013",
|
5
5
|
"main": "lib/index.js",
|
6
|
+
"files": [
|
7
|
+
"lib"
|
8
|
+
],
|
6
9
|
"repository": {
|
7
10
|
"type": "git",
|
8
11
|
"url": "https://github.com/nomiddlename/date-format.git"
|
@@ -26,7 +29,7 @@
|
|
26
29
|
"gitHead": "bf59015ab6c9e86454b179374f29debbdb403522",
|
27
30
|
"devDependencies": {
|
28
31
|
"eslint": "^8.6.0",
|
29
|
-
"eslint-plugin-mocha": "^
|
32
|
+
"eslint-plugin-mocha": "^10.0.3",
|
30
33
|
"mocha": "^9.1.3",
|
31
34
|
"should": "^13.2.3"
|
32
35
|
}
|
package/.eslintrc
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
# For most projects, this workflow file will not need changing; you simply need
|
2
|
-
# to commit it to your repository.
|
3
|
-
#
|
4
|
-
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
-
# or to provide custom queries or build logic.
|
6
|
-
#
|
7
|
-
# ******** NOTE ********
|
8
|
-
# We have attempted to detect the languages in your repository. Please check
|
9
|
-
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
-
# supported CodeQL languages.
|
11
|
-
#
|
12
|
-
name: "CodeQL"
|
13
|
-
|
14
|
-
on:
|
15
|
-
push:
|
16
|
-
branches: [ master ]
|
17
|
-
pull_request:
|
18
|
-
# The branches below must be a subset of the branches above
|
19
|
-
branches: [ master ]
|
20
|
-
schedule:
|
21
|
-
- cron: '34 6 * * 1'
|
22
|
-
|
23
|
-
jobs:
|
24
|
-
analyze:
|
25
|
-
name: Analyze
|
26
|
-
runs-on: ubuntu-latest
|
27
|
-
permissions:
|
28
|
-
actions: read
|
29
|
-
contents: read
|
30
|
-
security-events: write
|
31
|
-
|
32
|
-
strategy:
|
33
|
-
fail-fast: false
|
34
|
-
matrix:
|
35
|
-
language: [ 'javascript' ]
|
36
|
-
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
-
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
38
|
-
|
39
|
-
steps:
|
40
|
-
- name: Checkout repository
|
41
|
-
uses: actions/checkout@v2
|
42
|
-
|
43
|
-
# Initializes the CodeQL tools for scanning.
|
44
|
-
- name: Initialize CodeQL
|
45
|
-
uses: github/codeql-action/init@v1
|
46
|
-
with:
|
47
|
-
languages: ${{ matrix.language }}
|
48
|
-
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
-
# By default, queries listed here will override any specified in a config file.
|
50
|
-
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
52
|
-
|
53
|
-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
54
|
-
# If this step fails, then you should remove it and run the build manually (see below)
|
55
|
-
- name: Autobuild
|
56
|
-
uses: github/codeql-action/autobuild@v1
|
57
|
-
|
58
|
-
# ℹ️ Command-line programs to run using the OS shell.
|
59
|
-
# 📚 https://git.io/JvXDl
|
60
|
-
|
61
|
-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
62
|
-
# and modify them (or add more) to build your code if your project
|
63
|
-
# uses a compiled language
|
64
|
-
|
65
|
-
#- run: |
|
66
|
-
# make bootstrap
|
67
|
-
# make release
|
68
|
-
|
69
|
-
- name: Perform CodeQL Analysis
|
70
|
-
uses: github/codeql-action/analyze@v1
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
2
|
-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
3
|
-
|
4
|
-
name: Node.js CI
|
5
|
-
|
6
|
-
on:
|
7
|
-
push:
|
8
|
-
branches: [ master ]
|
9
|
-
pull_request:
|
10
|
-
branches: [ master ]
|
11
|
-
|
12
|
-
jobs:
|
13
|
-
build:
|
14
|
-
|
15
|
-
runs-on: ubuntu-latest
|
16
|
-
|
17
|
-
strategy:
|
18
|
-
matrix:
|
19
|
-
node-version: [12.x, 14.x, 16.x]
|
20
|
-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
21
|
-
|
22
|
-
steps:
|
23
|
-
- uses: actions/checkout@v2
|
24
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
25
|
-
uses: actions/setup-node@v2
|
26
|
-
with:
|
27
|
-
node-version: ${{ matrix.node-version }}
|
28
|
-
cache: 'npm'
|
29
|
-
- run: npm ci
|
30
|
-
- run: npm run build --if-present
|
31
|
-
- run: npm test
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# This workflow will run tests using node and then publish a package to GitHub Packages when a milestone is closed
|
2
|
-
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
|
3
|
-
|
4
|
-
name: Node.js Package
|
5
|
-
|
6
|
-
on:
|
7
|
-
milestone:
|
8
|
-
types: [closed]
|
9
|
-
|
10
|
-
jobs:
|
11
|
-
build:
|
12
|
-
runs-on: ubuntu-latest
|
13
|
-
steps:
|
14
|
-
- uses: actions/checkout@v2
|
15
|
-
- uses: actions/setup-node@v2
|
16
|
-
with:
|
17
|
-
node-version: 16
|
18
|
-
- run: npm ci
|
19
|
-
- run: npm test
|
20
|
-
|
21
|
-
publish-npm:
|
22
|
-
needs: build
|
23
|
-
runs-on: ubuntu-latest
|
24
|
-
steps:
|
25
|
-
- uses: actions/checkout@v2
|
26
|
-
- uses: actions/setup-node@v2
|
27
|
-
with:
|
28
|
-
node-version: 16
|
29
|
-
registry-url: https://registry.npmjs.org/
|
30
|
-
- run: npm ci
|
31
|
-
- run: |
|
32
|
-
git config user.name github-actions
|
33
|
-
git config user.email github-actions@github.com
|
34
|
-
- run: npm version ${{ github.event.milestone.title }}
|
35
|
-
- run: git push && git push --tags
|
36
|
-
- run: npm publish
|
37
|
-
env:
|
38
|
-
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/.travis.yml
DELETED
package/CHANGELOG.md
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
# log4js-node changelog
|
2
|
-
|
3
|
-
## 4.0.0
|
4
|
-
|
5
|
-
- [Fix timezone format to include colon separator](https://github.com/nomiddlename/date-format/pull/27) - thanks [@peteriman](https://github.com/peteriman)
|
6
|
-
- [test: have a test case for timezone with colon](https://github.com/nomiddlename/date-format/pull/32) - thanks [@peteriman](https://github.com/peteriman)
|
7
|
-
- [Docs: Updated README.md with more examples and expected output](https://github.com/nomiddlename/date-format/pull/33) - thanks [@peteriman](https://github.com/peteriman)
|
8
|
-
- Updated dependencies
|
9
|
-
- [should-util from 1.0.0 to 1.0.1](https://github.com/nomiddlename/date-format/pull/31)
|
10
|
-
- [eslint from 5.16.0 to 8.6.0 and mocha from 5.2.0 to 9.1.3](https://github.com/nomiddlename/date-format/pull/30)
|
11
|
-
- [acorn from 6.2.0 to 6.4.2](https://github.com/nomiddlename/date-format/pull/29)
|
12
|
-
- [lodash from 4.17.14 to 4.17.21](https://github.com/nomiddlename/date-format/pull/26)
|
13
|
-
|
14
|
-
## Previous versions
|
15
|
-
|
16
|
-
Change information for older versions can be found by looking at the milestones in github.
|
package/test/date_format-test.js
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
require('should');
|
4
|
-
|
5
|
-
var dateFormat = require('../lib');
|
6
|
-
|
7
|
-
function createFixedDate() {
|
8
|
-
return new Date(2010, 0, 11, 14, 31, 30, 5);
|
9
|
-
}
|
10
|
-
|
11
|
-
describe('date_format', function() {
|
12
|
-
var date = createFixedDate();
|
13
|
-
|
14
|
-
it('should default to now when a date is not provided', function() {
|
15
|
-
dateFormat.asString(dateFormat.DATETIME_FORMAT).should.not.be.empty();
|
16
|
-
});
|
17
|
-
|
18
|
-
it('should be usable directly without calling asString', function() {
|
19
|
-
dateFormat(dateFormat.DATETIME_FORMAT, date).should.eql('11 01 2010 14:31:30.005');
|
20
|
-
});
|
21
|
-
|
22
|
-
it('should format a date as string using a pattern', function() {
|
23
|
-
dateFormat.asString(dateFormat.DATETIME_FORMAT, date).should.eql('11 01 2010 14:31:30.005');
|
24
|
-
});
|
25
|
-
|
26
|
-
it('should default to the ISO8601 format', function() {
|
27
|
-
dateFormat.asString(date).should.eql('2010-01-11T14:31:30.005');
|
28
|
-
});
|
29
|
-
|
30
|
-
it('should provide a ISO8601 with timezone offset format', function() {
|
31
|
-
var tzDate = createFixedDate();
|
32
|
-
tzDate.getTimezoneOffset = function () {
|
33
|
-
return -660;
|
34
|
-
};
|
35
|
-
|
36
|
-
// when tz offset is in the pattern, the date should be in local time
|
37
|
-
dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, tzDate)
|
38
|
-
.should.eql('2010-01-11T14:31:30.005+11:00');
|
39
|
-
|
40
|
-
tzDate = createFixedDate();
|
41
|
-
tzDate.getTimezoneOffset = function () {
|
42
|
-
return 120;
|
43
|
-
};
|
44
|
-
|
45
|
-
dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, tzDate)
|
46
|
-
.should.eql('2010-01-11T14:31:30.005-02:00');
|
47
|
-
});
|
48
|
-
|
49
|
-
it('should provide a just-the-time format', function() {
|
50
|
-
dateFormat.asString(dateFormat.ABSOLUTETIME_FORMAT, date).should.eql('14:31:30.005');
|
51
|
-
});
|
52
|
-
|
53
|
-
it('should provide a custom format', function() {
|
54
|
-
var customDate = createFixedDate();
|
55
|
-
customDate.getTimezoneOffset = function () {
|
56
|
-
return 120;
|
57
|
-
};
|
58
|
-
|
59
|
-
dateFormat.asString('O.SSS.ss.mm.hh.dd.MM.yy', customDate).should.eql('-02:00.005.30.31.14.11.01.10');
|
60
|
-
});
|
61
|
-
});
|
package/test/parse-test.js
DELETED
@@ -1,220 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
require("should");
|
4
|
-
var dateFormat = require("../lib");
|
5
|
-
|
6
|
-
describe("dateFormat.parse", function() {
|
7
|
-
it("should require a pattern", function() {
|
8
|
-
(function() {
|
9
|
-
dateFormat.parse();
|
10
|
-
}.should.throw(/pattern must be supplied/));
|
11
|
-
(function() {
|
12
|
-
dateFormat.parse(null);
|
13
|
-
}.should.throw(/pattern must be supplied/));
|
14
|
-
(function() {
|
15
|
-
dateFormat.parse("");
|
16
|
-
}.should.throw(/pattern must be supplied/));
|
17
|
-
});
|
18
|
-
|
19
|
-
describe("with a pattern that has no replacements", function() {
|
20
|
-
it("should return a new date when the string matches", function() {
|
21
|
-
dateFormat.parse("cheese", "cheese").should.be.a.Date();
|
22
|
-
});
|
23
|
-
|
24
|
-
it("should throw if the string does not match", function() {
|
25
|
-
(function() {
|
26
|
-
dateFormat.parse("cheese", "biscuits");
|
27
|
-
}.should.throw(/String 'biscuits' could not be parsed as 'cheese'/));
|
28
|
-
});
|
29
|
-
});
|
30
|
-
|
31
|
-
describe("with a full pattern", function() {
|
32
|
-
var pattern = "yyyy-MM-dd hh:mm:ss.SSSO";
|
33
|
-
|
34
|
-
it("should return the correct date if the string matches", function() {
|
35
|
-
var testDate = new Date();
|
36
|
-
testDate.setUTCFullYear(2018);
|
37
|
-
testDate.setUTCMonth(8);
|
38
|
-
testDate.setUTCDate(13);
|
39
|
-
testDate.setUTCHours(18);
|
40
|
-
testDate.setUTCMinutes(10);
|
41
|
-
testDate.setUTCSeconds(12);
|
42
|
-
testDate.setUTCMilliseconds(392);
|
43
|
-
|
44
|
-
dateFormat
|
45
|
-
.parse(pattern, "2018-09-14 04:10:12.392+1000")
|
46
|
-
.getTime()
|
47
|
-
.should.eql(testDate.getTime())
|
48
|
-
;
|
49
|
-
});
|
50
|
-
|
51
|
-
it("should throw if the string does not match", function() {
|
52
|
-
(function() {
|
53
|
-
dateFormat.parse(pattern, "biscuits");
|
54
|
-
}.should.throw(
|
55
|
-
/String 'biscuits' could not be parsed as 'yyyy-MM-dd hh:mm:ss.SSSO'/
|
56
|
-
));
|
57
|
-
});
|
58
|
-
});
|
59
|
-
|
60
|
-
describe("with a partial pattern", function() {
|
61
|
-
var testDate = new Date();
|
62
|
-
dateFormat.now = function() {
|
63
|
-
return testDate;
|
64
|
-
};
|
65
|
-
|
66
|
-
/**
|
67
|
-
* If there's no timezone in the format, then we verify against the local date
|
68
|
-
*/
|
69
|
-
function verifyLocalDate(actual, expected) {
|
70
|
-
actual.getFullYear().should.eql(expected.year || testDate.getFullYear());
|
71
|
-
actual.getMonth().should.eql(expected.month || testDate.getMonth());
|
72
|
-
actual.getDate().should.eql(expected.day || testDate.getDate());
|
73
|
-
actual.getHours().should.eql(expected.hours || testDate.getHours());
|
74
|
-
actual.getMinutes().should.eql(expected.minutes || testDate.getMinutes());
|
75
|
-
actual.getSeconds().should.eql(expected.seconds || testDate.getSeconds());
|
76
|
-
actual
|
77
|
-
.getMilliseconds()
|
78
|
-
.should.eql(expected.milliseconds || testDate.getMilliseconds());
|
79
|
-
}
|
80
|
-
|
81
|
-
/**
|
82
|
-
* If a timezone is specified, let's verify against the UTC time it is supposed to be
|
83
|
-
*/
|
84
|
-
function verifyDate(actual, expected) {
|
85
|
-
actual.getUTCFullYear().should.eql(expected.year || testDate.getUTCFullYear());
|
86
|
-
actual.getUTCMonth().should.eql(expected.month || testDate.getUTCMonth());
|
87
|
-
actual.getUTCDate().should.eql(expected.day || testDate.getUTCDate());
|
88
|
-
actual.getUTCHours().should.eql(expected.hours || testDate.getUTCHours());
|
89
|
-
actual.getUTCMinutes().should.eql(expected.minutes || testDate.getUTCMinutes());
|
90
|
-
actual.getUTCSeconds().should.eql(expected.seconds || testDate.getUTCSeconds());
|
91
|
-
actual
|
92
|
-
.getMilliseconds()
|
93
|
-
.should.eql(expected.milliseconds || testDate.getMilliseconds());
|
94
|
-
}
|
95
|
-
|
96
|
-
it("should return a date with missing values defaulting to current time", function() {
|
97
|
-
var date = dateFormat.parse("yyyy-MM", "2015-09");
|
98
|
-
verifyLocalDate(date, { year: 2015, month: 8 });
|
99
|
-
});
|
100
|
-
|
101
|
-
it("should use a passed in date for missing values", function() {
|
102
|
-
var missingValueDate = new Date(2010, 1, 8, 22, 30, 12, 100);
|
103
|
-
var date = dateFormat.parse("yyyy-MM", "2015-09", missingValueDate);
|
104
|
-
verifyLocalDate(date, {
|
105
|
-
year: 2015,
|
106
|
-
month: 8,
|
107
|
-
day: 8,
|
108
|
-
hours: 22,
|
109
|
-
minutes: 30,
|
110
|
-
seconds: 12,
|
111
|
-
milliseconds: 100
|
112
|
-
});
|
113
|
-
});
|
114
|
-
|
115
|
-
it("should handle variations on the same pattern", function() {
|
116
|
-
var date = dateFormat.parse("MM-yyyy", "09-2015");
|
117
|
-
verifyLocalDate(date, { year: 2015, month: 8 });
|
118
|
-
|
119
|
-
date = dateFormat.parse("yyyy MM", "2015 09");
|
120
|
-
verifyLocalDate(date, { year: 2015, month: 8 });
|
121
|
-
|
122
|
-
date = dateFormat.parse("MM, yyyy.", "09, 2015.");
|
123
|
-
verifyLocalDate(date, { year: 2015, month: 8 });
|
124
|
-
});
|
125
|
-
|
126
|
-
describe("should match all the date parts", function() {
|
127
|
-
it("works with dd", function() {
|
128
|
-
var date = dateFormat.parse("dd", "21");
|
129
|
-
verifyLocalDate(date, { day: 21 });
|
130
|
-
});
|
131
|
-
|
132
|
-
it("works with hh", function() {
|
133
|
-
var date = dateFormat.parse("hh", "12");
|
134
|
-
verifyLocalDate(date, { hours: 12 });
|
135
|
-
});
|
136
|
-
|
137
|
-
it("works with mm", function() {
|
138
|
-
var date = dateFormat.parse("mm", "34");
|
139
|
-
verifyLocalDate(date, { minutes: 34 });
|
140
|
-
});
|
141
|
-
|
142
|
-
it("works with ss", function() {
|
143
|
-
var date = dateFormat.parse("ss", "59");
|
144
|
-
verifyLocalDate(date, { seconds: 59 });
|
145
|
-
});
|
146
|
-
|
147
|
-
it("works with ss.SSS", function() {
|
148
|
-
var date = dateFormat.parse("ss.SSS", "23.452");
|
149
|
-
verifyLocalDate(date, { seconds: 23, milliseconds: 452 });
|
150
|
-
});
|
151
|
-
|
152
|
-
it("works with hh:mm O (+1000)", function() {
|
153
|
-
var date = dateFormat.parse("hh:mm O", "05:23 +1000");
|
154
|
-
verifyDate(date, { hours: 19, minutes: 23 });
|
155
|
-
});
|
156
|
-
|
157
|
-
it("works with hh:mm O (-200)", function() {
|
158
|
-
var date = dateFormat.parse("hh:mm O", "05:23 -200");
|
159
|
-
verifyDate(date, { hours: 7, minutes: 23 });
|
160
|
-
});
|
161
|
-
|
162
|
-
it("works with hh:mm O (+09:30)", function() {
|
163
|
-
var date = dateFormat.parse("hh:mm O", "05:23 +09:30");
|
164
|
-
verifyDate(date, { hours: 19, minutes: 53 });
|
165
|
-
});
|
166
|
-
});
|
167
|
-
});
|
168
|
-
|
169
|
-
describe("with a date formatted by this library", function() {
|
170
|
-
describe("should format and then parse back to the same date", function() {
|
171
|
-
function testDateInitWithUTC() {
|
172
|
-
var td = new Date();
|
173
|
-
td.setUTCFullYear(2018);
|
174
|
-
td.setUTCMonth(8);
|
175
|
-
td.setUTCDate(13);
|
176
|
-
td.setUTCHours(18);
|
177
|
-
td.setUTCMinutes(10);
|
178
|
-
td.setUTCSeconds(12);
|
179
|
-
td.setUTCMilliseconds(392);
|
180
|
-
return td;
|
181
|
-
}
|
182
|
-
|
183
|
-
it("works with ISO8601_WITH_TZ_OFFSET_FORMAT", function() {
|
184
|
-
// For this test case to work, the date object must be initialized with
|
185
|
-
// UTC timezone
|
186
|
-
var td = testDateInitWithUTC();
|
187
|
-
var d = dateFormat(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, td);
|
188
|
-
dateFormat.parse(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, d)
|
189
|
-
.should.eql(td);
|
190
|
-
});
|
191
|
-
|
192
|
-
it("works with ISO8601_FORMAT", function() {
|
193
|
-
var td = new Date();
|
194
|
-
var d = dateFormat(dateFormat.ISO8601_FORMAT, td);
|
195
|
-
var actual = dateFormat.parse(dateFormat.ISO8601_FORMAT, d);
|
196
|
-
actual.should.eql(td);
|
197
|
-
});
|
198
|
-
|
199
|
-
it("works with DATETIME_FORMAT", function() {
|
200
|
-
var testDate = new Date();
|
201
|
-
dateFormat
|
202
|
-
.parse(
|
203
|
-
dateFormat.DATETIME_FORMAT,
|
204
|
-
dateFormat(dateFormat.DATETIME_FORMAT, testDate)
|
205
|
-
)
|
206
|
-
.should.eql(testDate);
|
207
|
-
});
|
208
|
-
|
209
|
-
it("works with ABSOLUTETIME_FORMAT", function() {
|
210
|
-
var testDate = new Date();
|
211
|
-
dateFormat
|
212
|
-
.parse(
|
213
|
-
dateFormat.ABSOLUTETIME_FORMAT,
|
214
|
-
dateFormat(dateFormat.ABSOLUTETIME_FORMAT, testDate)
|
215
|
-
)
|
216
|
-
.should.eql(testDate);
|
217
|
-
});
|
218
|
-
});
|
219
|
-
});
|
220
|
-
});
|