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

ROUTINE-LEVEL ON ERROR UNDO, THROW.

CLASS unittests.TestIntegerFormattedAsTime:
   
   /**
    * Test legacy time formats for integer values
    */
   @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.
      
      DEFINE VARIABLE i13_3 AS INTEGER NO-UNDO.
      i13_3 = 13 * 60 + 3.

      DEFINE VARIABLE i13_2_3 AS INTEGER NO-UNDO.
      i13_2_3 = 13 * 60 * 60 + 2 * 60 + 3.

      // prefix '+hh:mm' with no suffix, hour = 3
      test(i3_2_1, "+hh:mm", "+02:01").
      
      // prefix '+hh:mm' with no suffix, hour = 24
      test(i24_2_1, "+hh:mm", "+02:01").
      
      // prefix '+hh:mm' with suffix 'a', hour = 3
      test(i3_2_1, "+hh:mma", "+02:01a").
      
      // prefix '+hh:mm' with suffix 'a', hour = 24
      test(i24_2_1, "+hh:mma", "+02:01a").
      
      // prefix '+hh:mm' with suffix 'A', hour = 3
      test(i3_2_1, "+hh:mmA", "+02:01A").
      
      // prefix '+hh:mm' with suffix 'A', hour = 24
      test(i24_2_1, "+hh:mmA", "+02:01A").
      
      // prefix '+hh:mm' with suffix 'aa', hour = 3
      test(i3_2_1, "+hh:mmaa", "+02:01aa").
      
      // prefix '+hh:mm' with suffix 'aa', hour = 24
      test(i24_2_1, "+hh:mmaa", "+02:01aa").
      
      // prefix 'hh:mm:ss' with no suffix, hour = 3
      test(i3_2_1, "hh:mm:ss", "03:02:01").
      
      // prefix 'hh:mm:ss' with no suffix, hour = 24
      test(i24_2_1, "hh:mm:ss", "00:02:01").
      
      // prefix 'hh:mm:ss' with suffix 'a', hour = 3
      test(i3_2_1, "hh:mm:ssa", " 3:02:01a").
      
      // prefix 'hh:mm:ss' with suffix 'a', hour = 24
      test(i24_2_1, "hh:mm:ssa", "12:02:01a").
      
      // prefix 'hh:mm:ss' with suffix 'A', hour = 3
      test(i3_2_1, "hh:mm:ssA", " 3:02:01A").
      
      // prefix 'hh:mm:ss' with suffix 'A', hour = 24
      test(i24_2_1, "hh:mm:ssA", "12:02:01A").
      
      // prefix 'hh:mm:ss' with suffix 'aa', hour = 3
      test(i3_2_1, "hh:mm:ssaa", " 3:02:01aa").
      
      // prefix 'hh:mm:ss' with suffix 'aa', hour = 24
      test(i24_2_1, "hh:mm:ssaa", "12:02:01aa").
      
      // prefix 'hh:mm' with no suffix, hour = 3
      test(i3_2_1, "hh:mm", "03:02").
      
      // prefix 'hh:mm' with no suffix, hour = 24
      test(i24_2_1, "hh:mm", "00:02").
      
      // prefix 'hh:mm' with suffix 'a', hour = 3
      test(i3_2_1, "hh:mma", " 3:02a").
      
      // prefix 'hh:mm' with suffix 'a', hour = 24
      test(i24_2_1, "hh:mma", "12:02a").
      
      // prefix 'hh:mm' with suffix 'A', hour = 3
      test(i3_2_1, "hh:mmA", " 3:02A").
      
      // prefix 'hh:mm' with suffix 'A', hour = 24
      test(i24_2_1, "hh:mmA", "12:02A").
      
      // prefix 'hh:mm' with suffix 'aa', hour = 3
      test(i3_2_1, "hh:mmaa", " 3:02aa").
      
      // prefix 'hh:mm' with suffix 'aa', hour = 24
      test(i24_2_1, "hh:mmaa", "12:02aa").
      
      // prefix '+hh:mm' with suffix 'qwe', hour = 3
      test(i3_2_1, "+hh:mmqwe", "+02:01qwe").
      
      // prefix '+hh:mm' with suffix 'qwe', hour = 24
      test(i24_2_1, "+hh:mmqwe", "+02:01qwe").
      
      // prefix '+hh:mm' with suffix 'qweA', hour = 3
      test(i3_2_1, "+hh:mmqweA", "+02:01qweA").
      
      // prefix '+hh:mm' with suffix 'qweA', hour = 24
      test(i24_2_1, "+hh:mmqweA", "+02:01qweA").
      
      // prefix '+hh:mm' with suffix 'abc', hour = 3
      test(i3_2_1, "+hh:mmabc", "+02:01abc").
      
      // prefix '+hh:mm' with suffix 'abc', hour = 24
      test(i24_2_1, "+hh:mmabc", "+02:01abc").
      
      // prefix '+hh:mm' with suffix 'abcA', hour = 3
      test(i3_2_1, "+hh:mmabcA", "+02:01abcA").
      
      // prefix '+hh:mm' with suffix 'abcA', hour = 24
      test(i24_2_1, "+hh:mmabcA", "+02:01abcA").
      
      // prefix 'hh:mm' with suffix 'qwe', hour = 3
      test(i3_2_1, "hh:mmqwe", "03:02qwe").
      
      // prefix 'hh:mm' with suffix 'qwe', hour = 24
      test(i24_2_1, "hh:mmqwe", "00:02qwe").
      
      // prefix 'hh:mm' with suffix 'qweA', hour = 3
      test(i3_2_1, "hh:mmqweA", " 3:02qweA").
      
      // prefix 'hh:mm' with suffix 'qweA', hour = 24
      test(i24_2_1, "hh:mmqweA", "12:02qweA").
      
      // prefix 'hh:mm' with suffix 'abc', hour = 3
      test(i3_2_1, "hh:mmabc", " 3:02abc").
      
      // prefix 'hh:mm' with suffix 'abc', hour = 24
      test(i24_2_1, "hh:mmabc", "12:02abc").
      
      // prefix 'hh:mm' with suffix 'abcA', hour = 3
      test(i3_2_1, "hh:mmabcA", " 3:02abcA").
      
      // prefix 'hh:mm' with suffix 'abcA', hour = 24
      test(i24_2_1, "hh:mmabcA", "12:02abcA").
      
      // prefix '+hh:mm' with no suffix, hour = 13
      test(i13_2_1, "+hh:mm", "+02:01").
      
      // prefix '+hh:mm' with suffix 'a', hour = 13
      test(i13_2_1, "+hh:mma", "+02:01a").
      
      // prefix '+hh:mm' with suffix 'A', hour = 13
      test(i13_2_1, "+hh:mmA", "+02:01A").
      
      // prefix '+hh:mm' with suffix 'aa', hour = 13
      test(i13_2_1, "+hh:mmaa", "+02:01aa").
      
      // prefix 'hh:mm:ss' with no suffix, hour = 13
      test(i13_2_1, "hh:mm:ss", "13:02:01").
      
      // prefix 'hh:mm:ss' with suffix 'a', hour = 13, expecting 1 PM format
      test(i13_2_1, "hh:mm:ssa", " 1:02:01p").
      
      // prefix 'hh:mm:ss' with suffix 'A', hour = 13, expecting 1 PM format
      test(i13_2_1, "hh:mm:ssA", " 1:02:01P").
      
      // prefix 'hh:mm:ss' with suffix 'aa', hour = 13, expecting 1 PM format
      test(i13_2_1, "hh:mm:ssaa", " 1:02:01pa").
      
      // prefix 'hh:mm' with no suffix, hour = 13
      test(i13_2_1, "hh:mm", "13:02").
      
      // prefix 'hh:mm' with suffix 'a', hour = 13, expecting 1 PM format
      test(i13_2_1, "hh:mma", " 1:02p").
      
      // prefix 'hh:mm' with suffix 'A', hour = 13, expecting 1 PM format
      test(i13_2_1, "hh:mmA", " 1:02P").
      
      // prefix 'hh:mm' with suffix 'aa', hour = 13, expecting 1 PM format
      test(i13_2_1, "hh:mmaa", " 1:02pa").
      
      // prefix '+hh:mm' with suffix 'qwe', hour = 13
      test(i13_2_1, "+hh:mmqwe", "+02:01qwe").
      
      // prefix '+hh:mm' with suffix 'qweA', hour = 13
      test(i13_2_1, "+hh:mmqweA", "+02:01qweA").
      
      // prefix '+hh:mm' with suffix 'abc', hour = 13
      test(i13_2_1, "+hh:mmabc", "+02:01abc").
      
      // prefix '+hh:mm' with suffix 'abcA', hour = 13
      test(i13_2_1, "+hh:mmabcA", "+02:01abcA").
      
      // prefix 'hh:mm' with suffix 'qwe', hour = 13
      test(i13_2_1, "hh:mmqwe", "13:02qwe").
      
      // prefix 'hh:mm' with suffix 'qweA', hour = 13, expecting 1 PM format
      test(i13_2_1, "hh:mmqweA", " 1:02qweP").
      
      // prefix 'hh:mm' with suffix 'abc', hour = 13, expecting 1 PM format
      test(i13_2_1, "hh:mmabc", " 1:02pbc").
      
      // prefix 'hh:mm' with suffix 'abcA', hour = 13, expecting 1 PM format
      test(i13_2_1, "hh:mmabcA", " 1:02pbcA").

      // prefix '+hh:mm' with no suffix
      test(1, "+hh:mm", "+00:01").
      
      // prefix '+hh:mm' with suffix 'ee'
      test(1, "+hh:mmee", "+00:01ee").
      
      // prefix '+hh:mm' with suffix ':ss'
      test(1, "+hh:mm:ss", "+00:01:ss").
      
      // prefix 'hh:mm' with no suffix
      test(1, "hh:mm", "00:00").
      
      // prefix 'hh:mm:ss' with no suffix
      test(1, "hh:mm:ss", "00:00:01").
      
      // prefix 'hh:mm:ss' with no suffix, hour = 13, minutes = 2, seconds = 3
      test(i13_2_3, "hh:mm:ss", "13:02:03").
      
      // prefix 'hh:mm:ss' with suffix 'a', hour = 13, minutes = 2, seconds = 3, expecting 1 PM format
      test(i13_2_3, "hh:mm:ssa", " 1:02:03p").
      
      // prefix 'hh:mm:ss' with suffix ' a', hour = 13, minutes = 2, seconds = 3, expecting 1 PM format with space
      test(i13_2_3, "hh:mm:ss a", " 1:02:03 p").
      
      // prefix 'hh:mm:ss' with suffix 'A', hour = 3, minutes = 2, seconds = 1, expecting 3 AM format
      test(3 * 60 * 60 + 2 * 60 + 1, "hh:mm:ssA", " 3:02:01A").
      
      // prefix 'hh:mm:ss' with suffix 'A', hour = 12, minutes = 2, seconds = 1, expecting 12 AM format
      test(0 * 60 * 60 + 2 * 60 + 1, "hh:mm:ssA", "12:02:01A").
      
      // prefix 'hh:mm:ss' with suffix ' A', hour = 24, minutes = 2, seconds = 3, expecting 12 AM format with space
      test(24 * 60 * 60 + 2 * 60 + 3, "hh:mm:ss A", "12:02:03 A").
      
      // prefix '+hh:mm' with no suffix, hour = 1000, minutes = 2, seconds = 3
      test(1000 * 60 * 60 + 2 * 60 + 3, "+hh:mm", "+02:03").
      
      // prefix '+hh:mm' with suffix ':ssA'
      test(1, "+hh:mm:ssA", "+00:01:ssA").
      
      // prefix '+hh:mm' with suffix ':ssA', hour = 13, minutes = 3
      test(i13_3, "+hh:mm:ssA", "+13:03:ssA").
      
      // prefix 'hh:mm' with suffix 'a123'
      test(1, "hh:mma123", "12:00a123").
      
      // prefix 'hh:mm:ss' with suffix ' A', hour = 13, minutes = 2, seconds = 3, expecting 1 PM format with space
      test(i13_2_3, "hh:mm:ss A", " 1:02:03 P").
      
      // prefix 'hh:mm:ss' with suffix ' A', hour = 24, minutes = 2, seconds = 1, expecting 12 AM format with space
      test(24 * 60 * 60 + 2 * 60 + 1, "hh:mm:ss A", "12:02:01 A").
      
      // prefix 'hh:mm:ss' with suffix ' qweAAA', hour = 13, minutes = 2, seconds = 3, expecting 1 PM format
      test(i13_2_3, "hh:mm:ss qweAAA", " 1:02:03 qwePAA").
      
      // prefix 'Hh:mm' with no suffix, formatting 1000 seconds
      test(1000, "Hh:mm", "00:16").
      
      // prefix 'hh:mm:ss' with no suffix, formatting 1000 seconds
      test(1000, "hh:mm:ss", "00:16:40").
      
      // prefix 'hh:mm' with suffix ':ss.sss', formatting 1000 seconds
      test(1000, "hh:mm:ss.sss", "00:16:40.sss").
      
      // prefix 'hh:mm:ss' with no suffix, hour = 1000, minutes = 2, seconds = 3
      test(1000 * 60 * 60 + 2 * 60 + 3, "hh:mm:ss", "16:02:03").
      
      // prefix 'hh:mm' with suffix 'A', formatting 4210 seconds, expecting 1 AM format
      test(4210, "hh:mmA", " 1:10A").
      
      // prefix 'hh:mm:SS' with suffix 'A', formatting 4210 seconds, expecting 1 AM format
      test(4210, "hh:mm:SSA", " 1:10:10A").
      
      // prefix 'hh:mm' with no suffix, formatting 4210 seconds
      test(4210, "hh:mm", "01:10").
      
      // prefix 'hh:mm:SS' with no suffix, formatting 4210 seconds
      test(4210, "hh:mm:SS", "01:10:10").
      
      // prefix 'hh:mm' with no suffix, hour = 13, minutes = 2
      test(i13_2_3, "hh:mm", "13:02").
      
      // prefix 'hh:mm:SS' with no suffix, hour = 13, minutes = 2, seconds = 3
      test(i13_2_3, "hh:mm:SS", "13:02:03").
      
      // prefix 'hh:mma' with suffix 'p', hour = 13, minutes = 2, expecting 1 PM format
      test(i13_2_3, "hh:mma", " 1:02p").
      
      // prefix 'hh:mm:SSa' with suffix 'a', hour = 13, minutes = 2, seconds = 3, expecting 1 PM format
      test(i13_2_3, "hh:mm:SSa", " 1:02:03p").
      
      // prefix '+hh:mm' with no suffix, hour = 59, minutes = 3
      test(59 * 60 + 3, "+hh:mm", "+59:03").
      
      // prefix '+hh:mm' with no suffix, hour = 60, minutes = 3
      test(60 * 60 + 3, "+hh:mm", "+00:03").
   END METHOD. 
   
   /**
    * Verify that decimal values cannot be formatted with legacy time formats, expecting an error.
    */
   @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.
   
   /**
    * Execute the test, compare result with the expected value.
    */
   METHOD PRIVATE VOID test(INPUT v AS INTEGER, INPUT fmt AS CHARACTER, INPUT expectedResult AS CHARACTER):
      DEFINE VARIABLE rc AS CHARACTER NO-UNDO.
      rc = STRING(v, fmt).
      MESSAGE rc.
      Assert:IsTrue(COMPARE(rc, 'EQ', expectedResult, 'CASE-SENSITIVE')).
      Assert:Equals(LENGTH(rc), LENGTH(expectedResult)).
   END METHOD. 
END CLASS.
