Skip to content

Add prefix methods for Week and Quarter Types. #164

Open
Ianlmgoddard wants to merge 5 commits intomasterfrom
ig/prefixes
Open

Add prefix methods for Week and Quarter Types. #164
Ianlmgoddard wants to merge 5 commits intomasterfrom
ig/prefixes

Conversation

@Ianlmgoddard
Copy link
Copy Markdown

partially tackles #163

I haven't included prefixes for Microsecond or Nanosecond because as far as I can tell, DateTimes are only defined up to millisecond precision (see JuliaLang/julia#31525). I wasn't sure if we wanted to display DateTime Intervals with greater precision than what is available for DateTimes.

I also haven't added tests for Quarter because it's not clear to me how to get around the fact that this type was only introduced in Julia v1.6. Any advice there would be appreciated.

@Ianlmgoddard Ianlmgoddard requested a review from omus as a code owner April 20, 2021 14:45
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2021

Codecov Report

Merging #164 (abdb3f8) into master (f873f70) will increase coverage by 0.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #164      +/-   ##
==========================================
+ Coverage   81.09%   81.25%   +0.15%     
==========================================
  Files          11       11              
  Lines         603      608       +5     
==========================================
+ Hits          489      494       +5     
  Misses        114      114              
Impacted Files Coverage Δ
src/description.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f873f70...abdb3f8. Read the comment docs.

@Ianlmgoddard Ianlmgoddard marked this pull request as draft April 20, 2021 14:54
@omus
Copy link
Copy Markdown
Collaborator

omus commented Apr 21, 2021

I also haven't added tests for Quarter because it's not clear to me how to get around the fact that this type was only introduced in Julia v1.6. Any advice there would be appreciated.

Use conditional blocks like:

if VERSION >= v"1.6"
    ...
end

Which allows you to only run code if the Julia version is above or equal to 1.6.0.

It shouldn't matter here but if you use @static before the if Julia can do the check at compile time allowing you to write unsupported syntax.

@Ianlmgoddard Ianlmgoddard changed the title Draft: Add prefix methods for Week and Quarter Types. Add prefix methods for Week and Quarter Types. Apr 21, 2021
@Ianlmgoddard Ianlmgoddard marked this pull request as ready for review April 21, 2021 12:55
Copy link
Copy Markdown

@LilithHafner LilithHafner left a comment

Choose a reason for hiding this comment

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

Thanks for fixing these missing prefixes!

Comment thread src/description.jl
prefix(::Type{Second}) = "S"
prefix(::Type{Millisecond}) = "ms"

# `Quarter` defined after Julia1.6.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
# `Quarter` defined after Julia1.6.
# `Quarter` defined in Julia v1.6.

Comment thread src/description.jl
Comment on lines +75 to +77

# informative error if no prefix is defined for the given type.
prefix(T::Type{<:Period}) = error("A prefix for period $T has not yet been defined")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If we'd like it to "just work" instead of throwing,

Suggested change
# informative error if no prefix is defined for the given type.
prefix(T::Type{<:Period}) = error("A prefix for period $T has not yet been defined")
# Full name if no prefix is defined.
prefix(T::Type{<:Period}) = string(T)

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.

3 participants