tidyverse / hms

A simple class for storing time-of-day values
https://hms.tidyverse.org/
Other
138 stars 25 forks source link

Fix formatting for times with a very small distance to the full second #67

Closed krlmlr closed 5 years ago

krlmlr commented 5 years ago

Fully back-compatible. Times slightly below the full second are rounded up and shown with trailing zeros.

library(hms)
hms(0.99999)
#> 00:00:00.99999
hms(0.999999)
#> 00:00:00.999999
hms(0.9999999)
#> 00:00:01.000000
hms(0.99999999)
#> 00:00:01.000000
hms(1.00000001)
#> 00:00:01.000000

Created on 2019-03-24 by the reprex package (v0.2.1.9000)

Closes #64.

codecov[bot] commented 5 years ago

Codecov Report

Merging #67 into master will increase coverage by 0.01%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #67      +/-   ##
==========================================
+ Coverage    99.2%   99.22%   +0.01%     
==========================================
  Files           7        7              
  Lines         126      129       +3     
==========================================
+ Hits          125      128       +3     
  Misses          1        1
Impacted Files Coverage Δ
R/format.R 100% <100%> (ø) :arrow_up:
R/arith.R 100% <100%> (ø) :arrow_up:
R/hms.R 97.36% <100%> (ø) :arrow_up:
R/pillar.R 100% <100%> (ø) :arrow_up:

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 62fdb74...8e9abd2. Read the comment docs.

codecov[bot] commented 5 years ago

Codecov Report

Merging #67 into master will increase coverage by 0.03%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #67      +/-   ##
==========================================
+ Coverage    99.2%   99.24%   +0.03%     
==========================================
  Files           7        7              
  Lines         126      132       +6     
==========================================
+ Hits          125      131       +6     
  Misses          1        1
Impacted Files Coverage Δ
R/arith.R 100% <100%> (ø) :arrow_up:
R/format.R 100% <100%> (ø) :arrow_up:

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 e53d560...e393415. Read the comment docs.

hadley commented 5 years ago

I am surprised this required such large changes — I would've thought you'd be able to fix it simply by applying round(x, getOptions("digits")) in the right place in the format method.

krlmlr commented 5 years ago

This patch does three things:

It used to do a fourth thing too -- renaming split_second to tic . I extracted this change and applied to master to minimize the diff, but further minimization will require extra work.