Date, POSIXct, and POSIXlt are converted, with the timezone respected,
using clock::as_date()
.
Character input is parsed by two methods. Firstly, if format = NULL
then
character input is first checked to see if it is in the format of "YYYYWww"
(e.g. "2021W03") and parsed accordingly. If it is in a different format,
or format
is nonNULL then it is parsed using clock::date_parse()
.
as_yearweek(x, firstday = 1L, ...)
# S3 method for default
as_yearweek(x, firstday = 1L, ...)
# S3 method for character
as_yearweek(
x,
firstday = 1L,
format = "%Y%m%d",
locale = clock_locale(),
...
)
# S3 method for factor
as_yearweek(x, firstday = 1L, format = NULL, locale = clock_locale(), ...)
Arguments
x 
An object to coerce to yearweekly. 
firstday 
An integer representing the day the week starts on from 1
(Monday) to 7 (Sunday). 
... 
Not currently used. 
format 
[character / NULL]
A format string. A combination of the following commands, or NULL ,
in which case a default format string is used.
A vector of multiple format strings can be supplied. They will be tried in
the order they are provided.
Year
%C : The century as a decimal number. The modified command %NC where
N is a positive decimal integer specifies the maximum number of
characters to read. If not specified, the default is 2 . Leading zeroes
are permitted but not required.
%y : The last two decimal digits of the year. If the century is not
otherwise specified (e.g. with %C ), values in the range [69  99] are
presumed to refer to the years [1969  1999] , and values in the range
[00  68] are presumed to refer to the years [2000  2068] . The
modified command %Ny , where N is a positive decimal integer, specifies
the maximum number of characters to read. If not specified, the default is
2 . Leading zeroes are permitted but not required.
%Y : The year as a decimal number. The modified command %NY where N
is a positive decimal integer specifies the maximum number of characters to
read. If not specified, the default is 4 . Leading zeroes are permitted
but not required.
Month
%b , %B , %h : The locale 's full or abbreviated caseinsensitive
month name.
%m : The month as a decimal number. January is 1 . The modified command
%Nm where N is a positive decimal integer specifies the maximum number
of characters to read. If not specified, the default is 2 . Leading zeroes
are permitted but not required.
Day
%d , %e : The day of the month as a decimal number. The modified
command %Nd where N is a positive decimal integer specifies the maximum
number of characters to read. If not specified, the default is 2 . Leading
zeroes are permitted but not required.
Day of the week
%a , %A : The locale 's full or abbreviated caseinsensitive weekday
name.
%w : The weekday as a decimal number (06 ), where Sunday is 0 . The
modified command %Nw where N is a positive decimal integer specifies
the maximum number of characters to read. If not specified, the default is
1 . Leading zeroes are permitted but not required.
ISO 8601 weekbased year
%g : The last two decimal digits of the ISO weekbased year. The
modified command %Ng where N is a positive decimal integer specifies
the maximum number of characters to read. If not specified, the default is
2 . Leading zeroes are permitted but not required.
%G : The ISO weekbased year as a decimal number. The modified command
%NG where N is a positive decimal integer specifies the maximum number
of characters to read. If not specified, the default is 4 . Leading zeroes
are permitted but not required.
%V : The ISO weekbased week number as a decimal number. The modified
command %NV where N is a positive decimal integer specifies the maximum
number of characters to read. If not specified, the default is 2 . Leading
zeroes are permitted but not required.
%u : The ISO weekday as a decimal number (17 ), where Monday is 1 .
The modified command %Nu where N is a positive decimal integer
specifies the maximum number of characters to read. If not specified, the
default is 1 . Leading zeroes are permitted but not required.
Week of the year
%U : The week number of the year as a decimal number. The first Sunday
of the year is the first day of week 01 . Days of the same year prior to
that are in week 00 . The modified command %NU where N is a positive
decimal integer specifies the maximum number of characters to read. If not
specified, the default is 2 . Leading zeroes are permitted but not
required.
%W : The week number of the year as a decimal number. The first Monday
of the year is the first day of week 01 . Days of the same year prior to
that are in week 00 . The modified command %NW where N is a positive
decimal integer specifies the maximum number of characters to read. If not
specified, the default is 2 . Leading zeroes are permitted but not
required.
Day of the year
Date
%D , %x : Equivalent to %m/%d/%y .
%F : Equivalent to %Y%m%d . If modified with a width (like %NF ),
the width is applied to only %Y .
Time of day
%H : The hour (24hour clock) as a decimal number. The modified command
%NH where N is a positive decimal integer specifies the maximum number
of characters to read. If not specified, the default is 2 . Leading zeroes
are permitted but not required.
%I : The hour (12hour clock) as a decimal number. The modified command
%NI where N is a positive decimal integer specifies the maximum number
of characters to read. If not specified, the default is 2 . Leading zeroes
are permitted but not required.
%M : The minutes as a decimal number. The modified command %NM where
N is a positive decimal integer specifies the maximum number of
characters to read. If not specified, the default is 2 . Leading zeroes
are permitted but not required.
%S : The seconds as a decimal number. The modified command %NS where
N is a positive decimal integer specifies the maximum number of
characters to read. If not specified, the default is determined by the
precision that you are parsing at. If encountered, the locale
determines the decimal point character. Leading zeroes are permitted but
not required.
%p : The locale 's equivalent of the AM/PM designations associated with
a 12hour clock. The command %I must precede %p in the format string.
%R : Equivalent to %H:%M .
%T , %X : Equivalent to %H:%M:%S .
%r : Equivalent to %I:%M:%S %p .
Time zone
%z : The offset from UTC in the format [+]hh[mm] . For example
0430 refers to 4 hours 30 minutes behind UTC. And 04 refers to 4 hours
ahead of UTC. The modified command %Ez parses a : between the hours and
minutes and leading zeroes on the hour field are optional:
[+]h[h][:mm] . For example 04:30 refers to 4 hours 30 minutes behind
UTC. And 4 refers to 4 hours ahead of UTC.
%Z : The full time zone name or the time zone abbreviation, depending on
the function being used. A single word is parsed. This word can only
contain characters that are alphanumeric, or one of '_' , '/' , '' or
'+' .
Miscellaneous
%c : A date and time representation. Equivalent to
%a %b %d %H:%M:%S %Y .
%% : A % character.
%n : Matches one white space character. %n , %t , and a space can be
combined to match a wide range of whitespace patterns. For example "%n "
matches one or more white space characters, and "%n%t%t" matches one to
three white space characters.
%t : Matches zero or one white space characters.

locale 
[clock_locale]
A locale object created from clock_locale() . 
Value
A grates_yearweek
object.
Note
Internally grates_yearweek
objects are stored as the number of weeks
from the date of the firstday
nearest the Unix Epoch (19700101). That
is:
 19691229 for `firstday` as Monday
 19691230 for `firstday` as Tuesday
 19691231 for `firstday` as Wednesday
 19700101 for `firstday` as Thursday
 19700102 for `firstday` as Friday
 19700103 for `firstday` as Saturday
 19700104 for `firstday` as Sunday
See also
Examples
#> <grates_yearweek[1]>
#> [1] 2021W21
#> <grates_yearweek[1]>
#> [1] 2019W10
as_yearweek("20190503", firstday = 5L)
#> <grates_yearweek[1]>
#> [1] 2019W18
as_yearweek("2021W03", format = NULL)
#> <grates_yearweek[1]>
#> [1] 2021W03