date-format 4.0.10 → 4.0.11

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # date-format Changelog
2
2
 
3
+ ## 4.0.11
4
+
5
+ - [fix: date parsing errors (wrong month due to days overflow)](https://github.com/nomiddlename/date-format/pull/68) - thanks [@peteriman](https://github.com/peteriman)
6
+ - [test: use new Date(0) instead of new Date() before setting every field]() - thanks [@peteriman](https://github.com/peteriman)
7
+ - [chore(deps-dev): updated dependencies](https://github.com/nomiddlename/date-format/pull/70) - thanks [@peteriman](https://github.com/peteriman)
8
+ - chore(deps-dev): bump eslint from 8.15.0 to 8.16.0
9
+ - chore(deps-dev): bump eslint-plugin-mocha from 10.0.4 to 10.0.5
10
+ - chore(deps-dev): updated package-lock.json
11
+
3
12
  ## 4.0.10
4
13
 
5
14
  - [chore(deps-dev): updated dependencies](https://github.com/nomiddlename/date-format/pull/66) - thanks [@peteriman](https://github.com/peteriman)
package/lib/index.js CHANGED
@@ -70,6 +70,7 @@ function extractDateParts(pattern, str, missingValuesDate) {
70
70
  // GMT based to begin with. If the timezone offset is provided, then adjust
71
71
  // it using provided timezone, otherwise, adjust it with the system timezone.
72
72
  var local = pattern.indexOf('O') < 0;
73
+ var monthOverflow = false;
73
74
  var matchers = [
74
75
  {
75
76
  pattern: /y{1,4}/,
@@ -83,12 +84,22 @@ function extractDateParts(pattern, str, missingValuesDate) {
83
84
  regexp: "\\d{1,2}",
84
85
  fn: function(date, value) {
85
86
  setDatePart(date, 'Month', (value - 1), local);
87
+ if (date.getMonth() !== (value - 1)) {
88
+ // in the event of 31 May --> 31 Feb --> 3 Mar
89
+ // this is correct behavior if no Date is involved
90
+ monthOverflow = true;
91
+ }
86
92
  }
87
93
  },
88
94
  {
89
95
  pattern: /dd/,
90
96
  regexp: "\\d{1,2}",
91
97
  fn: function(date, value) {
98
+ // in the event of 31 May --> 31 Feb --> 3 Mar
99
+ // reset Mar back to Feb, before setting the Date
100
+ if (monthOverflow) {
101
+ setDatePart(date, 'Month', (date.getMonth() - 1), local);
102
+ }
92
103
  setDatePart(date, 'Date', value, local);
93
104
  }
94
105
  },
@@ -149,7 +160,7 @@ function extractDateParts(pattern, str, missingValuesDate) {
149
160
  // representation was wrong. It needs to be fixed by substracting the
150
161
  // offset (or adding the offset minutes as they are opposite sign).
151
162
  //
152
- // Note: the time zone has to be processed after all other fileds are
163
+ // Note: the time zone has to be processed after all other fields are
153
164
  // set. The result would be incorrect if the offset was calculated
154
165
  // first then overriden by the other filed setters.
155
166
  date.setUTCMinutes(date.getUTCMinutes() + timezoneOffset);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-format",
3
- "version": "4.0.10",
3
+ "version": "4.0.11",
4
4
  "description": "Formatting Date objects as strings since 2013",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -29,8 +29,8 @@
29
29
  "readmeFilename": "README.md",
30
30
  "gitHead": "bf59015ab6c9e86454b179374f29debbdb403522",
31
31
  "devDependencies": {
32
- "eslint": "^8.15.0",
33
- "eslint-plugin-mocha": "^10.0.4",
32
+ "eslint": "^8.16.0",
33
+ "eslint-plugin-mocha": "^10.0.5",
34
34
  "mocha": "^10.0.0",
35
35
  "nyc": "^15.1.0",
36
36
  "should": "^13.2.3"