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

WIP beginning_of_seconds and end_of_seconds #477

Closed

Conversation

nathanl
Copy link
Contributor

@nathanl nathanl commented Oct 12, 2018

These are two functions I found useful in my work, where I needed to "round" some datetimes to the nearest hour. They seems to fit in with functions like end_of_month, etc.

This is WIP, as it needs to be split up into protocol implementations. But I wanted to see if you like the idea before doing that.

Summary of changes

I'll review the commits, so I mostly want to understand the "why" rather than the "what"

Checklist

  • New functions have typespecs, changed functions were updated
  • Same for documentation, including moduledocs
  • Tests were added or updated to cover changes
  • Commits were squashed into a single coherent commit

(Needs to be split up into protocol implementations - eg in
lib/datetime/datetime, etc, as end_of_month, etc are)

# return the same type we were given
case input_datetime do
%DateTime{} -> output_datetime
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would be split into the various protocol implementations

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 69.816% when pulling 54400d5 on nathanl:nathanl/beginning-and-end-of-seconds into 4711f9b on bitwalker:master.

@bitwalker
Copy link
Owner

My feeling is that we'd be better off adding Timex.round/2 which rounds to the nearest granularity (as seen in other APIs, like compare/3). A Timex.round/3 variant could take an argument which indicates the rounding direction. Alternatively, we could do Timex.ceil/2 and Timex.floor/2 which act like their mathematical counterparts, but take a granularity like the proposed round/2 function. Thoughts?

@nathanl nathanl closed this Oct 15, 2021
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.

None yet

3 participants