GithubHelp home page GithubHelp logo

nomiddlename / date-format Goto Github PK

View Code? Open in Web Editor NEW
59.0 59.0 17.0 435 KB

node.js formatting of Date objects as strings. Probably exactly the same as some other library out there.

License: MIT License

JavaScript 100.00%

date-format's People

Contributors

dependabot[bot] avatar joshuabremerdexcom avatar lamweili avatar nomiddlename avatar raynos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

date-format's Issues

Critical issue with dataformat

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 !!!!

ISO8601 format is not correct

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'

format.parse fails when current date is 31st of some month

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.

lib/index.js in ES5

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'? ๐Ÿ˜„

when tz offset is in the pattern, the date should be in UTC

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');

Colon in timezone

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?

format parse adds a month in the default format

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

The 'L' millisecond flag can return 3 digits

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 #

Access to the meridiem

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.