Skip to content

Date/time overhaul #34

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

Merged
merged 4 commits into from
Jun 9, 2016
Merged

Date/time overhaul #34

merged 4 commits into from
Jun 9, 2016

Conversation

garyb
Copy link
Member

@garyb garyb commented Jun 6, 2016

Ok, I think this is ready now.

It's a fully PureScript based representation, but we privately hand off some logic to the JS date stuff, for now at least.

I didn't include Locale or Hour12 in here in the end, to keep this library down to just the types needed to represent and manipulate date/times. We will probably want to add some more operations over time too, but I think this is a reasonable starting place.

The other parts of datetime are now in two other libraries - purescript-now for fetching the current date, and purescript-js-date for the JSDate type and general interop. We'll probably also want to introduce a library for convenient parsing and printing of date formats fairly soon too.

@paf31
Copy link
Contributor

paf31 commented Jun 6, 2016

I like the split, but I wonder why the dependencies aren't reversed, with the smaller, lower-level JSDate library at the bottom? Does that make sense? It seems like it would just be a job of moving the functions which use both types into this library.

@garyb
Copy link
Member Author

garyb commented Jun 6, 2016

Eventually I would prefer this library not to use any FFI, so I think the dependencies are better this way around - ideally the datetime library should be backend agnostic, and pulling js-date along with it runs counter to that. It would also mean moving the conversion functions into datetime rather than having them in js-date, which again, rather specialises it to JS use cases.

@paf31
Copy link
Contributor

paf31 commented Jun 7, 2016

That makes sense. In that case, I'll review this a bit more later tonight.

@garyb
Copy link
Member Author

garyb commented Jun 7, 2016

I re-included the locale stuff - it seems reasonable to provide a method of representing localised date/time values, and I've updated purescript-now with cases where it makes sense to do so: https://github.com/purescript-contrib/purescript-now/blob/bf071638903fa17f036065d190129a41a3411982/src/Control/Monad/Eff/Now.purs#L27-L38. Without Locale these might have been confusing, as the returned values would always be in UTC.

foreign import jsDateMethod :: forall a. Fn2 String JSDate a

foreign import strictJsDate :: Fn3 (forall a. a -> Maybe a) (forall a. Maybe a) String (Maybe JSDate)
show (Date y m d) = "(Date " <> show y <> " " <> show m <> " " <> show d <> ")"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use gShow here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could certainly do that, for pretty much all the Show instances actually. Is that preferable in this case then?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think core libraries should use the generic implementations because they are much slower; and the libraries don't change very often (at least in theory 😆) so the overhead of manually writing and maintaining the instances is much lower.

@paf31
Copy link
Contributor

paf31 commented Jun 9, 2016

Looks great! Sorry for the delayed review.

@garyb
Copy link
Member Author

garyb commented Jun 9, 2016

No problem! It's a pretty big changeset. I'll merge and release this after we decide on whether gShow is better to use.

@garyb
Copy link
Member Author

garyb commented Jun 9, 2016

I'll add a comment in the code about the seemingly arbitrary year bounds too actually.

@garyb
Copy link
Member Author

garyb commented Jun 9, 2016

@paf31 is this good to go then?

@paf31
Copy link
Contributor

paf31 commented Jun 9, 2016

I think so! 🚢 it.

@garyb garyb merged commit 96c2bc8 into purescript:master Jun 9, 2016
@garyb garyb deleted the overhaul branch June 9, 2016 18:15
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

Successfully merging this pull request may close these issues.

3 participants