Comparing date addition and subtraction
Comparing date addition and subtraction
PeterCullenBurbery
I aim to compare date addition methods such as roll over, roll forward.
In 13.1 DatePlus and DateDifference were given a new method option for how computations should be made.
My birthday was at Cabell-Huntington hospital in Huntington West Virginia at 11:45 pm. I would like to think that it was 11:45:45pm to the second, so I'll go with that. The date was 18 February 2002 in the cold winter.
I will analyze dates with my birthday.
In[]:=
$birthday=DateObject"18 February 2002 11:45:45 pm",CalendarType->"Gregorian",DateFormat->"LocaleDateTimeFull",TimeZone->
Out[]=
I'm not sure why the date doesn't display 11:45:45 but it probably has something to do with daylight savings time.
In[]:=
$18thbirthday=DatePlus[$birthday,{18,"Year"}]
Out[]=
In[]:=
different18thbirthdays=AssociationMap[DatePlus[$birthday,{18,"Year"},Method->#]&,{"Continuous","RollForward","RollBackward","RollOver"}]
Out[]=
Continuous,RollForward,RollBackward,RollOver
I want to check if the values are all different.
In[]:=
DuplicateFreeQ[different18thbirthdays]
Out[]=
False
Let's delete the duplicates:
In[]:=
DeleteDuplicates[different18thbirthdays]
Out[]=
Continuous,RollForward
I think its interesting that if my 18th birthday was implemented with continuous time, I would have turned 18 on 14 February 2002.
Analyze the date difference:
In[]:=
DateDifference@@Values[DeleteDuplicates[different18thbirthdays]]
Out[]=
Make a table of my birthdays:
In[]:=
myBirthdays=AssociationMap[yearAssociationMap[DatePlus[$birthday,{year,"Year"},Method->#]&,{"Continuous","RollForward","RollBackward","RollOver"}],Range[20]]
Out[]=
In[]:=
Dataset[AssociationMap[yearAssociationMap[DatePlus[$birthday,{year,"Year"},Method->#]&,{"Continuous","RollForward","RollBackward","RollOver"}],Range[20]]]
Out[]=
In[]:=
DeleteDuplicates/@myBirthdays
Out[]=
1Continuous,2Continuous,3Continuous,RollForward,4Continuous,RollForward,5Continuous,RollForward,6Continuous,RollForward,7Continuous,RollForward,8Continuous,RollForward,9Continuous,RollForward,10Continuous,RollForward,11Continuous,RollForward,12Continuous,RollForward,13Continuous,RollForward,14Continuous,RollForward,15Continuous,RollForward,16Continuous,RollForward,17Continuous,RollForward,18Continuous,RollForward,19Continuous,RollForward,20Continuous,RollForward
Analyze the differences between continuous and roll forward. Which
First sort by length because the first years have only one element each, then by the difference between the dates:
In[]:=
ReverseSortBy[{Length,Now}][DeleteDuplicates/@myBirthdays]
Out[]=
20Continuous,RollForward,19Continuous,RollForward,18Continuous,RollForward,17Continuous,RollForward,16Continuous,RollForward,15Continuous,RollForward,14Continuous,RollForward,13Continuous,RollForward,12Continuous,RollForward,11Continuous,RollForward,10Continuous,RollForward,9Continuous,RollForward,8Continuous,RollForward,7Continuous,RollForward,6Continuous,RollForward,5Continuous,RollForward,4Continuous,RollForward,3Continuous,RollForward,2Continuous,1Continuous
In[]:=
Differences@*Values@*DeleteDuplicates/@myBirthdays
Out[]=
1{},2{},3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
DeleteCases[Differences@*Values@*DeleteDuplicates/@myBirthdays,{}]
Out[]=
3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
Now I can map first over the association.
In[]:=
First/@DeleteCases[Differences@*Values@*DeleteDuplicates/@myBirthdays,{}]
Out[]=
3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
I think it looks like every four years a difference of one happens based on the ListPlot.
Make a function for my age:
Delete duplicates.
It seems there is a difference in the methods, but its the computer's evaluation not the methods:
I want to compare some large times so I'm going to add the age of the Earth.
The age of the Earth is not known to enough precision to be interesting.
Time is bounded from below with the planck time:
See all the digits:
See my age in the planck time:
Make a short quiz on which units are used to express the age of the Earth: