nomiddlename / date-format Goto Github PK
View Code? Open in Web Editor NEWnode.js formatting of Date objects as strings. Probably exactly the same as some other library out there.
License: MIT License
node.js formatting of Date objects as strings. Probably exactly the same as some other library out there.
License: MIT License
console.log(dateFormat("ddmmyyyy", dateFormat.parse('yyyy-mm-dd', '2019-10-31')))
this is giving output as 01102019.
This seems to be an issue with all dates ending with 31 .
this should be fixed urgently !!!!
String '2019-04-12' could not be parsed as 'yyyy-MM-dd-hh-mm'
The ISO 8601 format for combined date and time should have a 'T' separating the date and time, not a space. e.g. '2017-11-13 08:39:24' should be '2017-11-13T08:39:24'
Easy function of 20 lines of code, the result is the same
https://www.npmjs.com/package/date-template
format.parse has a dependency on the current date.
This is how it shows up (results taken on May 31st 2022):
> const format = require('date-format');
undefined
> format.parse('yyyy-MM-dd', '2022-01-01');
2022-01-01T11:01:38.438Z
> format.parse('yyyy-MM-dd', '2022-02-01');
2022-03-01T11:01:45.258Z << wrong month
> format.parse('yyyy-MM-dd', '2022-03-01');
2022-03-01T11:01:55.626Z
> format.parse('yyyy-MM-dd', '2022-04-01');
2022-05-01T10:02:10.378Z << wrong month
> format.parse('yyyy-MM-dd', '2022-05-01');
2022-05-01T10:02:16.650Z
> format.parse('yyyy-MM-dd', '2022-06-01');
2022-07-01T10:02:22.938Z << wrong month
> format.parse('yyyy-MM-dd', '2022-07-01');
2022-07-01T10:02:27.354Z
> format.parse('yyyy-MM-dd', '2022-08-01');
2022-08-01T10:02:32.939Z
> format.parse('yyyy-MM-dd', '2022-09-01');
2022-10-01T10:02:37.851Z << wrong month
> format.parse('yyyy-MM-dd', '2022-10-01');
2022-10-01T10:02:44.108Z
> format.parse('yyyy-MM-dd', '2022-11-01');
2022-12-01T11:02:48.326Z << wrong month
> format.parse('yyyy-MM-dd', '2022-12-01');
2022-12-01T11:02:55.861Z
So format.parse fails for dates in February, April, June, September and November, the months having less than 31 days.
This bug shows up only when the current date is 31st of some month.
(And presumably it shows up for February also on 30th and 29th.)
The platform in the test was Node.js v16.14.0 and date-format v4.0.10.
Hi! thanks for this useful library.
I'm using it in my project, but unfortunately, I cannot use it directly from the node_modules, instead I had to copy the source to my project tree (nothing too bad, your library is tiny after all!). The reason for that is that I'm using webpack which uses uglifyjs for 'production' builds, and uglifyjs doesn't recognises ES6, only ES5. I get the following error:
ERROR in bundle.js from UglifyJs
SyntaxError: Unexpected token: name (numAsString) [./~/date-format/lib/index.js:4,0]
I use ES6 like you, but the difference is that my code gets translated to ES5 with babel
before the uglify.
Some people on the Internet suggests that you can develop your libraries in ES6 and release it in ES5 using babel, then you will allow a wider audience for date-format.
Your library's source tree would look like this.
+-- lib
| +-- library.js (es5)
| +-- library.min.js (es5)
+-- src
+-- index.js (es6)
+-- helpers.js (es6)
What do you think about this? are you interested at all in adding this support for ES5 or just 'not your problem'? ๐
see test/date_format-test.js
dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, tzDate)
.should.eql('2010-01-11T14:31:30.005+1100');
.should.eql('2010-01-11T03:31:30.005+1100');
should .should.eql('2010-01-11T03:31:30.005+1100'); be
.should.eql('2010-01-11T03:31:30.005+0000');
According to https://en.wikipedia.org/wiki/ISO_8601 the timezone is recommended to contain a colon.
Representations can be done in one of two formats โ a basic format with a minimal number of separators or an extended format with separators added to enhance human readability.[14][15] The standard notes that "The basic format should be avoided in plain text."[16] The separator used between date values (year, month, week, and day) is the hyphen, while the colon is used as the separator between time values (hours, minutes, and seconds). For example, the 6th day of the 1st month of the year 2009 may be written as "2009-01-06" in the extended format or simply as "20090106" in the basic format without ambiguity.
RFC3339, that is a profile of ISO 8601, also states that the offset between local time and UTC is defined as:
time-numoffset = ("+" / "-") time-hour ":" time-minute
As such, should the the O format string should most likely include a colon, right?
Greetings,
My string date is
1995-09-09T23:16:56.161
And when i parse it to the
ISO8601_FORMAT
it returns it with a month added like this
Mon Oct 09 1995 23:16:56 GMT+0200 (Eastern European Standard Time)
This is my code. Thanks in advance.
console.log(state.date); //1995-09-09T23:16:56.161
const formatedDate = format.parse(format.ISO8601_FORMAT,state.date);
console.log(formatedDate); //Mon Oct 09 1995 23:16:56 GMT+0200 (Eastern European Standard Time)
const birthDate = format('dd/MM/yyyy',formatedDate);
console.log(birthDate); //09/10/1995
See this issue in log4js log4js-node/log4js-node#940 - time format should be local time + offset, but seems to be showing UTC + offset
While it generally works correctly, it looks like in certain edge cases, the 'L' flag can return 3 digits instead of 2.
format: "mm/dd/yyyy HH:MM:ss.L"
output: 03/16/2020 19:50:22.100 #
Consider adding MMM or MMMM that would output as Oct or October respectively.
There is no way to display the meridiem (am/pm) of a custom 12-hour format.
For example, I want to display any of the following:
3:06 pm
3:06 p.m.
3:06 PM
3:06 P.M.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.