Tapatalk

Converting to 24 hour-clock

Converting to 24 hour-clock

18
Basic UserBasic User
18

    Jul 02, 2012#1

    ============
    BEFORE I BEGIN, ALLOW ME TO SAY THANKS FOR ANY HELP THAT CAN BE PROVIDED.
    ============
    Here is what I've been trying to figure out. Lets say in a file I have these lines, amoung others, but these would be on individual lines by themselves:

    USER1234 (06/21/2012 02:34:59 PM EST)
    XYZ1 (06/21/2012 03:38:14 PM EST)
    ABCD (06/22/2012 06:45:05 AM EST)

    What I want to do, is for the lines to become:

    USER1234 (2012_06_21 1434:59 HOURS ET)
    XYZ1 (2012_06_21 1538:14 HOURS ET)
    ABCD (2012_06_21 0645:05 HOURS ET)

    The hours, minutes and seconds will always be two digits (e.g. "06" instead of "6"). So I want to detect the "AM" or "PM" and convert the hour into the 24-hour clock, while at the same time, removing the ":" between the hour/minute, and change the EST to ET. On that I'd be using this for, it will always display EST or EDT (or maybe EDST).

    The usenames can be of any length 1-30 characters, but the time zone will always be EST, EDT or EDST. The only way I can think of is to have two if statements first to find the "AM" or "PM", then within that IF statement eliminate the "AM" or "PM", multiple statements to locate the year, month and day and manipulate them, and also find the first ":" and remove it.

    I was hoping that there would be an easier way then multiple lines to handle the 24 possibilities (" 00:" through " 23:") of the hour to change them, for example (not synthetically correct, this is just to illustrate the idea):

    Code: Select all

       If $line contains " AM" then
          if $line contains " 01:" then
              locate " 01:" change it to " 01"
              remove the "AM"
          endif
    
          if $line contains " 02:" then
              locate " 02:" change it to " 02"
              remove the "AM"
          endif
          blahblahblah
       endif
    
       If $line contains " PM" then
          if $line contains " 01:" then
              locate " 01:" change it to " 13"
              remove the "PM"
          endif
    
          if $line contains " 02:" then
              locate " 02:" change it to " 14"
              remove the "PM"
          endif
          blahblahblah
       endif
    
    So on and so on with the other changes also. Does anyone have an idea of a better way?

    Any help is appreciated, and I again say thanks in advance... even REGEX would be OK, I just haven't gotten the hand of REGEX.

    6,685587
    Grand MasterGrand Master
    6,685587

      Jul 02, 2012#2

      Using tagged expressions this is a simple task.

      Code: Select all

      if (UltraEdit.document.length > 0) {  // Is any file opened in UE?
         // Define environment for the conversion (replaces) to 24 hour format.
         UltraEdit.insertMode();
         UltraEdit.columnModeOff();
         UltraEdit.ueReOn();   // Regular expression engine is the UltraEdit engine.
         // The conversion is done with 13 case-sensitive regular expression Replace All.
         UltraEdit.activeDocument.findReplace.mode=0;
         UltraEdit.activeDocument.findReplace.matchCase=true;
         UltraEdit.activeDocument.findReplace.matchWord=false;
         UltraEdit.activeDocument.findReplace.regExp=true;
         UltraEdit.activeDocument.findReplace.searchDown=true;
         UltraEdit.activeDocument.findReplace.searchInColumn=false;
         UltraEdit.activeDocument.findReplace.preserveCase=false;
         UltraEdit.activeDocument.findReplace.replaceAll=true;
         UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
         UltraEdit.activeDocument.top();
         // The first expression is for all dates/times with AM value.
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^)^( [01][0-9]^):^([0-5][0-9]:[0-6][0-9]^) AM E[DS]++T", "^3_^1_^2^4^5 HOURS ET");
         // The other expressions are for 00 PM -> 12, 01 PM to 13, and so on. 
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 00:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 12^4 HOURS ET");
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 01:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 13^4 HOURS ET");
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 02:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 14^4 HOURS ET");
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 03:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 15^4 HOURS ET");
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 04:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 16^4 HOURS ET");
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 05:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 17^4 HOURS ET");
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 06:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 18^4 HOURS ET");
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 07:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 19^4 HOURS ET");
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 08:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 20^4 HOURS ET");
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 09:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 21^4 HOURS ET");
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 10:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 22^4 HOURS ET");
         UltraEdit.activeDocument.findReplace.replace("^([01][0-9]^)/^([0-3][0-9]^)/^([12][0-9]+^) 11:^([0-5][0-9]:[0-6][0-9]^) PM E[DS]++T", "^3_^1_^2 23^4 HOURS ET");
      }

      18
      Basic UserBasic User
      18

        Jul 02, 2012#3

        FANTASTIC! Worked great... thanks a lot!!!