Skip to content

Commit 4fe1536

Browse files
committed
Fixed a bug parsing Do format dates
1 parent 4cb1b0f commit 4fe1536

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
### 2.2.0
2+
Fixed a bug when parsing Do format dates
3+
14
## 2.0.0
25
Fecha now throws errors on invalid dates in `fecha.format` and is stricter about what dates it accepts. Dates must pass `Object.prototype.toString.call(dateObj) !== '[object Date]'`.

fecha.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@
144144
D: [twoDigits, function (d, v) {
145145
d.day = v;
146146
}],
147+
Do: [new RegExp(twoDigits.source + word.source), function (d, v) {
148+
d.day = parseInt(v, 10);
149+
}],
147150
M: [twoDigits, function (d, v) {
148151
d.month = v - 1;
149152
}],
@@ -195,7 +198,7 @@
195198
};
196199
parseFlags.dd = parseFlags.d;
197200
parseFlags.dddd = parseFlags.ddd;
198-
parseFlags.Do = parseFlags.DD = parseFlags.D;
201+
parseFlags.DD = parseFlags.D;
199202
parseFlags.mm = parseFlags.m;
200203
parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
201204
parseFlags.MM = parseFlags.M;

fecha.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fecha",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "Date formatting and parsing",
55
"main": "fecha.js",
66
"scripts": {

test.js

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ testParse('basic date parse with time', '2012/05/03 05:01:40', 'YYYY/MM/DD HH:mm
2222
testParse('date with different slashes', '2012-05-03 05:01:40', 'YYYY-MM-DD HH:mm:ss', new Date(2012, 4, 3, 5, 1, 40));
2323
testParse('date with different order', '11-7-97', 'D-M-YY', new Date(1997, 6, 11));
2424
testParse('date very short', '2-8-04', 'D-M-YY', new Date(2004, 7, 2));
25+
testParse('ordinal day 3rd', '3rd May', 'Do MMM', new Date(year, 4, 3));
26+
testParse('ordinal day 23rd, 2013', '23rd May, 2013', 'Do MMM, YYYY', new Date(2013, 4, 23));
27+
testParse('ordinal day 12th, 2002', 'nd12 Nov, 2002', 'Do MMM, YYYY', false);
28+
testParse('ordinal day 13th, 1995', '13thDec, 1995', 'DoMMM, YYYY', new Date(1995, 11, 13));
29+
testParse('ordinal day 13th, 1995', '1stFebruary, 1982', 'DoMMMM, YYYY', new Date(1982, 1, 1));
2530
testParse('compact', '11081997', 'MMDDYYYY', new Date(1997, 10, 8));
2631
testParse('month names', 'March 3rd, 1999', 'MMMM Do, YYYY', new Date(1999, 2, 3));
2732
testParse('month names short', 'Jun 12, 2003', 'MMM D, YYYY', new Date(2003, 5, 12));

0 commit comments

Comments
 (0)