Comments (6)
The code you tried is this?
date.parse('1/1/1', 'DD/MM/Y');
In the latest version, this code will return Invalid Date
. That is, error. Are you using the latest version?
from date-and-time.
from date-and-time.
Could you show reproducible code here?
and 1/1/0 or 1/1/00 cannot be parsed at all.
It's in the specifications.
from date-and-time.
What pattern should I use to parse as following:
1/1/1 -> 1 January 2001
1/1/0 -> 1 January 2000
1/1/20 -> 1 January 2020
1/1/75 -> 1 January 1975
Current version seems lost this distinctive feature, the only reason we have chosen date-and-time package.
from date-and-time.
I doubt it is parsed 1/1/1
as 1/1/1901
. Cannot reproduce it.
Hm...
Anyway, to get this library to do what you want, you need to override the default behavior of it. For example like this:
var date = require('date-and-time');
// Override the default behavior of the YY token.
date.extend({
parser: {
YY: function (str) {
var result = this.exec(/^\d{1,2}/, str);
result.value += result.value < 70 ? 2000 : result.value < 100 ? 1900 : 0;
return result;
}
}
})
// Use the YY token instead of the Y.
date.parse('1/1/1', 'D/M/YY'); // => 1/1/2001
date.parse('1/1/0', 'D/M/YY'); // => 1/1/2000
date.parse('1/1/20', 'D/M/YY'); // => 1/1/2020
date.parse('1/1/75', 'D/M/YY'); // => 1/1/1975
from date-and-time.
So we have to downgrade to 0.6.3 version, which successfully parses 1/1/1, 1/1/0, etc.
Usually package breaking changes do not introduce degradation in functionality, what is not the case here.
from date-and-time.
Related Issues (20)
- formatTZ returns wrong locale HOT 3
- Swedish locale HOT 1
- Format(tz) fails when timezone string is greater than +1200 (i.e +1300) HOT 3
- Add transformTZ HOT 7
- Make it possible to use the library with react typescript HOT 2
- transformTZ doesn't work properly when original time zone is +0000 HOT 2
- Consider adding native support for Typescript types HOT 3
- ESM version exposed to environments that don't support ESM (e.g. jest 28) HOT 3
- Support clock change for .transform() HOT 2
- Can we substract year? HOT 1
- Invalid `Podfile` file: 767: unexpected token at 'Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './package.json' is not defined by "exports" in /…/node_modules/date-and-time/package.json HOT 1
- Sudden invalid date HOT 4
- Format formats incorrect month HOT 1
- addMonth to 2022-03-01 does not add full month HOT 3
- addDays when crossing over from summer to standard time the UTC is incorrect HOT 2
- Module has no default export after upgrade to angular v15 HOT 3
- not an issue but need to highlight one missing HOT 8
- addMonts function calculates wrong date for some cases HOT 2
- It does not support Node.js 8 HOT 1
- Miising format HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from date-and-time.