Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing several format options #60

Closed
schiem opened this issue Apr 26, 2018 · 5 comments
Closed

Missing several format options #60

schiem opened this issue Apr 26, 2018 · 5 comments
Labels
discussion Further discussion

Comments

@schiem
Copy link
Contributor

schiem commented Apr 26, 2018

The Moment docs have a number of format options which are missing from DayJS. Some of them, like the locality specific ones, I think it makes sense to exclude, but there are others that are missing that could be included without having a serious impact on the library size.

Here are the missing formats that I propose are added:

  • Q - Quarter of the year
  • Do - Day of month with ordinal
  • DDD/DDDD - Day of year
  • X - Unix timestamp
  • x - Unix timestamp with ms
  • h/hh - 12 hour time
  • k/kk - 24 hour time beginning at 1
  • a/A - Post and ante meridiem
  • S/SS/SSS - Milliseconds

However, this would nearly double the size of the format function, which isn't ideal. Are there any of those that shouldn't be added?

@iamkun iamkun added the discussion Further discussion label Apr 26, 2018
@Frondor
Copy link
Contributor

Frondor commented Apr 27, 2018

In my humble opinion, the only useful ones in that list are h/hh and k/kk (and still not sure about them, can't think on an use case). The rest doesn't look like human-friendly formats.

@schiem
Copy link
Contributor Author

schiem commented Apr 27, 2018

I would tend to agree, I think that Q, DDD/DDDD, X/x, and S/SS/SSS are definitely not necessary. I think if h/hh is included, then a/A should probably be included as well, or you lose the ability to show specific times (1:00 vs 1:00 AM).

"Do" is kind of up in the air for me, because I've had clients who've insisted on having the ordinal (1st, 2nd, 3rd, etc) shown, but it's something that a user could implement on their own. I think most of it comes down to "what should be provided by a library" vs. "what can a user be reasonably expected to write themselves," and I think that's mostly up to the owner of the repo.

@iamkun
Copy link
Owner

iamkun commented Apr 29, 2018

I tend to agree adding h/hh & a/A(with local). And leave the rest formats to a separate plugin, maybe called AdvFormat
It will be nice if we implement a plugin system like this.

import { AdvFormat } from 'dayjs/plugin'
dayjs.extend('AdvFormat') // a plugin might add a new API or overwrite the existing one
//here it just overwrite the core.format
dayjs.format('Do SSS ... something less useful format')

@iamkun iamkun mentioned this issue Apr 30, 2018
@schiem
Copy link
Contributor Author

schiem commented May 1, 2018

I've updated #68 to only have AM/PM and 12 hour time support, with additional options included in another plugin (and the addition of a plugin system).

@schiem
Copy link
Contributor Author

schiem commented May 2, 2018

The PR from #68 has been split into #91 and #92.

@schiem schiem closed this as completed May 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Further discussion
Projects
None yet
Development

No branches or pull requests

3 participants