In[]:=
Needs["PeterBurbery`DateTime`"]
Compute the week date for today:
In[]:=
ISOWeekDate[]
Out[]=
2022-W52-6
Compute the week date for my birthday:
In[]:=
$Birthdate=DateObject,DateFormat->"DateTime",TimeZone->
Out[]=
In[]:=
ISOWeekDate[$Birthdate]
Out[]=
2002-W8-1
The ISO Week day uses 1 for Monday, 2 for Tuesday, 3 for Wednesday, 4 for Thursday, 5 for Friday, 6 for Saturday, and 7 for Sunday. In this system, Thursday is the middle day of the week, not Wednesday, which you would have when 1 is for Sunday, 2 is for Monday, 3 is for Tuesday, 4 is Wednesday, 5 is for Thursday, 6 is for Friday, and 7 is for Saturday.
Find the date a week from now:
In[]:=
Today+
Out[]=
Find the days between now and then:
In[]:=
DayRange[Now,Today+]
Out[]=
,,,,,,,
Find the ISO week days:
In[]:=
ISOWeekDate/@DayRange[Now,Today+]
Out[]=
{2022-W52-6,2023-W52-7,2023-W1-1,2023-W1-2,2023-W1-3,2023-W1-4,2023-W1-5,2023-W1-6}
In[]:=
AssociationMap[ISOWeekDate][DayRange[Now,Today+]]
Out[]=
2022-W52-6,2023-W52-7,2023-W1-1,2023-W1-2,2023-W1-3,2023-W1-4,2023-W1-5,2023-W1-6
In[]:=
Dataset[AssociationMap[ISOWeekDate][DayRange[Now,Today+]]]
Out[]=
This means today is not New Years Eve. The last day of the year is Sunday 1 January 2023, not Saturday 1 January 2023. This means that New Years Eve is tomorrow and New Years Day is two days from now on Monday 2 January 2023.
Verify the days correspond to the right numbers:
In[]:=
AssociationMap[ISOWeekDate][DayRange[Now,Today+]]
Out[]=
2022-W52-6,2023-W52-7,2023-W1-1,2023-W1-2,2023-W1-3,2023-W1-4,2023-W1-5,2023-W1-6
In[]:=
FromISOTimestamp/@AssociationMap[ISOWeekDate][DayRange[Now,Today+]]
Out[]=
,,Failure,Failure,Failure,Failure,Failure,Failure
Whoops. I need to add a 0 for something like 2023-W01-4 instead of 2023-W1-4.
In[]:=
FromISOTimestamp["2023-W01-4"]
Out[]=
I will reprogram the function ISOWeekDay
In[]:=
globalISOWeekDate//ClearAllSetAttributes[globalISOWeekDate,{Listable}]globalISOWeekDate[date_?DateObjectQ]:=StringTemplate["<* DateValue[#1,\"Year\"] *>-W<* DateValue[#1,\"ISOWeek\",String] *>-<* DateValue[#1,\"ISOWeekDay\"] *>"][date]globalISOWeekDate[]:=ISOWeekDate[Now]
In[]:=
globalISOWeekDate[DayRange[Now,Today+]]
Out[]=
{2022-W52-6,2023-W52-7,2023-W01-1,2023-W01-2,2023-W01-3,2023-W01-4,2023-W01-5,2023-W01-6}
In[]:=
DateValue,"ISOWeekDay"
Out[]=
4
In[]:=
DateValue,"ISOWeekDay",Integer
Out[]=
4
In[]:=
DateValue,"ISOWeek",Integer
Out[]=
1
In[]:=
DateValue,"ISOWeek",String
Out[]=
01
In[]:=
DateValue,"ISOWeek",String//InputForm
Out[]//InputForm=
01
Verify again:
In[]:=
FromISOTimestamp/@AssociationMap[globalISOWeekDate][DayRange[Now,Today+]]
Out[]=
,,,,,,,
Good.
Compute the day too:
In[]:=
DayName/@FromISOTimestamp/@AssociationMap[globalISOWeekDate][DayRange[Now,Today+]]
Out[]=
Saturday,Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
Make a dataset and association for the ISO convention:
In[]:=
NextDate[Monday]
Out[]=
This is the other convention:
Verify that the ISO week date is always right