tidyverse / hms

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

Can hms objects be comapred with strings? #108

Open yutannihilation opened 2 years ago

yutannihilation commented 2 years ago

I feel the result of the comparison with strings is a bit cryptic...

x <- readr::parse_time(c("19:00:00", "20:00:00", "21:00:00", "30:00:00"))

# why...
x > "20:00:00"
#> [1]  TRUE  TRUE  TRUE FALSE

# expected
x > hms::parse_hms("20:00:00")
#> [1] FALSE FALSE  TRUE  TRUE

Created on 2022-07-02 by the reprex package (v2.0.1)

zWarMob commented 1 year ago

I encountered this today 😅

I expect this comparison to be TRUE

library(hms)

a <- hms(0,0,0); a
#> 00:00:00
b <- "00:00:00"; b
#> [1] "00:00:00"

a == b
#> [1] FALSE

Created on 2023-03-24 with reprex v2.0.2

Specially because R like JS seems to coerce a lot and 3 == '3' is TRUE