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

USING OpenEdge.Core.Assert FROM PROPATH.

CLASS unittests.TestDateFormatTransition:

    /* DATE variable to test */
    DEFINE PRIVATE VARIABLE d AS DATE NO-UNDO.

    /* Frame for DATE variable */
    DEFINE FRAME myFrame
        d
        WITH NO-LABELS NO-BOX DOWN.

    /**
     * Tests the transition of a DATE variable's FORMAT from an initial value to a new value,
     * verifying that the transitioned FORMAT matches the expected value based on SESSION:DATE-FORMAT.
     *
     * @param sessionFormat
     *        The SESSION:DATE-FORMAT value to set (e.g., "mdy", "dmy").
     * @param initialFormat
     *        The initial FORMAT value to set.
     * @param newFormat
     *        The new FORMAT value to transition to.
     * @param expectedFormat
     *        The expected FORMAT after transition.
     */
    METHOD PRIVATE VOID testFormatTransition(INPUT sessionFormat AS CHARACTER,
                                             INPUT initialFormat AS CHARACTER,
                                             INPUT newFormat AS CHARACTER,
                                             INPUT expectedFormat AS CHARACTER):
        SESSION:DATE-FORMAT = sessionFormat.

        /* Set and assert initial FORMAT is unchanged */
        d:FORMAT IN FRAME myFrame = initialFormat.
        Assert:equals(initialFormat, d:FORMAT IN FRAME myFrame).

        /* Transition to new FORMAT and assert result */
        d:FORMAT IN FRAME myFrame = newFormat.
        Assert:equals(expectedFormat, d:FORMAT IN FRAME myFrame).
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "mdy"
     */
    @Test.
    METHOD PUBLIC VOID testMdyFrom1To2():
        testFormatTransition("mdy", "99/99.9999", "9999-99.99", "99-99.9999").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "mdy"
     */
    @Test.
    METHOD PUBLIC VOID testMdyFrom2To3():
        testFormatTransition("mdy", "99-99.9999", "9999-9999.9999", "9999-9999.9999").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "mdy"
     */
    @Test.
    METHOD PUBLIC VOID testMdyFrom3To1():
        testFormatTransition("mdy", "9999-9999.9999", "99/99.9999", "99/99.9999").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "dmy"
     */
    @Test.
    METHOD PUBLIC VOID testDmyFrom1To2():
        testFormatTransition("dmy", "99/99.9999", "9999-99.99", "99.99-9999").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "dmy"
     */
    @Test.
    METHOD PUBLIC VOID testDmyFrom2To3():
        testFormatTransition("dmy", "99.99-9999", "9999-9999.9999", "9999-9999.9999").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "dmy"
     */
    @Test.
    METHOD PUBLIC VOID testDmyFrom3To1():
        testFormatTransition("dmy", "9999-9999.9999", "99/99.9999", "99/99.9999").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "ymd"
     */
    @Test.
    METHOD PUBLIC VOID testYmdFrom1To2():
        testFormatTransition("ymd", "9999.99/99", "9999-99.99", "9999-99.99").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "ymd"
     */
    @Test.
    METHOD PUBLIC VOID testYmdFrom2To3():
        testFormatTransition("ymd", "9999-99.99", "9999-9999.9999", "9999-9999.9999").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "ymd"
     */
    @Test.
    METHOD PUBLIC VOID testYmdFrom3To1():
        testFormatTransition("ymd", "9999-9999.9999", "99/99.9999", "9999.99/99").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "myd"
     */
    @Test.
    METHOD PUBLIC VOID testMydFrom1To2():
        testFormatTransition("myd", "99/9999.99", "9999-99.99", "99-9999.99").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "myd"
     */
    @Test.
    METHOD PUBLIC VOID testMydFrom2To3():
        testFormatTransition("myd", "99-9999.99", "9999-9999.9999", "9999-9999.9999").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "myd"
     */
    @Test.
    METHOD PUBLIC VOID testMydFrom3To1():
        testFormatTransition("myd", "9999-9999.9999", "99/99.9999", "99/9999.99").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "dym"
     */
    @Test.
    METHOD PUBLIC VOID testDymFrom1To2():
        testFormatTransition("dym", "99.9999.99", "9999-99.99", "99.9999.99").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "dym"
     */
    @Test.
    METHOD PUBLIC VOID testDymFrom2To3():
        testFormatTransition("dym", "99.9999.99", "9999-9999.9999", "9999-9999.9999").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "dym"
     */
    @Test.
    METHOD PUBLIC VOID testDymFrom3To1():
        testFormatTransition("dym", "9999-9999.9999", "99/99.9999", "99.9999.99").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "ydm"
     */
    @Test.
    METHOD PUBLIC VOID testYdmFrom1To2():
        testFormatTransition("ydm", "9999.99.99", "9999-99.99", "9999-99.99").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "ydm"
     */
    @Test.
    METHOD PUBLIC VOID testYdmFrom2To3():
        testFormatTransition("ydm", "9999-99.99", "9999-9999.9999", "9999-9999.9999").
    END METHOD.

    /**
     * Test transitions for SESSION:DATE-FORMAT = "ydm"
     */
    @Test.
    METHOD PUBLIC VOID testYdmFrom3To1():
        testFormatTransition("ydm", "9999-9999.9999", "99/99.9999", "9999.99.99").
    END METHOD.

END CLASS.