/**
 * Test formatting integers with special time formats like "hh:mm".
 */
USING OpenEdge.Core.Assert.

ROUTINE-LEVEL ON ERROR UNDO, THROW.

CLASS unittests.IntegerFormattedAsTime:
   
   /**
    * Test time legacy formats
    */
   @Test.
   METHOD PUBLIC VOID TestTimeFormats():
      DEFINE VARIABLE i3_2_1 AS INTEGER NO-UNDO.
      i3_2_1 = 3 * 60 * 60 + 2 * 60 + 1.
      
      DEFINE VARIABLE i13_2_1 AS INTEGER NO-UNDO.
      i13_2_1 = 13 * 60 * 60 + 2 * 60 + 1.
      
      DEFINE VARIABLE i24_2_1 AS INTEGER NO-UNDO.
      i24_2_1 = 24 * 60 * 60 + 2 * 60 + 1.
      
      // prefix '+hh:mm' with no suffix, hour = 3
      Assert:Equals("+02:01", STRING(i3_2_1, "+hh:mm")).
      
      // prefix '+hh:mm' with no suffix, hour = 24
      Assert:Equals("+02:01", STRING(i24_2_1, "+hh:mm")).
      
      // prefix '+hh:mm' with suffix 'a', hour = 3
      Assert:Equals("+02:01a", STRING(i3_2_1, "+hh:mma")).
      
      // prefix '+hh:mm' with suffix 'a', hour = 24
      Assert:Equals("+02:01a", STRING(i24_2_1, "+hh:mma")).
      
      // prefix '+hh:mm' with suffix 'A', hour = 3
      Assert:Equals("+02:01A", STRING(i3_2_1, "+hh:mmA")).
      
      // prefix '+hh:mm' with suffix 'A', hour = 24
      Assert:Equals("+02:01A", STRING(i24_2_1, "+hh:mmA")).
      
      // prefix '+hh:mm' with suffix 'aa', hour = 3
      Assert:Equals("+02:01aa", STRING(i3_2_1, "+hh:mmaa")).
      
      // prefix '+hh:mm' with suffix 'aa', hour = 24
      Assert:Equals("+02:01aa", STRING(i24_2_1, "+hh:mmaa")).
      
      // prefix 'hh:mm:ss' with no suffix, hour = 3
      Assert:Equals("03:02:01", STRING(i3_2_1, "hh:mm:ss")).
      
      // prefix 'hh:mm:ss' with no suffix, hour = 24
      Assert:Equals("00:02:01", STRING(i24_2_1, "hh:mm:ss")).
      
      // prefix 'hh:mm:ss' with suffix 'a', hour = 3
      Assert:Equals(" 3:02:01a", STRING(i3_2_1, "hh:mm:ssa")).
      
      // prefix 'hh:mm:ss' with suffix 'a', hour = 24
      Assert:Equals("12:02:01a", STRING(i24_2_1, "hh:mm:ssa")).
      
      // prefix 'hh:mm:ss' with suffix 'A', hour = 3
      Assert:Equals(" 3:02:01A", STRING(i3_2_1, "hh:mm:ssA")).
      
      // prefix 'hh:mm:ss' with suffix 'A', hour = 24
      Assert:Equals("12:02:01A", STRING(i24_2_1, "hh:mm:ssA")).
      
      // prefix 'hh:mm:ss' with suffix 'aa', hour = 3
      Assert:Equals(" 3:02:01aa", STRING(i3_2_1, "hh:mm:ssaa")).
      
      // prefix 'hh:mm:ss' with suffix 'aa', hour = 24
      Assert:Equals("12:02:01aa", STRING(i24_2_1, "hh:mm:ssaa")).
      
      // prefix 'hh:mm' with no suffix, hour = 3
      Assert:Equals("03:02", STRING(i3_2_1, "hh:mm")).
      
      // prefix 'hh:mm' with no suffix, hour = 24
      Assert:Equals("00:02", STRING(i24_2_1, "hh:mm")).
      
      // prefix 'hh:mm' with suffix 'a', hour = 3
      Assert:Equals(" 3:02a", STRING(i3_2_1, "hh:mma")).
      
      // prefix 'hh:mm' with suffix 'a', hour = 24
      Assert:Equals("12:02a", STRING(i24_2_1, "hh:mma")).
      
      // prefix 'hh:mm' with suffix 'A', hour = 3
      Assert:Equals(" 3:02a", STRING(i3_2_1, "hh:mmA")).
      
      // prefix 'hh:mm' with suffix 'A', hour = 24
      Assert:Equals("12:02A", STRING(i24_2_1, "hh:mmA")).
      
      // prefix 'hh:mm' with suffix 'aa', hour = 3
      Assert:Equals(" 3:02aa", STRING(i3_2_1, "hh:mmaa")).
      
      // prefix 'hh:mm' with suffix 'aa', hour = 24
      Assert:Equals("12:02aa", STRING(i24_2_1, "hh:mmaa")).
      
      // prefix '+hh:mm' with suffix 'qwe', hour = 3
      Assert:Equals("+02:01qwe", STRING(i3_2_1, "+hh:mmqwe")).
      
      // prefix '+hh:mm' with suffix 'qwe', hour = 24
      Assert:Equals("+02:01qwe", STRING(i24_2_1, "+hh:mmqwe")).
      
      // prefix '+hh:mm' with suffix 'qweA', hour = 3
      Assert:Equals("+02:01qweA", STRING(i3_2_1, "+hh:mmqweA")).
      
      // prefix '+hh:mm' with suffix 'qweA', hour = 24
      Assert:Equals("+02:01qweA", STRING(i24_2_1, "+hh:mmqweA")).
      
      // prefix '+hh:mm' with suffix 'abc', hour = 3
      Assert:Equals("+02:01abc", STRING(i3_2_1, "+hh:mmabc")).
      
      // prefix '+hh:mm' with suffix 'abc', hour = 24
      Assert:Equals("+02:01abc", STRING(i24_2_1, "+hh:mmabc")).
      
      // prefix '+hh:mm' with suffix 'abcA', hour = 3
      Assert:Equals("+02:01abcA", STRING(i3_2_1, "+hh:mmabcA")).
      
      // prefix '+hh:mm' with suffix 'abcA', hour = 24
      Assert:Equals("+02:01abcA", STRING(i24_2_1, "+hh:mmabcA")).
      
      // prefix 'hh:mm' with suffix 'qwe', hour = 3
      Assert:Equals("03:02qwe", STRING(i3_2_1, "hh:mmqwe")).
      
      // prefix 'hh:mm' with suffix 'qwe', hour = 24
      Assert:Equals("00:02qwe", STRING(i24_2_1, "hh:mmqwe")).
      
      // prefix 'hh:mm' with suffix 'qweA', hour = 3
      Assert:Equals(" 3:02qweA", STRING(i3_2_1, "hh:mmqweA")).
      
      // prefix 'hh:mm' with suffix 'qweA', hour = 24
      Assert:Equals("12:02qweA", STRING(i24_2_1, "hh:mmqweA")).
      
      // prefix 'hh:mm' with suffix 'abc', hour = 3
      Assert:Equals(" 3:02abc", STRING(i3_2_1, "hh:mmabc")).
      
      // prefix 'hh:mm' with suffix 'abc', hour = 24
      Assert:Equals("12:02abc", STRING(i24_2_1, "hh:mmabc")).
      
      // prefix 'hh:mm' with suffix 'abcA', hour = 3
      Assert:Equals(" 3:02abcA", STRING(i3_2_1, "hh:mmabcA")).
      
      // prefix 'hh:mm' with suffix 'abcA', hour = 24
      Assert:Equals("12:02abcA", STRING(i24_2_1, "hh:mmabcA")).
      
      // prefix '+hh:mm' with no suffix, hour = 13
      Assert:Equals("+02:01", STRING(i13_2_1, "+hh:mm")).
      
      // prefix '+hh:mm' with suffix 'a', hour = 13
      Assert:Equals("+02:01a", STRING(i13_2_1, "+hh:mma")).
      
      // prefix '+hh:mm' with suffix 'A', hour = 13
      Assert:Equals("+02:01A", STRING(i13_2_1, "+hh:mmA")).
      
      // prefix '+hh:mm' with suffix 'aa', hour = 13
      Assert:Equals("+02:01aa", STRING(i13_2_1, "+hh:mmaa")).
      
      // prefix 'hh:mm:ss' with no suffix, hour = 13
      Assert:Equals("13:02:01", STRING(i13_2_1, "hh:mm:ss")).
      
      // prefix 'hh:mm:ss' with suffix 'a', hour = 13
      Assert:Equals(" 1:02:01p", STRING(i13_2_1, "hh:mm:ssa")).
      
      // prefix 'hh:mm:ss' with suffix 'A', hour = 13
      Assert:Equals(" 1:02:01P", STRING(i13_2_1, "hh:mm:ssA")).
      
      // prefix 'hh:mm:ss' with suffix 'aa', hour = 13
      Assert:Equals(" 1:02:01pa", STRING(i13_2_1, "hh:mm:ssaa")).
      
      // prefix 'hh:mm' with no suffix, hour = 13
      Assert:Equals("13:02", STRING(i13_2_1, "hh:mm")).
      
      // prefix 'hh:mm' with suffix 'a', hour = 13
      Assert:Equals(" 1:02p", STRING(i13_2_1, "hh:mma")).
      
      // prefix 'hh:mm' with suffix 'A', hour = 13
      Assert:Equals(" 1:02P", STRING(i13_2_1, "hh:mmA")).
      
      // prefix 'hh:mm' with suffix 'aa', hour = 13
      Assert:Equals(" 1:02pa", STRING(i13_2_1, "hh:mmaa")).
      
      // prefix '+hh:mm' with suffix 'qwe', hour = 13
      Assert:Equals("+02:01qwe", STRING(i13_2_1, "+hh:mmqwe")).
      
      // prefix '+hh:mm' with suffix 'qweA', hour = 13
      Assert:Equals("+02:01qweA", STRING(i13_2_1, "+hh:mmqweA")).
      
      // prefix '+hh:mm' with suffix 'abc', hour = 13
      Assert:Equals("+02:01abc", STRING(i13_2_1, "+hh:mmabc")).
      
      // prefix '+hh:mm' with suffix 'abcA', hour = 13
      Assert:Equals("+02:01abcA", STRING(i13_2_1, "+hh:mmabcA")).
      
      // prefix 'hh:mm' with suffix 'qwe', hour = 13
      Assert:Equals("13:02qwe", STRING(i13_2_1, "hh:mmqwe")).
      
      // prefix 'hh:mm' with suffix 'qweA', hour = 13
      Assert:Equals(" 1:02qweP", STRING(i13_2_1, "hh:mmqweA")).
      
      // prefix 'hh:mm' with suffix 'abc', hour = 13
      Assert:Equals(" 1:02pbc", STRING(i13_2_1, "hh:mmabc")).
      
      // prefix 'hh:mm' with suffix 'abcA', hour = 13
      Assert:Equals(" 1:02pbcA", STRING(i13_2_1, "hh:mmabcA")).

   END METHOD. 
   
   /**
    * decimal value cannot be formatted with legacy time formats.
    */
   @Test.
   METHOD PUBLIC VOID TestFormattingDecimalWithTimeFormatErrors():
      DEFINE VARIABLE rc AS CHARACTER NO-UNDO.
      rc = STRING(1.0, "+hh:ss") NO-ERROR.
      Assert:Equals(22, ERROR-STATUS:GET-NUMBER(1)).
   END METHOD. 
END CLASS.
