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

Handle more time formats and allow custom formats #146

Merged
merged 1 commit into from
Jul 11, 2019

Conversation

paulcsmith
Copy link
Member

@paulcsmith paulcsmith commented Jul 11, 2019

Closes #40

@paulcsmith paulcsmith force-pushed the pcs/40-more-time-formats branch 2 times, most recently from 06923f8 to d23e446 Compare July 11, 2019 03:07
@paulcsmith paulcsmith changed the title [WIP] More time formats Handle more time formats and allow custom formats Jul 11, 2019
Avram.settings.time_formats.find do |format|
begin
Time.parse(value, format, Time::Location.load("UTC"))
rescue e : Time::Format::Error
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 wish Crystal had some way to return nil but it only raises when parsing so we have to do this kind of hacky begin/rescue dance :(

Copy link
Member

Choose a reason for hiding this comment

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

Working with Time in crystal is actually really clunky.

@paulcsmith paulcsmith force-pushed the pcs/40-more-time-formats branch 2 times, most recently from 8d4a795 to 8ca50d2 Compare July 11, 2019 03:26
@paulcsmith paulcsmith force-pushed the pcs/40-more-time-formats branch from 8ca50d2 to 775abbb Compare July 11, 2019 03:29
Copy link
Member

@edwardloveall edwardloveall left a comment

Choose a reason for hiding this comment

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

I really like the way you coded this up! It's a nice pattern and I'm going to steal it for future projects 😄

@jwoertink
Copy link
Member

Looks good to me!

@paulcsmith
Copy link
Member Author

Thanks for the reviews. And thanks for the kind words Edward!

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.

Handle more input types for the Time type
3 participants