Other #1488

Write a C function for recognizing date formats

Added by Andy Dufilie about 2 years ago. Updated about 2 years ago.

Status:ResolvedStart date:03/11/2015
Priority:NormalDue date:
Assignee:Philip Kovac% Done:


Target version:-
Complexity: OIC Priority:No
Required by:


Write a C function that looks at a list of cstrings and determines if they all conform to a single date format string, and return that format string. The first pass at this function should just be in a C program for testing. Once it works, we can migrate the code to FlasCC and Weave.

Use strptime:

Here are some example date formats we should test for:

    formatPatterns: {
        shortDate: "M/d/yyyy",
        longDate: "dddd, MMMM dd, yyyy",
        shortTime: "h:mm tt",
        longTime: "h:mm:ss tt",
        fullDateTime: "dddd, MMMM dd, yyyy h:mm:ss tt",
        sortableDateTime: "yyyy-MM-ddTHH:mm:ss",
        universalSortableDateTime: "yyyy-MM-dd HH:mm:ssZ",
        rfc1123: "ddd, dd MMM yyyy HH:mm:ss GMT",
        monthDay: "MMMM dd",
        yearMonth: "MMMM, yyyy" 

     final String[] possibleFormats = {
      "EEE, dd MMM yyyy HH:mm:ss z", // RFC_822
        "EEE, dd MMM yyyy HH:mm zzzz",
        "yyyy-MM-dd'T'HH:mm:ss.SSSzzzz", // Blogger Atom feed has millisecs also
        "yyyy-MM-dd'T'HH:mm:ss z",
        "yyyy-MM-dd'T'HH:mm:ssz", // ISO_8601

string[] formats = {"M/d/yyyy", "MM/dd/yyyy",                                    
                            "d/M/yyyy", "dd/MM/yyyy", 
                            "yyyy/M/d", "yyyy/MM/dd",
                            "M-d-yyyy", "MM-dd-yyyy",                                    
                            "d-M-yyyy", "dd-MM-yyyy", 
                            "yyyy-M-d", "yyyy-MM-dd",
                            "M.d.yyyy", "MM.dd.yyyy",                                    
                            "d.M.yyyy", "dd.MM.yyyy", 
                            "yyyy.M.d", "yyyy.MM.dd",
                            "M,d,yyyy", "MM,dd,yyyy",                                    
                            "d,M,yyyy", "dd,MM,yyyy", 
                            "yyyy,M,d", "yyyy,MM,dd",
                            "M d yyyy", "MM dd yyyy",                                    
                            "d M yyyy", "dd MM yyyy", 
                            "yyyy M d", "yyyy MM dd" 

Date and Time Pattern     Result
"yyyy.MM.dd G 'at' HH:mm:ss z"     2001.07.04 AD at 12:08:56 PDT
"EEE, MMM d, ''yy"     Wed, Jul 4, '01
"h:mm a"     12:08 PM
"hh 'o''clock' a, zzzz"     12 o'clock PM, Pacific Daylight Time
"K:mm a, z"     0:08 PM, PDT
"yyyyy.MMMMM.dd GGG hh:mm aaa"     02001.July.04 AD 12:08 PM
"EEE, d MMM yyyy HH:mm:ss Z"     Wed, 4 Jul 2001 12:08:56 -0700
"yyMMddHHmmssZ"     010704120856-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSZ"     2001-07-04T12:08:56.235-0700
"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"     2001-07-04T12:08:56.235-07:00

2015_Moon_Export.csv Magnifier (30.5 KB) Andy Dufilie, 03/11/2015 02:47 PM

2015_Planet_Export.csv Magnifier (79.8 KB) Andy Dufilie, 03/11/2015 02:47 PM

2015_Sun_Export.csv Magnifier (17 KB) Andy Dufilie, 03/11/2015 02:47 PM


#1 Updated by Andy Dufilie about 2 years ago

  • Description updated (diff)

#2 Updated by Andy Dufilie about 2 years ago

Sample files attached - these show the type of data we wish to recognize

#3 Updated by Andy Dufilie about 2 years ago

  • Assignee changed from John Fallon to Philip Kovac

#4 Updated by Philip Kovac about 2 years ago

  • Status changed from Open to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF