/**
Program Purpose:
- To determine how OpenEdge modifies the FORMAT attribute of a DATE variable when set, depending on the SESSION:DATE-FORMAT value.

Program Requirements:
- Define a DATE variable named 'd' with no initial value.
- Iterate over a list of valid SESSION:DATE-FORMAT values: mdy, dmy, ymd, myd, dym, ydm.
- For each SESSION:DATE-FORMAT value:
  - Set SESSION:DATE-FORMAT to the current value.
  - Set the format of 'd' to each of: 99/99.9999, 9999-99.99, 9999-9999.9999.
  - Display the current SESSION:DATE-FORMAT, the format just set, and the applied FORMAT of 'd', ensuring the character format length is large enough to fit the result line.
- Use a frame to contain 'd' for UI operations, without specifying a default format in the frame, and ensure the frame is wide enough to fit the output lines.
- Adjust the DEFAULT-WINDOW size to be wide enough to accommodate the frame and output lines.
- Save
*/

/* Adjust the DEFAULT-WINDOW size */
DEFAULT-WINDOW:WIDTH-CHARS = 65.
DEFAULT-WINDOW:HEIGHT-CHARS = 15.

/* Define the DATE variable without an initial value */
DEFINE VARIABLE d AS DATE NO-UNDO.

/* Define a frame for the variable, wide enough for output */
DEFINE FRAME myFrame
   d
   WITH NO-LABELS NO-BOX DOWN SIZE 62 BY 10.

/* List of valid SESSION:DATE-FORMAT values */
DEFINE VARIABLE dateFormats AS CHARACTER NO-UNDO EXTENT 6
   INITIAL ["mdy", "dmy", "ymd", "myd", "dym", "ydm"].

/* List of date variable formats to test */
DEFINE VARIABLE varFormats AS CHARACTER NO-UNDO EXTENT 576
   INITIAL [ {all-date-formats.i} ].

/* Loop variables */
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE j AS INTEGER NO-UNDO.

/* Iterate over SESSION:DATE-FORMAT values */
DO i = 1 TO EXTENT(dateFormats):
    /* Set SESSION:DATE-FORMAT */
    SESSION:DATE-FORMAT = dateFormats[i].
    
    /* Redirect output to a file */
    OUTPUT TO VALUE( "date_format_assignment_adjusted_" + dateFormats[i] + ".i" ).
    
    /* Iterate over variable formats */
    REPEAT j = 1 TO EXTENT(varFormats):
        /* Apply the format to the date variable within the frame */
        d:FORMAT IN FRAME myFrame = varFormats[j].

        /* Print the format just set and the FORMAT attribute with newline */
        PUT UNFORMATTED '"' + ( d:FORMAT IN FRAME myFrame ) + '",~n'.
        // DISPLAY
        //     '"' + ( d:FORMAT IN FRAME myFrame ) + '",' FORMAT "x(20)"
        //     .
    END.
    
    OUTPUT CLOSE.
END.
