/*REXX*/
/*--- TMATH ------------------------------------ 2005 MARK MCDONALD --*/
/* TMATH$("HH:MM:SS"1, "HH:MM:SS"2, OPTION)                           */
/*  SUBTRACT OR ADD TWO TIMES                                         */
/* OPTIONS: "A" = ADD "HH:MM:SS"1 TO "HH:MM:SS"2                      */
/*          "S" = SUBTRACT "HH:MM:SS"2 FROM "HH:MM:SS"1               */
/*--------------------------------------------------------------------*/
  SAY "SUBTRACT TWO TIMES"
  SAY "START TIME = 07:30:00     15:00:00"
  SAY "  END TIME = 16:30:00     23:00:00"
  SAY "           = "TMATH("16:30:00","07:30:00","S")"     "TMATH("23:00:00","15:00:00","S")
  SAY "SHOULD BE  = 09:00:00     08:00:00"
  SAY ""
  SAY "ADD TWO TIMES"
  SAY "START TIME =  7:30:00      0:00:00"
  SAY "  END TIME =  9:30:00     12:30:00"
  SAY "           = "TMATH("7:30:00","9:30:00","A")"     "TMATH("0:00:00","12:30:00","A")
  SAY "SHOULD BE  = 17:00:00     12:30:00"
EXIT
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
/* TMATH("HH:MM:SS"1, "HH:MM:SS"2, OPTION)                            */
/* SUBTRACT OR ADD TWO TIMES                                          */
/* OPTIONS: "A" = ADD "HH:MM:SS"1 TO "HH:MM:SS"2                      */
/*          "S" = SUBTRACT "HH:MM:SS"2 FROM "HH:MM:SS"1               */
/*--------------------------------------------------------------------*/
TMATH: PROCEDURE
  PARSE ARG X1,X2,XTYPE
  XT1 = HMS2S(X1); XT2 = HMS2S(X2)
  IF XTYPE = "A" THEN XRET = (XT1 + XT2)
  IF XTYPE = "S" THEN XRET = (XT1 - XT2)
RETURN S2HMS(XRET)
/*--------------------------------------------------------------------*/
HMS2S: PROCEDURE
  PARSE ARG XX
  PARSE VAR XX XH":"XM":"XS
  XRET = ((XH * 3600) + (XM * 60) + XS)
RETURN XRET
/*--------------------------------------------------------------------*/
S2HMS: PROCEDURE
  PARSE ARG XX
      XH = (XX % 3600)
      XM = ((XX  - (XH * 3600)) % 60)
      XS = (XX  - (XH * 3600) - (XM * 60))
      XH = RIGHT("00"||XH,2)
      XM = RIGHT("00"||XM,2)
      XS = RIGHT("00"||XS,2)
      XRET = XH":"XM":"XS
RETURN XRET