// 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 72 NO-UNDO INITIAL [
        "99.99.99", "99.99/99", "99.99-99", "99/99.99", "99/99/99", "99/99-99", "99-99.99", "99-99/99", "99-99-99",
        "99.99.9999", "99.99/9999", "99.99-9999", "99/99.9999", "99/99/9999", "99/99-9999", "99-99.9999", "99-99/9999", "99-99-9999",
        "99.9999.99", "99.9999/99", "99.9999-99", "99/9999.99", "99/9999/99", "99/9999-99", "99-9999.99", "99-9999/99", "99-9999-99",
        "99.9999.9999", "99.9999/9999", "99.9999-9999", "99/9999.9999", "99/9999/9999", "99/9999-9999", "99-9999.9999", "99-9999/9999", "99-9999-9999",
        "9999.99.99", "9999.99/99", "9999.99-99", "9999/99.99", "9999/99/99", "9999/99-99", "9999-99.99", "9999-99/99", "9999-99-99",
        "9999.99.9999", "9999.99/9999", "9999.99-9999", "9999/99.9999", "9999/99/9999", "9999/99-9999", "9999-99.9999", "9999-99/9999", "9999-99-9999",
        "9999.9999.99", "9999.9999/99", "9999.9999-99", "9999/9999.99", "9999/9999/99", "9999/9999-99", "9999-9999.99", "9999-9999/99", "9999-9999-99",
        "9999.9999.9999", "9999.9999/9999", "9999.9999-9999", "9999/9999.9999", "9999/9999/9999", "9999/9999-9999", "9999-9999.9999", "9999-9999/9999", "9999-9999-9999"
    ].

    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "mdy"
     */
    @Test.
    METHOD PUBLIC VOID testMdyFormatAdjustment():
        SESSION:DATE-FORMAT = "mdy".
        DEFINE VARIABLE expected AS CHARACTER EXTENT 72 NO-UNDO INITIAL [
            "99.99.99", "99.99/99", "99.99-99", "99/99.99", "99/99/99", "99/99-99", "99-99.99", "99-99/99", "99-99-99",
            "99.99.9999", "99.99/9999", "99.99-9999", "99/99.9999", "99/99/9999", "99/99-9999", "99-99.9999", "99-99/9999", "99-99-9999",
            "99.99.9999", "99.99/9999", "99.99-9999", "99/99.9999", "99/99/9999", "99/99-9999", "99-99.9999", "99-99/9999", "99-99-9999",
            "99.9999.9999", "99.9999/9999", "99.9999-9999", "99/9999.9999", "99/9999/9999", "99/9999-9999", "99-9999.9999", "99-9999/9999", "99-9999-9999",
            "99.99.9999", "99.99/9999", "99.99-9999", "99/99.9999", "99/99/9999", "99/99-9999", "99-99.9999", "99-99/9999", "99-99-9999",
            "9999.99.9999", "9999.99/9999", "9999.99-9999", "9999/99.9999", "9999/99/9999", "9999/99-9999", "9999-99.9999", "9999-99/9999", "9999-99-9999",
            "9999.9999.99", "9999.9999/99", "9999.9999-99", "9999/9999.99", "9999/9999/99", "9999/9999-99", "9999-9999.99", "9999-9999/99", "9999-9999-99",
            "9999.9999.9999", "9999.9999/9999", "9999.9999-9999", "9999/9999.9999", "9999/9999/9999", "9999/9999-9999", "9999-9999.9999", "9999-9999/9999", "9999-9999-9999"
        ].
        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.

    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "dmy"
     */
    @Test.
    METHOD PUBLIC VOID testDmyFormatAdjustment():
        SESSION:DATE-FORMAT = "dmy".
        DEFINE VARIABLE expected AS CHARACTER EXTENT 72 NO-UNDO INITIAL [
            "99.99.99", "99.99/99", "99.99-99", "99/99.99", "99/99/99", "99/99-99", "99-99.99", "99-99/99", "99-99-99",
            "99.99.9999", "99.99/9999", "99.99-9999", "99/99.9999", "99/99/9999", "99/99-9999", "99-99.9999", "99-99/9999", "99-99-9999",
            "99.99.9999", "99/99.9999", "99-99.9999", "99.99/9999", "99/99/9999", "99-99/9999", "99.99-9999", "99/99-9999", "99-99-9999",
            "99.9999.9999", "99.9999/9999", "99.9999-9999", "99/9999.9999", "99/9999/9999", "99/9999-9999", "99-9999.9999", "99-9999/9999", "99-9999-9999",
            "99.99.9999", "99/99.9999", "99-99.9999", "99.99/9999", "99/99/9999", "99-99/9999", "99.99-9999", "99/99-9999", "99-99-9999",
            "9999.99.9999", "9999.99/9999", "9999.99-9999", "9999/99.9999", "9999/99/9999", "9999/99-9999", "9999-99.9999", "9999-99/9999", "9999-99-9999",
            "9999.9999.99", "9999.9999/99", "9999.9999-99", "9999/9999.99", "9999/9999/99", "9999/9999-99", "9999-9999.99", "9999-9999/99", "9999-9999-99",
            "9999.9999.9999", "9999.9999/9999", "9999.9999-9999", "9999/9999.9999", "9999/9999/9999", "9999/9999-9999", "9999-9999.9999", "9999-9999/9999", "9999-9999-9999"
        ].
        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.

    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "ymd"
     */
    @Test.
    METHOD PUBLIC VOID testYmdFormatAdjustment():
        SESSION:DATE-FORMAT = "ymd".
        DEFINE VARIABLE expected AS CHARACTER EXTENT 72 NO-UNDO INITIAL [
            "99.99.99", "99.99/99", "99.99-99", "99/99.99", "99/99/99", "99/99-99", "99-99.99", "99-99/99", "99-99-99",
            "9999.99.99", "9999/99.99", "9999-99.99", "9999.99/99", "9999/99/99", "9999-99/99", "9999.99-99", "9999/99-99", "9999-99-99",
            "9999.99.99", "9999/99.99", "9999-99.99", "9999.99/99", "9999/99/99", "9999-99/99", "9999.99-99", "9999/99-99", "9999-99-99",
            "99.9999.9999", "99.9999/9999", "99.9999-9999", "99/9999.9999", "99/9999/9999", "99/9999-9999", "99-9999.9999", "99-9999/9999", "99-9999-9999",
            "9999.99.99", "9999.99/99", "9999.99-99", "9999/99.99", "9999/99/99", "9999/99-99", "9999-99.99", "9999-99/99", "9999-99-99",
            "9999.99.9999", "9999.99/9999", "9999.99-9999", "9999/99.9999", "9999/99/9999", "9999/99-9999", "9999-99.9999", "9999-99/9999", "9999-99-9999",
            "9999.9999.99", "9999.9999/99", "9999.9999-99", "9999/9999.99", "9999/9999/99", "9999/9999-99", "9999-9999.99", "9999-9999/99", "9999-9999-99",
            "9999.9999.9999", "9999.9999/9999", "9999.9999-9999", "9999/9999.9999", "9999/9999/9999", "9999/9999-9999", "9999-9999.9999", "9999-9999/9999", "9999-9999-9999"
        ].
        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.

    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "myd"
     */
    @Test.
    METHOD PUBLIC VOID testMydFormatAdjustment():
        SESSION:DATE-FORMAT = "myd".
        DEFINE VARIABLE expected AS CHARACTER EXTENT 72 NO-UNDO INITIAL [
            "99.99.99", "99.99/99", "99.99-99", "99/99.99", "99/99/99", "99/99-99", "99-99.99", "99-99/99", "99-99-99",
            "99.9999.99", "99.9999/99", "99.9999-99", "99/9999.99", "99/9999/99", "99/9999-99", "99-9999.99", "99-9999/99", "99-9999-99",
            "99.9999.99", "99.9999/99", "99.9999-99", "99/9999.99", "99/9999/99", "99/9999-99", "99-9999.99", "99-9999/99", "99-9999-99",
            "99.9999.9999", "99.9999/9999", "99.9999-9999", "99/9999.9999", "99/9999/9999", "99/9999-9999", "99-9999.9999", "99-9999/9999", "99-9999-9999",
            "99.9999.99", "99.9999/99", "99.9999-99", "99/9999.99", "99/9999/99", "99/9999-99", "99-9999.99", "99-9999/99", "99-9999-99",
            "9999.99.9999", "9999.99/9999", "9999.99-9999", "9999/99.9999", "9999/99/9999", "9999/99-9999", "9999-99.9999", "9999-99/9999", "9999-99-9999",
            "9999.9999.99", "9999.9999/99", "9999.9999-99", "9999/9999.99", "9999/9999/99", "9999/9999-99", "9999-9999.99", "9999-9999/99", "9999-9999-99",
            "9999.9999.9999", "9999.9999/9999", "9999.9999-9999", "9999/9999.9999", "9999/9999/9999", "9999/9999-9999", "9999-9999.9999", "9999-9999/9999", "9999-9999-9999"
        ].
        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.

    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "dym"
     */
    @Test.
    METHOD PUBLIC VOID testDymFormatAdjustment():
        SESSION:DATE-FORMAT = "dym".
        DEFINE VARIABLE expected AS CHARACTER EXTENT 72 NO-UNDO INITIAL [
            "99.99.99", "99.99/99", "99.99-99", "99/99.99", "99/99/99", "99/99-99", "99-99.99", "99-99/99", "99-99-99",
            "99.9999.99", "99/9999/99", "99-9999-99", "99.9999.99", "99/9999/99", "99-9999-99", "99.9999.99", "99/9999/99", "99-9999-99",
            "99.9999.99", "99.9999/99", "99.9999-99", "99/9999.99", "99/9999/99", "99/9999-99", "99-9999.99", "99-9999/99", "99-9999-99",
            "99.9999.9999", "99.9999/9999", "99.9999-9999", "99/9999.9999", "99/9999/9999", "99/9999-9999", "99-9999.9999", "99-9999/9999", "99-9999-9999",
            "99.9999.99", "99/9999/99", "99-9999-99", "99.9999.99", "99/9999/99", "99-9999-99", "99.9999.99", "99/9999/99", "99-9999-99",
            "9999.99.9999", "9999.99/9999", "9999.99-9999", "9999/99.9999", "9999/99/9999", "9999/99-9999", "9999-99.9999", "9999-99/9999", "9999-99-9999",
            "9999.9999.99", "9999.9999/99", "9999.9999-99", "9999/9999.99", "9999/9999/99", "9999/9999-99", "9999-9999.99", "9999-9999/99", "9999-9999-99",
            "9999.9999.9999", "9999.9999/9999", "9999.9999-9999", "9999/9999.9999", "9999/9999/9999", "9999/9999-9999", "9999-9999.9999", "9999-9999/9999", "9999-9999-9999"
        ].
        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.

    /**
     * Tests FORMAT adjustments for SESSION:DATE-FORMAT = "ydm"
     */
    @Test.
    METHOD PUBLIC VOID testYdmFormatAdjustment():
        SESSION:DATE-FORMAT = "ydm".
        DEFINE VARIABLE expected AS CHARACTER EXTENT 72 NO-UNDO INITIAL [
            "99.99.99", "99.99/99", "99.99-99", "99/99.99", "99/99/99", "99/99-99", "99-99.99", "99-99/99", "99-99-99",
            "9999.99.99", "9999/99/99", "9999-99-99", "9999.99.99", "9999/99/99", "9999-99-99", "9999.99.99", "9999/99/99", "9999-99-99",
            "9999.99.99", "9999/99/99", "9999-99-99", "9999.99.99", "9999/99/99", "9999-99-99", "9999.99.99", "9999/99/99", "9999-99-99",
            "99.9999.9999", "99.9999/9999", "99.9999-9999", "99/9999.9999", "99/9999/9999", "99/9999-9999", "99-9999.9999", "99-9999/9999", "99-9999-9999",
            "9999.99.99", "9999.99/99", "9999.99-99", "9999/99.99", "9999/99/99", "9999/99-99", "9999-99.99", "9999-99/99", "9999-99-99",
            "9999.99.9999", "9999.99/9999", "9999.99-9999", "9999/99.9999", "9999/99/9999", "9999/99-9999", "9999-99.9999", "9999-99/9999", "9999-99-9999",
            "9999.9999.99", "9999.9999/99", "9999.9999-99", "9999/9999.99", "9999/9999/99", "9999/9999-99", "9999-9999.99", "9999-9999/99", "9999-9999-99",
            "9999.9999.9999", "9999.9999/9999", "9999.9999-9999", "9999/9999.9999", "9999/9999/9999", "9999/9999-9999", "9999-9999.9999", "9999-9999/9999", "9999-9999-9999"
        ].
        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.