Skip to content

Define CompoundPeriod conversion/constructor for Real #52519

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

charleskawczynski
Copy link
Contributor

@charleskawczynski charleskawczynski commented Dec 13, 2023

This PR defines conversions, or rather, CompoundPeriod constructors that accept Real numbers. For example (from the tests added):

    ccp(x, p) = Dates.canonicalize(Dates.CompoundPeriod(x, p))
    @test string(ccp(1.5, Dates.Minute)) == "1 minute, 30 seconds"
    @test string(ccp((Dates.Second(Dates.Week(1))+Dates.Second(1)).value, Dates.Second)) == "1 week, 1 second"
    @test string(ccp(1.5, Dates.Day)) == "1 day, 12 hours"
    @test string(ccp(1.5+7, Dates.Day)) == "1 week, 1 day, 12 hours"
    @test string(ccp(1.4, Dates.Second)) == "1 second, 400 milliseconds"
    @test string(ccp(10.1, Dates.Week)) == "10 weeks, 16 hours, 48 minutes"
    @test string(ccp(10.1, Dates.Week) - Dates.Minute(6)) == "10 weeks, 16 hours, 42 minutes"

@charleskawczynski charleskawczynski marked this pull request as draft December 13, 2023 17:38
@charleskawczynski charleskawczynski force-pushed the ck/dates_compound_period branch 3 times, most recently from 90a9067 to 957f341 Compare December 13, 2023 20:19
@charleskawczynski charleskawczynski marked this pull request as ready for review December 13, 2023 20:19
@inkydragon inkydragon added dates Dates, times, and the Dates stdlib module stdlib Julia's standard library labels Feb 6, 2024
@vtjnash vtjnash requested a review from vchuravy February 6, 2024 21:19
@charleskawczynski
Copy link
Contributor Author

One downside of this feature is that it gets hit pretty hard by #52873, but I think we can fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dates Dates, times, and the Dates stdlib module stdlib Julia's standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants