R Package ISO Week Returning incorrect values compared to ISO 8601 in Spotfire

404 Views Asked by At

Following this article, I am using the ISOWeek "R" package in Tibco Spotfire to return the ISOWeek for a specific date.

https://community.tibco.com/wiki/tibco-spotfirer-tips-tricks-reusable-simple-easy-iso-week-calculation-spotfire

According to all websites, 01-Dec-2019 is Week 48. This day is a Sunday, and ISO 8601 assumes a week starts on a Monday.

https://www.epochconverter.com/weeks/2019

However, the TERR function in Spotfire, when passed the date 01-Dec-2019 returns week 49...almost as if it is making Sunday the start day of the week, in complete contradiction to ISO 8601.

This is the Spotfire output.

e

2

There are 2 best solutions below

8
On

This indeed looks like a bug. A more reliable solution might be to use strftime:

strftime("2019-12-1", "%U")
> "48"
0
On

Maybe you can try format() with %V, i.e.,

d <- as.Date(c("2019-12-01","2019-12-17"))
w <- format(d,"%V")

such that

> w
[1] "48" "51"