datejs / Datejs

A JavaScript Date and Time Library
Other
1.89k stars 483 forks source link

[FIX] Namespace Conflicts #104

Closed DerekTBrown closed 7 years ago

DerekTBrown commented 7 years ago

It seems like there are some pretty substantial namespace conflicts within the date format module. For instance:

My usecase requires parsing portions of the format string individually (so "d" should refer to the day of the month, not the shortDate format). I would like to make a pull request to resolve this ambiguity. Any suggestions before I go ahead and code up a fix?

geoffreymcgill commented 7 years ago

This is by design.

The Standard Format Specifiers which include d and D are to be used as a single char format, not used in combination with Custom Format Specifiers.

If you pass just a single character "d", then it's considered a Standard Format Specifier. If you pass d in combination with other Custom Format Specifiers, then it functions differently.

https://github.com/datejs/Datejs/wiki/Format-Specifiers

DerekTBrown commented 7 years ago

@geoffreymcgill that is still a problem for my usecase. I am exposing the format specifiers to the user, and need "d" to correspond with date per custom format specifier, not a standard format specifier.

geoffreymcgill commented 7 years ago

Can you use .format instead of .toString? The format function will accept PHP/Unix style format specifiers.

https://github.com/datejs/Datejs/wiki/Format-Specifiers#format