ISOweek/0000755000175100001440000000000011631616126011601 5ustar hornikusersISOweek/DESCRIPTION0000744000175100001440000000145611631616126013316 0ustar hornikusersPackage: ISOweek Type: Package Title: Week of the year and weekday according to ISO 8601 Version: 0.6-2 Date: 2011-09-07 Author: Uwe Block , using an algorithm by Hatto von Hatzfeld Maintainer: Uwe Block Imports: stringr Suggests: testthat Description: This is an substitute for the %V and %u formats which are not implemented on Windows. In addition, the package offers functions to convert from standard calender format yyyy-mm-dd to and from ISO 8601 week format yyyy-Www-d. License: GPL (>= 2) LazyLoad: yes Collate: 'ISOweek.R' 'ISOweekday.R' 'date2ISOweek.R' 'ISOweek2date.R' 'ISOweek-internal.R' Packaged: 2011-09-07 06:45:51 UTC; Uwe Repository: CRAN Date/Publication: 2011-09-07 07:25:10 ISOweek/inst/0000755000175100001440000000000011631611436012555 5ustar hornikusersISOweek/inst/tests/0000755000175100001440000000000011631611436013717 5ustar hornikusersISOweek/inst/tests/test-date2ISOweek.r0000744000175100001440000000377011631611436017315 0ustar hornikuserscontext("date2ISOweek") test_that("date2ISOweek returns proper format", { expect_that(date2ISOweek("1999-12-31"), is_a("character")) expect_that(date2ISOweek("1999-12-31"), matches("[0-9]{4}-W[0-9]{2}-[0-9]{1}")) }) test_that("date2ISOweek returns proper values", { input_chr <- paste(1999:2011, "-12-31", sep="") input_date <- as.Date(input_chr) result_chr <- c("1999-W52-5", "2000-W52-7", "2002-W01-1", "2003-W01-2", "2004-W01-3", "2004-W53-5", "2005-W52-6", "2006-W52-7", "2008-W01-1", "2009-W01-3", "2009-W53-4", "2010-W52-5", "2011-W52-6") expect_that(date2ISOweek(input_date), equals(result_chr)) expect_that(date2ISOweek(input_chr), equals(result_chr)) }) test_that("date2ISOweek handles NAs", { expect_that(date2ISOweek(NA), equals(NA_character_)) expect_that(date2ISOweek(NA_character_), equals(NA_character_)) input_chr <- paste(1999:2011, "-12-31", sep="") result_chr <- c("1999-W52-5", "2000-W52-7", "2002-W01-1", "2003-W01-2", "2004-W01-3", "2004-W53-5", "2005-W52-6", "2006-W52-7", "2008-W01-1", "2009-W01-3", "2009-W53-4", "2010-W52-5", "2011-W52-6") idx_NA <- seq(from =2, to = length(input_chr), by = 2) input_chr_NA <- input_chr input_chr_NA[idx_NA] <- NA_character_ input_date_NA <- as.Date(input_chr_NA) result_chr_NA <- result_chr result_chr_NA[idx_NA] <- NA expect_that(date2ISOweek(input_date_NA), equals(result_chr_NA)) expect_that(date2ISOweek(input_chr_NA), equals(result_chr_NA)) }) test_that("date2ISOweek handles zero length vectors", { input_date <- as.Date("1999-12-31") expect_that(length(date2ISOweek(input_date[0])), equals(0)) }) test_that("date2ISOweek stops on invalid parameters", { expect_that(date2ISOweek(31), throws_error()) expect_that(date2ISOweek(31.1), throws_error()) expect_that(date2ISOweek(FALSE), throws_error()) expect_that(date2ISOweek("31"), throws_error()) expect_that(date2ISOweek("12/31/1999"), throws_error()) }) ISOweek/inst/tests/test-ISOweek-internal.r0000744000175100001440000000144111631611436020200 0ustar hornikuserscontext("Internal functions") test_that("weekday0 returns proper values", { input_chr <- paste(1999:2011, "-12-31", sep="") input_date <- as.Date(input_chr) result_int <- as.integer(c(5, 7, 1, 2, 3, 5, 6, 7, 1, 3, 4, 5, 6)) - 1L expect_that(weekday0(input_date), equals(result_int)) expect_that(weekday0(input_chr), equals(result_int)) }) test_that("thursday0 returns proper values", { expect_that(thursday0(Sys.Date()), is_a("Date")) expect_that(weekday0(thursday0("1999-12-31")), equals(3L)) expect_that(abs(difftime(thursday0(Sys.Date()), Sys.Date(), units = "days")) <= 3, is_true()) }) test_that("year0 returns proper values", { expect_that(year0(Sys.Date()), is_a("integer")) expect_that(year0(c("1999-12-31", "2000-01-01")), equals(c(1999, 2000))) }) ISOweek/inst/tests/test-ISOweek.r0000744000175100001440000000352711631611436016375 0ustar hornikuserscontext("ISOweek") test_that("ISOweek returns proper format", { expect_that(ISOweek("1999-12-31"), is_a("character")) expect_that(ISOweek("1999-12-31"), matches("[0-9]{4}-W[0-9]{2}")) }) test_that("ISOweek returns proper values", { input_chr <- paste(1999:2011, "-12-31", sep="") input_date <- as.Date(input_chr) result_chr <- c("1999-W52", "2000-W52", "2002-W01", "2003-W01", "2004-W01", "2004-W53", "2005-W52", "2006-W52", "2008-W01", "2009-W01", "2009-W53", "2010-W52", "2011-W52") expect_that(ISOweek(input_date), equals(result_chr)) expect_that(ISOweek(input_chr), equals(result_chr)) }) test_that("ISOweek handles NAs", { expect_that(ISOweek(NA), equals(NA_character_)) expect_that(ISOweek(NA_character_), equals(NA_character_)) input_chr <- paste(1999:2011, "-12-31", sep="") result_chr <- c("1999-W52", "2000-W52", "2002-W01", "2003-W01", "2004-W01", "2004-W53", "2005-W52", "2006-W52", "2008-W01", "2009-W01", "2009-W53", "2010-W52", "2011-W52") idx_NA <- seq(from =2, to = length(input_chr), by = 2) input_chr_NA <- input_chr input_chr_NA[idx_NA] <- NA_character_ input_date_NA <- as.Date(input_chr_NA) result_chr_NA <- result_chr result_chr_NA[idx_NA] <- NA expect_that(ISOweek(input_date_NA), equals(result_chr_NA)) expect_that(ISOweek(input_chr_NA), equals(result_chr_NA)) }) test_that("ISOweek handles zero length vectors", { input_date <- as.Date("1999-12-31") expect_that(length(ISOweek(input_date[0])), equals(0)) }) test_that("ISOweek stops on invalid parameters", { expect_that(ISOweek(31), throws_error()) expect_that(ISOweek(31.1), throws_error()) expect_that(ISOweek(FALSE), throws_error()) expect_that(ISOweek("31"), throws_error()) expect_that(ISOweek("12/31/1999"), throws_error()) }) ISOweek/inst/tests/test-ISOweek2date.r0000744000175100001440000000405411631611436017311 0ustar hornikuserscontext("ISOweek2date") test_that("ISOweek2date returns proper format", { expect_that(ISOweek2date("1999-W01-1"), is_a("Date")) }) test_that("ISOweek2date returns proper values", { input_chr <- c("1999-W52-5", "2000-W52-7", "2002-W01-1", "2003-W01-2", "2004-W01-3", "2004-W53-5", "2005-W52-6", "2006-W52-7", "2008-W01-1", "2009-W01-3", "2009-W53-4", "2010-W52-5", "2011-W52-6") result_chr <- paste(1999:2011, "-12-31", sep="") result_date <- as.Date(result_chr) expect_that(ISOweek2date(input_chr), equals(result_date)) }) test_that("ISOweek2date handles NAs", { expect_that(ISOweek2date(NA), equals(as.Date(NA))) expect_that(ISOweek2date(NA_character_), equals(as.Date(NA))) input_chr <- c("1999-W52-5", "2000-W52-7", "2002-W01-1", "2003-W01-2", "2004-W01-3", "2004-W53-5", "2005-W52-6", "2006-W52-7", "2008-W01-1", "2009-W01-3", "2009-W53-4", "2010-W52-5", "2011-W52-6") result_chr <- paste(1999:2011, "-12-31", sep="") result_date <- as.Date(result_chr) idx_NA <- seq(from =2, to = length(input_chr), by = 2) input_chr_NA <- input_chr input_chr_NA[idx_NA] <- NA_character_ result_chr_NA <- result_chr result_chr_NA[idx_NA] <- NA result_date_NA <- as.Date(result_chr_NA) expect_that(ISOweek2date(input_chr_NA), equals(result_date_NA)) }) test_that("ISOweek2date handles zero length vectors", { input_chr <- c("1999-W52-5") expect_that(length(ISOweek2date(input_chr[0])), equals(0)) }) test_that("ISOweek2date stops on invalid parameters", { expect_that(ISOweek2date(31), throws_error()) expect_that(ISOweek2date(31.1), throws_error()) expect_that(ISOweek2date(FALSE), throws_error()) expect_that(ISOweek2date("31"), throws_error()) expect_that(ISOweek2date("12/31/1999"), throws_error()) expect_that(ISOweek2date("1999-W00-1"), throws_error()) expect_that(ISOweek2date("1999-W54-1"), throws_error()) expect_that(ISOweek2date("1999-W01-0"), throws_error()) expect_that(ISOweek2date("1999-W01-8"), throws_error()) }) ISOweek/inst/tests/test-ISOweekday.r0000744000175100001440000000304611631611436017067 0ustar hornikuserscontext("ISOweekday") test_that("ISOweekday returns integer values", { expect_that(ISOweekday("1999-12-31"), is_a("integer")) }) test_that("ISOweekday returns proper values", { input_chr <- paste(1999:2011, "-12-31", sep="") input_date <- as.Date(input_chr) result_int <- as.integer(c(5, 7, 1, 2, 3, 5, 6, 7, 1, 3, 4, 5, 6)) expect_that(ISOweekday(input_date), equals(result_int)) expect_that(ISOweekday(input_chr), equals(result_int)) }) test_that("ISOweekday handles NAs", { expect_that(ISOweekday(NA), equals(NA_integer_)) expect_that(ISOweekday(NA_character_), equals(NA_integer_)) input_chr <- paste(1999:2011, "-12-31", sep="") result_int <- as.integer(c(5, 7, 1, 2, 3, 5, 6, 7, 1, 3, 4, 5, 6)) idx_NA <- seq(from =2, to = length(input_chr), by = 2) input_chr_NA <- input_chr input_chr_NA[idx_NA] <- NA_character_ input_date_NA <- as.Date(input_chr_NA) result_int_NA <- result_int result_int_NA[idx_NA] <- NA expect_that(ISOweekday(input_date_NA), equals(result_int_NA)) expect_that(ISOweekday(input_chr_NA), equals(result_int_NA)) }) test_that("ISOweekday handles zero length vectors", { input_date <- as.Date("1999-12-31") expect_that(length(ISOweekday(input_date[0])), equals(0)) }) test_that("ISOweekday stops on invalid parameters", { expect_that(ISOweekday(31), throws_error()) expect_that(ISOweekday(31.1), throws_error()) expect_that(ISOweekday(FALSE), throws_error()) expect_that(ISOweekday("31"), throws_error()) expect_that(ISOweekday("12/31/1999"), throws_error()) }) ISOweek/man/0000755000175100001440000000000011631611437012354 5ustar hornikusersISOweek/man/date2ISOweek.Rd0000744000175100001440000000203111631611436015065 0ustar hornikusers\name{date2ISOweek} \alias{date2ISOweek} \title{Converts date from standard notation to week notation according to ISO 8601} \usage{ date2ISOweek(date) } \arguments{ \item{date}{Vector which can be coerced to class \code{Date}} } \value{ A character vector of year, week, and weekday in format "\code{\%Y-W\%V-\%u}" } \description{ This function returns the year, the week of the year, and the day of week of a given date according to ISO 8601. It is an substitute for the \code{\%Y-W\%V-\%u} format which is not implemented on Windows. } \details{ According to ISO 8601, the year of the week can differ from the calendar year (see the examples). } \examples{ x <- paste(1999:2011, "-12-31", sep = "") y <- as.Date(x) data.frame(date = format(y), weekdate = date2ISOweek(y)) data.frame(date = x, weekdate = date2ISOweek(x)) } \author{ Uwe Block \email{u.block.mz@googlemail.com} } \seealso{ \code{\link{strptime}} for a description of the date formats and references on ISO 8601. } ISOweek/man/ISOweek.Rd0000744000175100001440000000221111631611436014145 0ustar hornikusers\name{ISOweek} \alias{ISOweek} \title{Week of the year according to ISO 8601} \usage{ ISOweek(date) } \arguments{ \item{date}{Vector which can be coerced to class \code{Date}} } \value{ A character vector of year and week in format "\code{\%Y-W\%V}" } \description{ This function returns the year and the week of the year of a given date according to ISO 8601. It is an substitute for the \code{\%Y-W\%V} format which is not implemented on Windows. } \details{ According to ISO 8601, the year of the week can differ from the calendar year (see the examples). } \examples{ x <- paste(1999:2011, "-12-31", sep = "") y <- as.Date(x) data.frame(date = format(y), week = ISOweek(y)) data.frame(date = x, week = ISOweek(x)) } \author{ Hatto von Hatzfeld \email{hatto@salesianer.de}, adopted to \R by Uwe Block \email{u.block.mz@googlemail.com} } \references{ \url{http://www.salesianer.de/util/kalwoch.html} } \seealso{ \code{\link{strptime}} for a description of the date formats and references on ISO 8601. \code{\link[surveillance]{isoWeekYear}} for an alternative implementation. } ISOweek/man/ISOweek2date.Rd0000744000175100001440000000213311631611436015070 0ustar hornikusers\name{ISOweek2date} \alias{ISOweek2date} \title{Converts date from week notation according to ISO 8601 to standard notation} \usage{ ISOweek2date(weekdate) } \arguments{ \item{weekdate}{A character vector of year, week, and weekday in format "\code{\%Y-W\%V-\%u}"} } \value{ A vector of class \code{Date} } \description{ This function returns the date of a given weekdate (year, week of the year, day of week according to ISO 8601). It is the inverse function to \code{date2ISOweek}. } \details{ According to ISO 8601, the year of the week can differ from the calendar year (see the examples). } \examples{ w <- paste("2009-W53", 1:7, sep = "-") data.frame(weekdate = w, date = ISOweek2date(w)) # convert from calendar date to week date and back to calendar date x <- paste(1999:2011, "-12-31", sep = "") w <- date2ISOweek(x) d <- ISOweek2date(w) data.frame(date = x, weekdate = w, date2 = d) } \author{ Uwe Block \email{u.block.mz@googlemail.com} } \seealso{ \code{\link{strptime}} for a description of the date formats and references on ISO 8601. } ISOweek/man/ISOweekday.Rd0000744000175100001440000000132611631611436014651 0ustar hornikusers\name{ISOweekday} \alias{ISOweekday} \title{Day of week according to ISO 8601} \usage{ ISOweekday(date) } \arguments{ \item{date}{Vector which can be coerced to class \code{Date}} } \value{ An integer vector of weekdays (1-7, Monday is 1) } \description{ This function returns the weekday of a given date according to ISO 8601. It is an substitute for the "\code{\%u}" format which is not implemented on Windows. } \examples{ x <- paste(1999:2011, "-12-31", sep = "") y <- as.Date(x) data.frame(date = format(y), weekday = ISOweekday(y)) data.frame(date = x, weekday = ISOweekday(x)) } \author{ Uwe Block \email{u.block.mz@googlemail.com} } \seealso{ \code{\link{strptime}} } ISOweek/man/thursday0.Rd0000744000175100001440000000073511631611437014574 0ustar hornikusers\name{thursday0} \alias{thursday0} \title{Date of the nearest Thursday of a given date} \usage{ thursday0(date) } \arguments{ \item{date}{Vector which can be coerced to class \code{Date}} } \value{ A vector of dates of the nearest Thursdays } \description{ This internal function returns the date of the Thursday of the week in which the given date is located. } \details{ The week starts on Monday and ends on Sunday. } \keyword{internal} ISOweek/man/weekday0.Rd0000744000175100001440000000073611631611437014363 0ustar hornikusers\name{weekday0} \alias{weekday0} \title{Weekday as integer number (0-6, Monday is 0)} \usage{ weekday0(date) } \arguments{ \item{date}{Vector which can be coerced to class \code{Date}} } \value{ An integer vector of weekdays (0-6, Monday is 0) } \description{ This internal function returns the weekday of a given date. } \details{ The week starts on Monday and ends on Sunday. } \seealso{ \code{\link{ISOweekday}} } \keyword{internal} ISOweek/man/year0.Rd0000744000175100001440000000051411631611437013664 0ustar hornikusers\name{year0} \alias{year0} \title{Calendar year of a given date} \usage{ year0(date) } \arguments{ \item{date}{Vector which can be coerced to class \code{Date}} } \value{ An integer vector of years } \description{ This internal function returns the year with century as integer. } \keyword{internal} ISOweek/NAMESPACE0000744000175100001440000000022011631611437013013 0ustar hornikusersexport(date2ISOweek) export(ISOweek) export(ISOweek2date) export(ISOweekday) importFrom(stringr,str_detect) importFrom(stringr,str_match) ISOweek/NEWS0000744000175100001440000000142411631611437012302 0ustar hornikusersISOweek 0.6-2 ------------- BUG FIX * Fixed problems when package "lubridate" is loaded. lubridate overrides + and - methods for POSIXt, Date and difftime ISOweek 0.6-1 ------------- MINOR CHANGES * Minor corrections to the documentation * Added one more example to ISOweek2date() * Moved internal functions to separate file, added keyword internal * Corrected email address of maintainer ISOweek 0.6.0 ------------- MAJOR CHANGES * Added the functions date2ISOweek() and ISOweek2date() ISOweek 0.5 ----------- MAJOR CHANGES * Code was restructured and rewritten. Comments and variable names were translated from German to English. * Documentation added to R sources using roxygen2 * Test cases added for use by test_that ISOweek/R/0000755000175100001440000000000011631611437012002 5ustar hornikusersISOweek/R/date2ISOweek.R0000744000175100001440000000204411631611437014354 0ustar hornikusers#' Converts date from standard notation to week notation according to ISO 8601 #' #' This function returns the year, the week of the year, and the day of week of a given date according to ISO 8601. #' It is an substitute for the \code{\%Y-W\%V-\%u} format which is not implemented on Windows. #' #' According to ISO 8601, the year of the week can differ from the calendar year (see the examples). #' #' @param date Vector which can be coerced to class \code{Date} #' @return A character vector of year, week, and weekday in format "\code{\%Y-W\%V-\%u}" #' @seealso \code{\link{strptime}} for a description of the date formats and references on ISO 8601. #' @export #' @author Uwe Block \email{u.block.mz@@googlemail.com} #' @examples #' x <- paste(1999:2011, "-12-31", sep = "") #' y <- as.Date(x) #' data.frame(date = format(y), weekdate = date2ISOweek(y)) #' data.frame(date = x, weekdate = date2ISOweek(x)) date2ISOweek <- function(date) { return(ifelse(is.na(date), NA_character_, paste(ISOweek(date), ISOweekday(date), sep = "-"))) }ISOweek/R/ISOweek-internal.R0000744000175100001440000000231411631611437015246 0ustar hornikusers#' Weekday as integer number (0-6, Monday is 0) #' #' This internal function returns the weekday of a given date. #' #' The week starts on Monday and ends on Sunday. #' #' @param date Vector which can be coerced to class \code{Date} #' @return An integer vector of weekdays (0-6, Monday is 0) #' @seealso \code{\link{ISOweekday}} #' @keywords internal weekday0 <- function(date) { return(ISOweekday(date) - 1L) } #' Date of the nearest Thursday of a given date #' #' This internal function returns the date of the Thursday of the week in which the given date is located. #' #' The week starts on Monday and ends on Sunday. #' #' @param date Vector which can be coerced to class \code{Date} #' @return A vector of dates of the nearest Thursdays #' @keywords internal thursday0 <- function(date) { date <- as.Date(date) return(date - weekday0(date) + 3) } #' Calendar year of a given date #' #' This internal function returns the year with century as integer. #' #' @param date Vector which can be coerced to class \code{Date} #' @return An integer vector of years #' @keywords internal year0 <- function(date) { date <- as.Date(date) return(as.integer(format(date, "%Y"))) } ISOweek/R/ISOweek.R0000744000175100001440000000373311631611437013442 0ustar hornikusers#' Week of the year according to ISO 8601 #' #' This function returns the year and the week of the year of a given date according to ISO 8601. #' It is an substitute for the \code{\%Y-W\%V} format which is not implemented on Windows. #' #' According to ISO 8601, the year of the week can differ from the calendar year (see the examples). #' #' @param date Vector which can be coerced to class \code{Date} #' @return A character vector of year and week in format "\code{\%Y-W\%V}" #' @seealso \code{\link{strptime}} for a description of the date formats and references on ISO 8601. #' \code{\link[surveillance]{isoWeekYear}} for an alternative implementation. #' @export #' @author Hatto von Hatzfeld \email{hatto@@salesianer.de}, #' adopted to \R by Uwe Block \email{u.block.mz@@googlemail.com} #' @references \url{http://www.salesianer.de/util/kalwoch.html} #' @examples #' x <- paste(1999:2011, "-12-31", sep = "") #' y <- as.Date(x) #' data.frame(date = format(y), week = ISOweek(y)) #' data.frame(date = x, week = ISOweek(x)) ISOweek <- function(date) { date <- as.Date(date) nearest_thursday <- thursday0(date) year <- year0(nearest_thursday) # year of the week can differ from year of the date # first week of the year includes always the 4th of January, # take care of NA dates january04 <- as.Date(ifelse(is.na(year), NA, paste(year, "01", "04", sep="-"))) # first thursday of the year first_thursday <- thursday0(january04) # difference in days, use difftime explicitly to avoid problems with package "lubridate" # lubridate overrides + and - methods for POSIXt, Date and difftime diffdays <- difftime(nearest_thursday, first_thursday, units = "days") stopifnot(class(diffdays) == "difftime") # as.integer is required to convert difftime object week <- as.integer(diffdays) %/% 7 + 1 # use sprintf to produce leading zeros for the week number return(ifelse(is.na(week), NA_character_, sprintf("%04.0f-W%02.0f", year, week))) } ISOweek/R/ISOweek2date.R0000744000175100001440000000427311631611437014362 0ustar hornikusers#' Converts date from week notation according to ISO 8601 to standard notation #' #' This function returns the date of a given weekdate (year, week of the year, day of week according to ISO 8601). #' It is the inverse function to \code{date2ISOweek}. #' #' According to ISO 8601, the year of the week can differ from the calendar year (see the examples). #' #' @param weekdate A character vector of year, week, and weekday in format "\code{\%Y-W\%V-\%u}" #' @return A vector of class \code{Date} #' @seealso \code{\link{strptime}} for a description of the date formats and references on ISO 8601. #' @export #' @importFrom stringr str_detect str_match #' @author Uwe Block \email{u.block.mz@@googlemail.com} #' @examples #' w <- paste("2009-W53", 1:7, sep = "-") #' data.frame(weekdate = w, date = ISOweek2date(w)) #' # convert from calendar date to week date and back to calendar date #' x <- paste(1999:2011, "-12-31", sep = "") #' w <- date2ISOweek(x) #' d <- ISOweek2date(w) #' data.frame(date = x, weekdate = w, date2 = d) ISOweek2date <- function(weekdate) { kPattern <- "^([0-9]{4})-W([0-9]{2})-([0-9]{1})$" # not used kPattern <- "^([0-9]{4})-W([0][1-9]|[1-4][0-9]|[5][0-3])-([1-7]{1})$" # instead check ranges separately stopifnot(all(is.na(weekdate) | stringr::str_detect(weekdate, kPattern))) wd_ywd <- stringr::str_match(weekdate, kPattern) # take care of all NA input because this will break the split into 4 columns if (all(is.na(weekdate))) { return(rep(as.Date(NA_character_), length.out = length(weekdate))) } stopifnot(ncol(wd_ywd) == 4) year <- wd_ywd[, 2] week <- as.integer(wd_ywd[, 3]) weekday <- as.integer(wd_ywd[, 4]) stopifnot(all(is.na(week) | (1 <= week & week <= 53))) stopifnot(all(is.na(weekday) | (1 <= weekday & weekday <= 7))) # first week of the year includes always the 4th of January, # take care of NA dates january04 <- as.Date(ifelse(is.na(year), NA, paste(year, "01", "04", sep="-"))) # first thursday of the year first_thursday <- thursday0(january04) # advance by week-1 thursdays nearest_thursday <- first_thursday + 7 * (week - 1) # correct for weekday return(nearest_thursday - 4 + weekday) }ISOweek/R/ISOweekday.R0000744000175100001440000000137111631611437014134 0ustar hornikusers#' Day of week according to ISO 8601 #' #' This function returns the weekday of a given date according to ISO 8601. #' It is an substitute for the "\code{\%u}" format which is not implemented on Windows. #' #' @param date Vector which can be coerced to class \code{Date} #' @return An integer vector of weekdays (1-7, Monday is 1) #' @author Uwe Block \email{u.block.mz@@googlemail.com} #' @seealso \code{\link{strptime}} #' @export #' @examples #' x <- paste(1999:2011, "-12-31", sep = "") #' y <- as.Date(x) #' data.frame(date = format(y), weekday = ISOweekday(y)) #' data.frame(date = x, weekday = ISOweekday(x)) ISOweekday <- function(date) { date <- as.Date(date) return(as.integer((as.integer(format(date, "%w"))+6) %% 7 + 1)) } ISOweek/tests/0000755000175100001440000000000011631611437012743 5ustar hornikusersISOweek/tests/run-all.R0000744000175100001440000000007611631611437014444 0ustar hornikuserslibrary(testthat) library(ISOweek) test_package("ISOweek")ISOweek/MD50000644000175100001440000000212611631616126012112 0ustar hornikusers45d6f118749fa5becf439be1a74e8a61 *DESCRIPTION 9b1fcecf65f88ea3f0c420843a32f7fa *NAMESPACE 519f0c95d03ef916cb513b81d9ebb53f *NEWS eb30c9cfbf56bcfd41ef6dac88743eed *R/ISOweek-internal.R b1e8100f6ac6c029a85449cf7687861e *R/ISOweek.R b87a8d0729d14ced0b0af5cc4d6767b5 *R/ISOweek2date.R beaec8387c382319e3354b83aaad102f *R/ISOweekday.R fe126cc496d3732e673975c95ee44960 *R/date2ISOweek.R fc22fc851b8e8732c9144909f9e1f2c9 *inst/tests/test-ISOweek-internal.r 0efe09816e6e53c451243588bdb21ba5 *inst/tests/test-ISOweek.r 61774a79bcd510e3c5809b70f93a906d *inst/tests/test-ISOweek2date.r 4f1aee9053e0034a0c8a6df94652700f *inst/tests/test-ISOweekday.r ecee54021c873024674f539f89fd225b *inst/tests/test-date2ISOweek.r d9e79e6dda1d8affba3dc14f793bb2ab *man/ISOweek.Rd 445ec8a204d6f2c95846c869c0943c72 *man/ISOweek2date.Rd ebdcd16e791345121815f4f11b9c2ef1 *man/ISOweekday.Rd b51c1b84626cb12a7336945f5b4ea83a *man/date2ISOweek.Rd 77c899876a85fcb9de73a78e68a54418 *man/thursday0.Rd 5b74ebb12cd750c53339d6f7a627c8a1 *man/weekday0.Rd df69498b0fa045d7d9379d62ce6218b8 *man/year0.Rd 43cc7deba9991700886c056f4b03775c *tests/run-all.R