Read Date and Time Package - Readme

Harry Bishop
Process Modeling Solutions, Inc.
17 April 2006

hrbishop@pmsi-va.com

Gettting data in a form that can be used for data analysis can be a time consuming project by itself. Data sources can include text based documents such as letters, emails and text notes.  In recovering the actual data content from this type of information, an important data element is a date or time that may be part of a text string. This notebook is a package of functions related to reading text strings that represent date or time or both types of data and converting them to a datatype conducive to using the information content.  The importing of text informaton containing dates and/or times is based on the formats of standard interfaces.  In addition, a fully customizable output format is available for display of the datatype that can also be exported as a string.

The datatype date▫time is constructed and parts are selectable.  Manipulation consist of differencing, comparisons, and additions of a number of days. Numbers can be converted to the datatype where the number value is taken in days.  Strings can be checked for matching allowed formats and for conversion to the datatype.  In addition, a string consisting of dates and or times such as in a sentence can be separated to provide the dates and times matching the built in formats.  Examples are provided in the last section.

Loading the package ReadDateTime

The package ReadDateTime is placed in folder PMSI located along the filepath:  "/Applications/Mathematica 5.2.app/AddOns/Applications"/PMSI.
I use the Get request and select initialization as a cell property such as:

<< PMSI`ReadDateTime`;

Exported functions and constants are found by using Names and each has a usage message to describe the arguments and return values.

Names["PMSI`ReadDateTime`*"]

For questions or comments please email me at hrbishop@pmsi-va.com

Examples to use the package and possible tests

?deconstruct*

?deconstructDate

\(Map[
      deconstructTime, {"1:35PM", "2:23:45 pm", "13:22:55.1", "1:35"}]\)

\(Map[
      deconstructDate, {"20-dec-2006", "15nov05", "13-Mar", "october03", "12/5/2001", "12/4/01", "aug05", "3/12"}]\)

deconstructDateTime[{"March 3, 2005", "13:35:17.3"}]

deconstructDateTime[{"3/12", "13:35:17.3"}]

Map[
      valid▫dateQ, {"20-dec-2006", "15nov05", "\
13-Mar", "october03", "12/30/2001", "12/4/01", "aug05", "\
3/12", "march 5 2000"}]

\(Map[
      valid▫timeQ, {"1:35PM", "2:23:45 pm", "13:22:55.1", "1:35", "24:35:59"}]\)

test = 
      make…date▫time[Date[]]

test + 86400.9999999999999999999999

monthddyyyy[test]

monthyyyy[test]
monthyy[test]

ddMMMyyyy[test]
ddMMMyy[test]
ddMMM[test]

mmddyyyy[test]
mmddyy[test]
mmdd[test]

testam = 
      make…date▫time[{2006, 3, 31, 9, 25, 
          16}]

hhmnss[testam]
hhmn[testam]
hhmnssEXP[testam]
hhmnEXP[testam]
hhmnssPM[testam]
hhmnPM[testam]

?VerticalSeparator

testam \[VerticalSeparator] "hh:mn:ss AM"

Context[make…date▫time]

testdays = 
      make…date▫time[{1850, 3, 31, 9, 25, 
          16}]
valueDTtoDT[valueDT[testdays]]

findDateTimeStrings["4:16:23 pm March 27, 2006 1440 16:23"]

Data Example

\(\(handData = 
{"1:35pm 3-27-06 124", 
"7:44am 3-27-06 106", 
"6:08pm 3-26-06 140", 
"7:35am 3-26-06 173", 
"6:44 3-25-06 153", 
"5:08pm 3-25-06 140", 
"7:41am 3-24-06 138", 
"7:03pm 3-23-06 98", 
"11:11am 3-23-06 185", 
"7:24am 3-23-06 146", 
"5:06pm 3-22-06 139", 
"1:58pm 3-22-06 124", 
"7:42am 3-22-06 141", 
"6:32pm 3-21-06 96", 
"12:01pm 3-21-06 135", 
"7:21am 3-21-06 133", 
"6:33pm 3-20-06 121", 
"12:54pm 3-20-06 95"};\)\)

Map[deconstructDateTime[findDateTimeStrings[#]] &, handData]

Reformat Rules for Data

readingItemQ[r_?NonNegative] := 0 < r < 1000. ;
readingItemQ[rs_String] := 
        readingItemQ[ToExpression[rs]];
readingItemQ[_] := False;

\(\(deconstructDataRules = {
{e1_List, 
              e2_?readingItemQ} :> {e1, 
              e2}, 
\((e1_String)\) :> \((\(StringSplit[e1, " "] /. {s1_?valid▫timeQ, 
                      s2_?valid▫dateQ, 
                      s3_?readingItemQ} :> {deconstructDateTime[{s2, s1}], ToExpression[s3]}\) /. {s1_?
                      valid▫dateQ, 
                    s2_?valid▫timeQ, 
                    s3_?readingItemQ} :> {deconstructDateTime[{s1, s2}], 
                    ToExpression[
                      s3]})\), 
__ :> 
            Null
};\)\)

Map[# /. deconstructDataRules &, handData]