// Example program demonstrating issue #9855
ROUTINE-LEVEL ON ERROR UNDO, THROW.

USING OpenEdge.Core.Assert FROM PROPATH.

CLASS unittests.TestDateFormatAdjustment:

    DEFINE VARIABLE d AS DATE NO-UNDO.
    DEFINE FRAME myFrame d WITH NO-LABELS NO-BOX.

    DEFINE VARIABLE varFormats AS CHARACTER EXTENT NO-UNDO INITIAL [ {all-date-formats.i} ].

    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "mdy"
     */
    @Test.
    METHOD PUBLIC VOID testMdyFormatAdjustment():
        SESSION:DATE-FORMAT = "mdy".
        DEFINE VARIABLE expected AS CHARACTER EXTENT NO-UNDO INITIAL [ {date_format_assignment_adjusted_mdy.i} ].
        testFormatAdjustment(expected).
    END METHOD.
    
    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "dmy"
     */
    @Test.
    METHOD PUBLIC VOID testDmyFormatAdjustment():
        SESSION:DATE-FORMAT = "dmy".
        DEFINE VARIABLE expected AS CHARACTER EXTENT NO-UNDO INITIAL [ {date_format_assignment_adjusted_dmy.i} ].
        testFormatAdjustment(expected).
    END METHOD.

    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "ymd"
     */
    @Test.
    METHOD PUBLIC VOID testYmdFormatAdjustment():
        SESSION:DATE-FORMAT = "ymd".
        DEFINE VARIABLE expected AS CHARACTER EXTENT NO-UNDO INITIAL [ {date_format_assignment_adjusted_ymd.i} ].
        testFormatAdjustment(expected).
    END METHOD.

    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "myd"
     */
    @Test.
    METHOD PUBLIC VOID testMydFormatAdjustment():
        SESSION:DATE-FORMAT = "myd".
        DEFINE VARIABLE expected AS CHARACTER EXTENT NO-UNDO INITIAL [ {date_format_assignment_adjusted_myd.i} ].
        testFormatAdjustment(expected).
    END METHOD.

    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "dym"
     */
    @Test.
    METHOD PUBLIC VOID testDymFormatAdjustment():
        SESSION:DATE-FORMAT = "dym".
        DEFINE VARIABLE expected AS CHARACTER EXTENT NO-UNDO INITIAL [ {date_format_assignment_adjusted_dym.i} ].
        testFormatAdjustment(expected).
    END METHOD.

    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "ydm"
     */
    @Test.
    METHOD PUBLIC VOID testYdmFormatAdjustment():
    SESSION:DATE-FORMAT = "ydm".
        DEFINE VARIABLE expected AS CHARACTER EXTENT NO-UNDO INITIAL [ {date_format_assignment_adjusted_ydm.i} ].
        testFormatAdjustment(expected).
    END METHOD.

    /**
     * Tests FORMAT adjustments for given SESSION:DATE-FORMAT
     */
    METHOD PRIVATE VOID testFormatAdjustment(INPUT expected AS CHARACTER EXTENT):
        DEFINE VARIABLE i AS INTEGER NO-UNDO.
        DO i = 1 TO EXTENT(varFormats):
            d:FORMAT IN FRAME myFrame = varFormats[i].
            Assert:equals(expected[i], d:FORMAT IN FRAME myFrame).
        END.
    END METHOD.

END CLASS.