Skip to content

Conversation

@zWarMob
Copy link

@zWarMob zWarMob commented Mar 24, 2023

Description

The class hms can not be compared with strings
#108

Expected behavior

hms(0,0,0) == "00:00:00"
#> [1] TRUE

Actual behavior

hms(0,0,0) == "00:00:00"
#> [1] FALSE

@krlmlr
Copy link
Member

krlmlr commented Mar 19, 2025

Thanks. I wonder if we should make this comparison an error instead. What do you expect with hms::hms(1) > "a" ?

Comment on lines 281 to 291
Ops.hms <- function (e1, e2) {
boolean <- switch(.Generic, `<` = , `>` = , `==` = , `!=` = ,
`<=` = , `>=` = TRUE, FALSE)
if (boolean) {
if (inherits(e1, "hms") & inherits(e2, "character"))
e1 <- as.character(e1)
if (inherits(e2, "hms") & inherits(e1, "character"))
e2 <- as.character(e2)
}
NextMethod(.Generic)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since hms is based on the vctrs package, I believe the recommended way is to implement the vec_ptype2 and vec_cast methods.

@krlmlr krlmlr marked this pull request as draft September 19, 2025 17:13
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