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

Add builder with MonthMatch #44

Open
vrom911 opened this issue Dec 30, 2019 · 3 comments
Open

Add builder with MonthMatch #44

vrom911 opened this issue Dec 30, 2019 · 3 comments

Comments

@vrom911
Copy link
Contributor

vrom911 commented Dec 30, 2019

It would be helpful to have a builder with which you could use MonthMatch.
For example, in co-log we needed to have months in 3-letter format (like Dec, Jan, etc.), so we implemented a builder manually:
co-log/co-log#166

If you think that it makes sense to have in the chronos library, I could help with the implementation as soon as we agree on the API (to have an additional field in the DatetimeFormat or to explicitly take a Maybe (MonthMatch a) as an argument, or something else?).

Let me know what do you think.

Oh, by the way, while implementing the builder, I have noticed that functions like zeroPadDayOfMonth etc. are not exported. Would you consider exporting them, or there is a reason not to do that? (if this question if offtopic for this issue I totally understand and could create a new one if you think that this idea makes sense at all).

@andrewthad
Copy link
Member

I think this is the function I would want:

builder_DmyHMSz_m ::
     OffsetFormat -> SubsecondPrecision -> DatetimeFormat
  -> OffsetDatetime -> MonthMatch -> Builder

This is similar to the builderDmyHMSz function you have in co-log except that the formatting things are configurable.

Concerning exporting zeroPadDayOfMonth, I don't think chronos is the right place for this. I would rather push this into a different library and have a function like:

zeroPaddedTwoDigit :: Int -> Ptr CChar

as a part of its public API, and then chronos would depend on that library.

@vrom911
Copy link
Contributor Author

vrom911 commented Dec 30, 2019

Great!

The only concern I had for the builder_DmyHMSz from chronos (apart from the MonthMatch) is that it doesn't have a separator option to separate offset with a space as we do now. Do you think that we can include this option somewhere as well?

@andrewthad
Copy link
Member

For anyone browsing this issue, an example of the desired format (taken from co-log) is 03 May 2019 05:23:19.058 +00:00. I had forgotten about the space. What I've been doing for spaces is using underscores in the function names. So rather than builder_DmyHMSz_m, how about chronos having builder_DbyHMS_z? The rational being:

  • Underscore before z means there's a space before the offset.
  • The letter b is taken from the man page for date(1), which uses %b to mean "locale's abbreviated month name (e.g., Jan)" and %B to mean locale's full month name (e.g., January). Here, we would just use b to mean both of these since MonthMatch can store both abbreviated and unabbreviated localizations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants