Skip to content

Instantly share code, notes, and snippets.

@symbolrush
Last active January 25, 2019 09:15
Show Gist options
  • Save symbolrush/91334044d299f2525cfa6f7ab5dc70bd to your computer and use it in GitHub Desktop.
Save symbolrush/91334044d299f2525cfa6f7ab5dc70bd to your computer and use it in GitHub Desktop.
Happy to solve your unsolvable problem, Mr. Smith. :-)
imsbasics::clc()
jahr16 <- seq(as.Date("2016/1/1"), as.Date("2016/12/31"), "days")
jahr17 <- seq(as.Date("2017/1/1"), as.Date("2017/12/31"), "days")
jahr18 <- seq(as.Date("2018/1/1"), as.Date("2018/12/31"), "days")
jahr19 <- seq(as.Date("2019/1/1"), as.Date("2019/12/31"), "days")
library(testthat)
library(lubridate)
expect_equal(wday(jahr16[5]), wday(jahr19[1]))
expect_equal(wday(jahr17[3]), wday(jahr19[1]))
expect_equal(wday(jahr18[2]), wday(jahr19[1]))
jahr16to19 <- jahr16 + (3*52*7)
jahr17to19 <- jahr17 + (2*52*7)
jahr18to19 <- jahr18 + (1*52*7)
jahr16to19 <- c(jahr16to19, jahr16to19[(length(jahr16to19)-6):length(jahr16to19)] + 7)[5:(5+364)]
jahr17to19 <- c(jahr17to19, jahr17to19[(length(jahr17to19)-6):length(jahr17to19)] + 7)[3:(3+364)]
jahr18to19 <- c(jahr18to19, jahr18to19[(length(jahr18to19)-6):length(jahr18to19)] + 7)[2:(2+364)]
expect_equal(as.numeric(diff(jahr16to19)), rep(1, 364))
expect_equal(as.numeric(diff(jahr17to19)), rep(1, 364))
expect_equal(as.numeric(diff(jahr18to19)), rep(1, 364))
expect_true(all(jahr19 == jahr16to19))
expect_true(all(jahr19 == jahr17to19))
expect_true(all(jahr19 == jahr18to19))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment