date-format 3.0.0 → 4.0.1

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.
@@ -0,0 +1,70 @@
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
@@ -0,0 +1,31 @@
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
@@ -0,0 +1,38 @@
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/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
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/README.md CHANGED
@@ -15,18 +15,28 @@ Formatting dates as strings
15
15
 
16
16
  ```javascript
17
17
  var format = require('date-format');
18
- format.asString(); //defaults to ISO8601 format and current date.
19
- format.asString(new Date()); //defaults to ISO8601 format
20
- format.asString('hh:mm:ss.SSS', new Date()); //just the time
18
+ format.asString(); // defaults to ISO8601 format and current date
19
+ format.asString(new Date()); // defaults to ISO8601 format
20
+ format.asString('hh:mm:ss.SSS', new Date()); // just the time
21
+ format.asString(format.ISO8601_WITH_TZ_OFFSET_FORMAT, new Date()); // in ISO8601 with timezone
21
22
  ```
22
23
 
23
24
  or
24
25
 
25
26
  ```javascript
26
27
  var format = require('date-format');
27
- format(); //defaults to ISO8601 format and current date.
28
- format(new Date());
29
- format('hh:mm:ss.SSS', new Date());
28
+ format(); // defaults to ISO8601 format and current date
29
+ format(new Date()); // defaults to ISO8601 format
30
+ format('hh:mm:ss.SSS', new Date()); // just the time
31
+ format(format.ISO8601_WITH_TZ_OFFSET_FORMAT, new Date()); // in ISO8601 with timezone
32
+ ```
33
+
34
+ **output:**
35
+ ```javascript
36
+ 2017-03-14T14:10:20.391
37
+ 2017-03-14T14:10:20.391
38
+ 14:10:20.391
39
+ 2017-03-14T14:10:20.391+11:00
30
40
  ```
31
41
 
32
42
  Format string can be anything, but the following letters will be replaced (and leading zeroes added if necessary):
@@ -38,11 +48,11 @@ Format string can be anything, but the following letters will be replaced (and l
38
48
  * mm - `date.getMinutes()`
39
49
  * ss - `date.getSeconds()`
40
50
  * SSS - `date.getMilliseconds()`
41
- * O - timezone offset in +hm format (note that time will be in UTC if displaying offset)
51
+ * O - timezone offset in ±hh:mm format (note that time will still be local if displaying offset)
42
52
 
43
53
  Built-in formats:
44
54
  * `format.ISO8601_FORMAT` - `2017-03-14T14:10:20.391` (local time used)
45
- * `format.ISO8601_WITH_TZ_OFFSET_FORMAT` - `2017-03-14T03:10:20.391+1100` (UTC + TZ used)
55
+ * `format.ISO8601_WITH_TZ_OFFSET_FORMAT` - `2017-03-14T14:10:20.391+11:00` (local + TZ used)
46
56
  * `format.DATETIME_FORMAT` - `14 03 2017 14:10:20.391` (local time used)
47
57
  * `format.ABSOLUTETIME_FORMAT` - `14:10:20.391` (local time used)
48
58
 
@@ -54,5 +64,8 @@ The date format library has limited ability to parse strings into dates. It can
54
64
  var format = require('date-format');
55
65
  // pass in the format of the string as first argument
56
66
  format.parse(format.ISO8601_FORMAT, '2017-03-14T14:10:20.391');
67
+ format.parse(format.ISO8601_WITH_TZ_OFFSET_FORMAT, '2017-03-14T14:10:20.391+1100');
68
+ format.parse(format.ISO8601_WITH_TZ_OFFSET_FORMAT, '2017-03-14T14:10:20.391+11:00');
69
+ format.parse(format.ISO8601_WITH_TZ_OFFSET_FORMAT, '2017-03-14T03:10:20.391Z');
57
70
  // returns Date
58
71
  ```
package/lib/index.js CHANGED
@@ -27,7 +27,7 @@ function offset(timezoneOffset) {
27
27
  if (m.length === 1) {
28
28
  m = "0" + m;
29
29
  }
30
- return timezoneOffset < 0 ? "+" + h + m : "-" + h + m;
30
+ return timezoneOffset === 0 ? "Z" : (timezoneOffset < 0 ? "+" : "-") + h + ":" + m;
31
31
  }
32
32
 
33
33
  function asString(format, date) {
@@ -126,11 +126,14 @@ function extractDateParts(pattern, str, missingValuesDate) {
126
126
  },
127
127
  {
128
128
  pattern: /O/,
129
- regexp: "[+-]\\d{3,4}|Z",
129
+ regexp: "[+-]\\d{1,2}:?\\d{2}?|Z",
130
130
  fn: function(date, value) {
131
131
  if (value === "Z") {
132
132
  value = 0;
133
133
  }
134
+ else {
135
+ value = value.replace(":", "");
136
+ }
134
137
  var offset = Math.abs(value);
135
138
  var timezoneOffset = (value > 0 ? -1 : 1 ) * ((offset % 100) + Math.floor(offset / 100) * 60);
136
139
  // Per ISO8601 standard: UTC = local time - offset
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-format",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Formatting Date objects as strings since 2013",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -25,9 +25,9 @@
25
25
  "readmeFilename": "README.md",
26
26
  "gitHead": "bf59015ab6c9e86454b179374f29debbdb403522",
27
27
  "devDependencies": {
28
- "eslint": "^5.16.0",
28
+ "eslint": "^8.6.0",
29
29
  "eslint-plugin-mocha": "^5.3.0",
30
- "mocha": "^5.2.0",
30
+ "mocha": "^9.1.3",
31
31
  "should": "^13.2.3"
32
32
  }
33
33
  }
@@ -35,7 +35,7 @@ describe('date_format', function() {
35
35
 
36
36
  // when tz offset is in the pattern, the date should be in local time
37
37
  dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, tzDate)
38
- .should.eql('2010-01-11T14:31:30.005+1100');
38
+ .should.eql('2010-01-11T14:31:30.005+11:00');
39
39
 
40
40
  tzDate = createFixedDate();
41
41
  tzDate.getTimezoneOffset = function () {
@@ -43,7 +43,7 @@ describe('date_format', function() {
43
43
  };
44
44
 
45
45
  dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, tzDate)
46
- .should.eql('2010-01-11T14:31:30.005-0200');
46
+ .should.eql('2010-01-11T14:31:30.005-02:00');
47
47
  });
48
48
 
49
49
  it('should provide a just-the-time format', function() {
@@ -56,6 +56,6 @@ describe('date_format', function() {
56
56
  return 120;
57
57
  };
58
58
 
59
- dateFormat.asString('O.SSS.ss.mm.hh.dd.MM.yy', customDate).should.eql('-0200.005.30.31.14.11.01.10');
59
+ dateFormat.asString('O.SSS.ss.mm.hh.dd.MM.yy', customDate).should.eql('-02:00.005.30.31.14.11.01.10');
60
60
  });
61
61
  });
@@ -159,8 +159,8 @@ describe("dateFormat.parse", function() {
159
159
  verifyDate(date, { hours: 7, minutes: 23 });
160
160
  });
161
161
 
162
- it("works with hh:mm O (+0930)", function() {
163
- var date = dateFormat.parse("hh:mm O", "05:23 +0930");
162
+ it("works with hh:mm O (+09:30)", function() {
163
+ var date = dateFormat.parse("hh:mm O", "05:23 +09:30");
164
164
  verifyDate(date, { hours: 19, minutes: 53 });
165
165
  });
166
166
  });