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 support for ISO calendar week to Time #6681

Merged
merged 4 commits into from Oct 12, 2018

Conversation

Projects
None yet
4 participants
@straight-shoota
Contributor

straight-shoota commented Sep 8, 2018

This PR adds two methods to Time for handling ISO calendar week:

  • Time#calendar_week returns the year and week number. The year is important because calendar weeks don't match up with calendar years and the calendar week might actually be in a different year than the regular calendar year (returned by #year).
  • Time.week_date creates a Time instance from a week date specified by year, week number and day of week.

It also adds directives %G, %g, %V which utilize these methods to Time::Format.

The algorithms for calculating the week number and back are completely annotated in code. They're based on the description on Wikipedia and the implementation in Go's stdlib but with a few improvements.

Closes #2533
Depends on #6555

@jhass

jhass approved these changes Sep 10, 2018

I didn't review the algorithm much, but this seems more than solid enough to be accepted for a first implementation. We can always sort out edge cases as they're discovered, if any.

@RX14

RX14 approved these changes Sep 10, 2018

@RX14 RX14 added this to the 0.27.0 milestone Sep 10, 2018

@RX14

This comment has been minimized.

Member

RX14 commented Sep 10, 2018

needs a rebase after #6555.

@straight-shoota straight-shoota force-pushed the straight-shoota:jm/feature/time-week branch from 4b951bd to cd4303c Oct 2, 2018

@straight-shoota

This comment has been minimized.

Contributor

straight-shoota commented Oct 2, 2018

Rebased.

@straight-shoota straight-shoota force-pushed the straight-shoota:jm/feature/time-week branch 2 times, most recently from 426d229 to beee7a6 Oct 2, 2018

@straight-shoota straight-shoota force-pushed the straight-shoota:jm/feature/time-week branch 2 times, most recently from 3fb2581 to f3f95ee Oct 11, 2018

@bcardiff

This comment has been minimized.

Member

bcardiff commented Oct 12, 2018

@straight-shoota Sorry, could you rebase again this on master so we can merge in a more tidy fashion?

straight-shoota added some commits Aug 16, 2018

@straight-shoota straight-shoota force-pushed the straight-shoota:jm/feature/time-week branch from f3f95ee to 887d346 Oct 12, 2018

@straight-shoota

This comment has been minimized.

Contributor

straight-shoota commented Oct 12, 2018

Sure, done. But I'm not sure what it adds, it could just be fast forwarded.

@bcardiff bcardiff merged commit c263549 into crystal-lang:master Oct 12, 2018

4 checks passed

ci/circleci: test_darwin Your tests passed on CircleCI!
Details
ci/circleci: test_linux Your tests passed on CircleCI!
Details
ci/circleci: test_linux32 Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@bcardiff

This comment has been minimized.

Member

bcardiff commented Oct 12, 2018

Thanks! A rebase will not leave a text reference to the PR. Squash or merge commit will. But is better to avoid long standing branch merged and keep the repo as thin as possible.

@straight-shoota straight-shoota deleted the straight-shoota:jm/feature/time-week branch Oct 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment