scripting@wanadoo.nl




SerialTime()

http://www.scriptlogic.com/kixtart/FunctionLibrary_FunctionList.aspx


actual FunctionLibrary list on 'Scriptlogic' site printer-friendly mirror of UDF topic on 'scripting@wanadoo.nl' site close
25 March 2002 SerialTime()
AuthorW.M. Hinsch (New Mexico Mark)
Action Convert time to numbers (and back) for the purpose of performing time math.
SyntaxSerialTime ( "strTime" )
-or-
SerialTime ( intSeconds ) 
Parameters
  • strTime -or- intSeconds (Required / Numeric) if strTime is supplied, it must be a sting in "HH:MM[:SS]" format. if intSeconds is supplied it must be an integer greater than zero and less than 86400. 
  • RemarksThis function is a complement to the SerialDate() function, when one needs to work with dates AND times. 
    ReturnsIf supplied a time, returns seconds since midnight. If supplied seconds since midnight, returns time. 
    DependenciesAbs(), Mod(), Word() 
    Examples
    $Value = ""
    DO
      IF $Value <> ""
        ? SerialTime($Value) ?
      ENDIF
      "Enter time or serial string less than 86399, Q to quit: "
      GETS $Value ? ?
    UNTIL $Value = "Q"
    
    ; "01:00"     returns 3600
    ; "23:59:59"  returns 86399
    ; "0:0:1"     returns 1
    ; "7200"      returns "02:00:00"
    
     
    Source
    FUNCTION SerialTime ($tors)
      ; Syntax: SerialTime(Time | Serial)
      ; Where Time is a time string in HH:MM[:SS] format or
      ; Serial is a time serial number (seconds since midnight) 1 - 86399
      ; If Time is supplied, SerialTime will return the seconds since midnight.
      ; If seconds since midnight is supplied, SerialTime will return a time.
      ; DEPENDENCIES: word(), abs(), mod()
    
      DIM $hours, $minutes, $seconds, $serial, $error
      $error = 0
      IF InStr($tors,":") ; Time supplied
        $tors = "" + $tors  ; Cast to string
        IF (Len($tors) > 4) AND (Len($tors) < 9)
          $hours = 0 + word($tors,1,":")      ; Hours as integer for calculation
          IF ($hours > 23)
            $error = 1
          ENDIF
          $minutes = 0 + word($tors,2,":")    ; Minutes as integer for calculation
          IF ($minutes > 59)
            $error = 1
          ENDIF
          $seconds = 0 + word($tors,3,":")    ; Seconds as integer for calculation
          IF ($seconds > 59)
            $error = 1
          ENDIF
          $serial = ($hours * 3600) + ($minutes * 60) + $seconds
          IF ($serialtime > 86399)
            $error = 1
          ENDIF
          IF $error
            $serialtime = "-1"          ; error
          ELSE
            $serialtime = "" + $serial  ; Return as string
          ENDIF
        ELSE
          $serialtime = "-1"            ; error
        ENDIF
      ELSE ; Seconds supplied
        $tors = 0 + $tors  ; Cast to integer for calculation
        IF ($tors <= 86399) AND ($tors >= 0)
          $hours = $tors / 3600
          $tors = $tors - ($hours * 3600)
          $hours = "" + $hours
          $hours = Substr("00",1,2 - Len($hours)) + $hours
          $minutes = $tors / 60
          $tors = $tors - ($minutes * 60)
          $minutes = "" + $minutes
          $minutes = Substr("00",1,2 - Len($minutes)) + $minutes
          $seconds = "" + $tors
          $seconds = Substr("00",1,2 - Len($seconds)) + $seconds
          $serialtime = $hours + ":" + $minutes + ":" + $seconds  ; Return as string
        ELSE
          $serialtime = "-1"  ; error
        ENDIF
      ENDIF
    ENDFUNCTION ; - SerialTime -
     
      original source of UDF topic. show actual FunctionLibrary list on Scriptlogic site close top
              printer-friendly mirror of UDF topic on scripting@wanadoo.nl site  




    Copyright © 2003 www.scriptlogic.com & scripting@wanadoo.nl - last updated on 20 May 2003


    Site Meter