Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Interpret date strings by specifying how ambiguity should be handled
ResourceFunction["DateAmbiguityBreak"]["DayFirst"][string] interprets string as a DateObject, using a day-before-month interpretation if there is ambiguity. | |
ResourceFunction["DateAmbiguityBreak"]["MonthFirst"][string] interprets string as a DateObject, using a month-before-day interpretation if there is ambiguity. | |
ResourceFunction["DateAmbiguityBreak"][{elem1,elem2,elem3}][string] specifies a custom day-month-year pattern for prioritization. | |
ResourceFunction["DateAmbiguityBreak"][Function[…]][string] applies a function to an Association holding all possible interpretations and ambiguity data. | |
ResourceFunction["DateAmbiguityBreak"][Interpreter[…], pattern][string] uses the specified Interpreter to interpret string. |
Interpret an ambiguous date string:
| In[1]:= |
| Out[1]= |
Interpret ambiguous strings with date and time information:
| In[2]:= |
| Out[2]= |
| In[3]:= |
| Out[3]= |
Strings in year-first form are always assumed to be in the ISO standard year-month-day form:
| In[4]:= |
| Out[4]= |
| In[5]:= |
| Out[5]= |
| In[6]:= |
| Out[6]= |
Interpret multiple strings at a time:
| In[7]:= |
| Out[7]= |
Specify your own preferred formats to break ambiguity:
| In[8]:= | ![]() |
| Out[8]= |
Specify a custom function to apply to the ambiguity data in the form of an Association to make it easier to pick compatible interpretations:
| In[9]:= |
| Out[9]= | ![]() |
| In[10]:= | ![]() |
| Out[10]= |
Use a more restrictive Interpreter to parse only pure date strings:
| In[11]:= |
| Out[11]= | ![]() |
DateAmbiguityBreak uses an AmbiguityFunction to find the desired interpretation from an AmbiguityList:
| In[12]:= |
| Out[12]= | ![]() |
Note that unambiguous strings do not get placed in an AmbiguityList.
When the year is given by only two digits, a year-last interpretation is always preferred since the ISO standard mandates four year digits. Thus, dd-mm-yy takes precedence over yy-mm-dd:
| In[13]:= |
| Out[13]= |
mm-dd-yy takes precedence over yy-mm-dd:
| In[14]:= |
| Out[14]= |
Any date string that's completely unambiguous will be interpreted, even if it's incompatible with the specified pattern:
| In[15]:= |
| Out[15]= |
Wolfram Language 12.3 (May 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License