knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

We create the following functions to make it easier to work with date and times in different formats.

For the input, we allow either a numeric (3) or string ("03", "2020-03").

For the output, the user need to specify whether numeric or string is required. Functions end with c returns a character output and n returns a double.

library(fhiplot)

Which year/week is it?

By default the functions returns the isoyear or isoweek of today.

isoyear_c()
isoyear_n()
isoweek_c()
isoweek_n()

# provide a date
isoyear_c('2021-01-01')
isoyear_n('2021-01-01')
isoweek_c('2021-01-01')
isoweek_n('2021-01-01')

Get year/week from a isoyearweek string

isoyearweek_to_year_c("2021-02")
isoyearweek_to_year_n("2021-02")
isoyearweek_to_week_c("2021-02")
isoyearweek_to_week_n("2021-02")

A list of isoyearweek can be accessed in the following way.

yrwk_19_20 <- fhidata::world_dates_isoyearweek[year %in% c(2019, 2020)]
head(yrwk_19_20)


folkehelseinstituttet/fhiplot documentation built on March 25, 2022, 7:59 a.m.