Is there a better way?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • TJ_Tigger
    Indigo Rose Customer
    • Sep 2002
    • 3159

    Is there a better way?

    I was working on a piece of a script that checks the file written date and compares it to the current system date. The format of the two dates is different. for the system date I used

    Code:
    mm = System.GetDate(DATE_FMT_MONTH);
    dd = System.GetDate(DATE_FMT_DAY);
    yyyy = System.GetDate(DATE_FMT_YEAR);
    dow = System.GetDate(DATE_FMT_DAYOFWEEK);
    and it returns a string for instance for today it would return
    mm = 02
    dd = 09
    yyyy = 2004
    dow = 2

    I then wanted to convert this to a comparable format that is retrieved by the File.GetAttributes (table.WriteDate). Which is returned as

    Monday, February 09, 2004

    To do this I created two tables and had to convert the above GetDate information to a number.

    Here are the tables and script, but is there an easier way?
    [code]--Month table
    month = {};
    month[1] = "January";
    month[2] = "February";
    month[3] = "March";
    month[4] = "April";
    month[5] = "May";
    month[6] = "June";
    month[7] = "July";
    month[8] = "August";
    month[9] = "September";
    month[10] = "October";
    month[11] = "November";
    month[12] = "December";

    --Day of the Week Table
    dayoftheweek = {};
    dayoftheweek[1] = "Sunday";
    dayoftheweek[2] = "Monday";
    dayoftheweek[3] = "Tuesday";
    dayoftheweek[4] = "Wednesday";
    dayoftheweek[5] = "Thursday";
    dayoftheweek[6] = "Friday";
    dayoftheweek[7] = "Saturday";

    --Get date information and convert month and day of week to numbers
    mm = System.GetDate(DATE_FMT_MONTH);
    mm = String.ToNumber(mm);
    dd = System.GetDate(DATE_FMT_DAY);
    yyyy = System.GetDate(DATE_FMT_YEAR);
    dow = System.GetDate(DATE_FMT_DAYOFWEEK);
    dow = String.ToNumber(dow);

    --Display information as "DayOfWeek, Month dd, yyyy"
    Dialog.Message("Date", "The current date is "..date.."\r\nor "..dayoftheweek[dow]..", "..month[mm].." "..dd..", "..yyyy, MB_OK, MB_ICONNONE, MB_DEFBUTTON1)
    [\code]
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine
  • Stefan_M
    Indigo Rose Customer
    • Nov 2003
    • 315

    #2
    Maybe this helps

    sys_year = System.GetDate(DATE_FMT_YEAR);
    sys_month = System.GetDate(DATE_FMT_MONTH);
    sys_day = System.GetDate(DATE_FMT_DAY);
    sys_all=sys_year..sys_month..sys_day;
    num_sys_all = String.ToNumber(sys_all);

    datei = File.GetAttributes(_SourceFolder.."\\autoplay\\aut orun.cdd");
    datei_date=datei.WriteDateISO;
    datei_year=String.Mid(datei_date, 1, 4);
    datei_month=String.Mid(datei_date, 6, 2);
    datei_day=String.Mid(datei_date, 9, 2);
    datei_all=datei_year..datei_month..datei_day;
    num_datei_all = String.ToNumber(datei_all);

    if (num_sys_all~=num_datei_all) then
    --do something here
    else
    --do something else here
    end

    Stefan
    "With a rubber duck, one's never alone."

    Douglas Adams, The Hitchhiker's Guide to the Galaxy

    Comment

    • Lorne
      Indigo Rose Staff Member
      • Feb 2001
      • 2729

      #3
      Whoa, you guys are making this way too difficult.

      This is all you need right here:

      Code:
      systemDate = System.GetDate(DATE_FMT_ISO);
      tbAttrib = File.GetAttributes(_SourceFolder.."\\autoplay\\autorun.cdd");
      
      if(systemDate == tbAttrib.WriteDateISO)
      	-- dates match!
      else
      	-- dates don't match
      end
      Heck, you can even use > and < to do greater-than or lesser-than comparisons on ISO dates as strings.

      No need to break the dates into parts, or convert them to numbers, or any of that.
      --[[ Indigo Rose Software Developer ]]

      Comment

      • Stefan_M
        Indigo Rose Customer
        • Nov 2003
        • 315

        #4
        Hi Lorne,

        I looked at the Onlinehelp and found the two functions

        table File.GetAttributes ( string Filename )
        WriteDateISO string The last date the file was written to, in ISO format (2003-06-18T14:55:05).

        string System.GetDate ( number DateType )
        DATE_FMT_ISO 2 ISO Date (YYYY-MM-DD)

        I didn't see that I can compare this two strings
        file_date: 2004-02-10T20:06:52
        sys_date: 2004-02-10


        Stefan
        "With a rubber duck, one's never alone."

        Douglas Adams, The Hitchhiker's Guide to the Galaxy

        Comment

        • Lorne
          Indigo Rose Staff Member
          • Feb 2001
          • 2729

          #5
          Ah, sorry. Didn't realize it included the time. (Can you tell I didn't bother testing that script? ) That's no big deal, though. Just trim the excess off using String.Left, or add the time onto the other one if you need it to be time-specific (although I highly doubt that would be the intent in this case).

          Code:
          systemDate = System.GetDate(DATE_FMT_ISO);
          
          -- we only want the date part, not the time...so chop off
          -- everything after the first 10 characters in systemDate
          [b]systemDate = String.Left(systemDate,10);[/b]
          
          tbAttrib = File.GetAttributes(_SourceFolder.."\\autoplay\\autorun.cdd");
          
          if(systemDate == tbAttrib.WriteDateISO)
          	-- dates match!
          else
          	-- dates don't match
          end
          --[[ Indigo Rose Software Developer ]]

          Comment

          • TJ_Tigger
            Indigo Rose Customer
            • Sep 2002
            • 3159

            #6
            I figured there would be a better way to do it. As usual I picked a way (round peg) and stuck with it (square hole). Thanks for the sounding board.
            TJ-Tigger
            "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
            "Draco dormiens nunquam titillandus."
            Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

            Comment

            Working...
            X