Working on some exercises to learn programming and Julia, and I am attempting to calculate my little one’s age.
I see that Julia does almost all of the work compared to the solution I wrote yesterday in Perl where I had to do most of it manually, wanting to use only built-in functions (adding no modules).
What I would like to add to my Julia solution is an age output in “x months, y days” or some variation of “x months” and other smaller units.
Canonicalize already gives me “x weeks, y days” but I don’t see a way to tell Dates.canonicalize which units I want. It seems to decide for itself based on the documentation.
Note that my time duration is coming from Julia performing algebra on two dates.
Is there any way to request specific units from Dates.canonicalize?
Thanks!
julia> birthday = Dates.Date(2022,9,7)
2022-09-07
julia> today_date = Dates.today()
julia> age = today_date - birthday
74 days
julia> Dates.canonicalize(age)
10 weeks, 4 days
help?> Dates.canonicalize
canonicalize(::CompoundPeriod) -> CompoundPeriod
Reduces the CompoundPeriod into its canonical form by applying the following rules:
• Any Period large enough be partially representable by a coarser Period will be broken into multiple Periods (eg. Hour(30)
becomes Day(1) + Hour(6))