Bug #9855
Date FILL-IN: adjusts DATE format to SESSION:DATE-FORMAT order
100%
Related issues
History
#1 Updated by Vladimir Tsichevski over 1 year ago
When a DATE variable’s FORMAT is set (e.g., d:FORMAT = "99/99.9999"), FWD should modify the format to match SESSION:DATE-FORMAT.
Demo Example Program
The following program demonstrates the issue by testing various FORMAT settings across all valid SESSION:DATE-FORMAT values and comparing the set versus applied formats:
DEFAULT-WINDOW:WIDTH-CHARS = 65.
DEFAULT-WINDOW:HEIGHT-CHARS = 15.
DEFINE VARIABLE d AS DATE NO-UNDO.
DEFINE FRAME myFrame
d
WITH NO-LABELS NO-BOX DOWN SIZE 62 BY 10.
DEFINE VARIABLE dateFormats AS CHARACTER NO-UNDO EXTENT 6
INITIAL ["mdy", "dmy", "ymd", "myd", "dym", "ydm"].
DEFINE VARIABLE varFormats AS CHARACTER NO-UNDO EXTENT 3
INITIAL ["99/99.9999", "9999-99.99", "9999-9999.9999"].
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE j AS INTEGER NO-UNDO.
OUTPUT TO "date_format_test.txt".
REPEAT i = 1 TO EXTENT(dateFormats):
SESSION:DATE-FORMAT = dateFormats[i].
DISPLAY "SESSION:DATE-FORMAT = " + SESSION:DATE-FORMAT FORMAT "x(30)".
REPEAT j = 1 TO EXTENT(varFormats):
d:FORMAT IN FRAME myFrame = varFormats[j].
DISPLAY " Format Set = " + varFormats[j] FORMAT "x(30)"
"Applied Format = " + d:FORMAT IN FRAME myFrame FORMAT "x(35)".
END.
END.
OUTPUT CLOSE.
FWD Program Output
FWD does not adjust d:FORMAT, so the "Applied Format" matches the "Format Set" exactly, regardless of SESSION:DATE-FORMAT:
SESSION:DATE-FORMAT = mdy Format Set = 99/99.9999 Applied Format = 99/99.9999 Format Set = 9999-99.99 Applied Format = 99-99.9999 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999 SESSION:DATE-FORMAT = dmy Format Set = 99/99.9999 Applied Format = 99/99.9999 Format Set = 9999-99.99 Applied Format = 99.99-9999 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999 SESSION:DATE-FORMAT = ymd Format Set = 99/99.9999 Applied Format = 9999.99/99 Format Set = 9999-99.99 Applied Format = 9999-99.99 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999 SESSION:DATE-FORMAT = myd Format Set = 99/99.9999 Applied Format = 99/9999.99 Format Set = 9999-99.99 Applied Format = 99-9999.99 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999 SESSION:DATE-FORMAT = dym Format Set = 99/99.9999 Applied Format = 99.9999.99 Format Set = 9999-99.99 Applied Format = 99.9999.99 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999 SESSION:DATE-FORMAT = ydm Format Set = 99/99.9999 Applied Format = 9999.99.99 Format Set = 9999-99.99 Applied Format = 9999-99.99 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999
Expected Program Output
In OE FORMAT is adjusted to match SESSION:DATE-FORMAT, reordering date components and repositioning separators:
SESSION:DATE-FORMAT = mdy Format Set = 99/99.9999 Applied Format = 99/99.9999 Format Set = 9999-99.99 Applied Format = 99-99.9999 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999 SESSION:DATE-FORMAT = dmy Format Set = 99/99.9999 Applied Format = 99/99.9999 Format Set = 9999-99.99 Applied Format = 99.99-9999 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999 SESSION:DATE-FORMAT = ymd Format Set = 99/99.9999 Applied Format = 9999.99/99 Format Set = 9999-99.99 Applied Format = 9999-99.99 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999 SESSION:DATE-FORMAT = myd Format Set = 99/99.9999 Applied Format = 99/9999.99 Format Set = 9999-99.99 Applied Format = 99-9999.99 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999 SESSION:DATE-FORMAT = dym Format Set = 99/99.9999 Applied Format = 99.9999.99 Format Set = 9999-99.99 Applied Format = 99.9999.99 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999 SESSION:DATE-FORMAT = ydm Format Set = 99/99.9999 Applied Format = 9999.99.99 Format Set = 9999-99.99 Applied Format = 9999-99.99 Format Set = 9999-9999.9999 Applied Format = 9999-9999.9999
#2 Updated by Vladimir Tsichevski over 1 year ago
- File TestDateFormatTransition.cls added
The attached TestDateFormatTransition.cls contains ABLUnit tests.
#3 Updated by Vladimir Tsichevski over 1 year ago
- File TestDateFormatAdjustment.cls added
- % Done changed from 0 to 40
- Status changed from New to WIP
- Assignee set to Vladimir Tsichevski
Attached TestDateFormatAdjustment.cls is an advanced unit test class, which tests all (72) possible date format permutations.
#4 Updated by Vladimir Tsichevski over 1 year ago
Here are the rules for date format adjustments in OE. It determine:
- In which situations format adjustment is required.
- How separators are adjusted when a format change occurs.
In Which Situations Format Adjustment is Required
Format adjustment is required under the following conditions:
- The new format includes separators (i.e., it is not a no-separator format like
999999or99999999). - The new requested format’s component order or lengths do not match the current
SESSION:DATE-FORMATorder, such as:- A short component specification (
99) for the year component, and - A long component specification (
9999) for exactly one other component (month or day).
- A short component specification (
Note: Adjustment depends only on the new format being set and the current SESSION:DATE-FORMAT value. Changing SESSION:DATE-FORMAT does not affect existing formats.
Separators Adjustment Rules
When a new format is applied, separators are modified based on the SESSION:DATE-FORMAT:
- Month in first position (mdy, myd): Preserves separators; the original separators in the new format remain unchanged (e.g.,
-and.stay-and.).
- Month in middle position (dmy, ymd): Separators swap positions (e.g.,
-and.become.and-).
- Month in last position (dym, ydm): The second separator is copied to the first position, replacing the original first separator (e.g.,
-and.become.and.;.and-become-and-).
#5 Updated by Vladimir Tsichevski over 1 year ago
- File DateFormatAdjustmentDisplay.cls added
- File TestDateFormatAdjustmentDeclaration.cls added
Format adjustment can occur also in a date variable declaration, but the adjustment rules differs.
I've created a class to capture the format adjustment for all format permutations (DateFormatAdjustmentDisplay.cls), and, based on the output of this program, the "real" unit test class TestDateFormatAdjustmentDeclaration.cls.
The output analyses proves that:
- The rules for date components adjustments for date variable declaration is the same as the rules for date format assignment.
- The rules for separators adjustments differs:
When a DATE variable is declared with a FORMAT clause, OpenEdge adjusts the separators based on SESSION:DATE-FORMAT as follows:
mdy, dmy, dym (Preserved)
The declared separators remain unchanged.
Examples:
- mdy: 9999.99/99 → 99.99/9999, 9999-99.99 → 99-99.9999
- dmy: 99/9999-99 → 99/99-9999
- dym: 9999-99.99 → 99-9999.99
ymd, myd (Swap)
The first and second separators are exchanged.
Examples:
- ymd: 99.9999/99 → 9999/99.99, 99-99.9999 → 9999.99-99
- myd: 9999.99/99 → 99/9999.99, 99/99-9999 → 99-9999/99
ydm (Copy 2 to 1)
The second separator overwrites the first; the second remains unchanged.
Examples:
- ydm: 99.9999/99 → 9999/99/99, 99-99.9999 → 99.9999.99
#6 Updated by Vladimir Tsichevski over 1 year ago
- % Done changed from 40 to 50
UPD1: Formats are also adjusted when converting a date to a string, such as with STRING(d, "99/99/9999").
UPD2: A format component may consist of any number of nines from 1 to 4, not just 99 or 9999.
Both scenarios require further investigation.
#7 Updated by Vladimir Tsichevski over 1 year ago
- File DisplayDateFormatDeclarationAdjustmentAll.cls added
- File display-date-format-assignment-adjustment.p
added
Vladimir Tsichevski wrote:
UPD2: A format component may consist of any number of nines from 1 to 4, not just
99or9999.
I've created two test programs which capture format adjusting both for date variable declaration and date format attribute assignment for all 576 possible date formats.
I’ve created two data collection programs in OpenEdge ABL.
The first program DisplayDateFormatDeclarationAdjustmentAll.cls collects data on format adjustments for variable declarations, while the second display-date-format-assignment-adjustment.p collects data on format adjustments for format assignments.
The experiment revealed that the data obtained for variable declarations and format assignments are identical.
Converting the data to a string might yield similar results, though this hypothesis requires testing.
#8 Updated by Vladimir Tsichevski over 1 year ago
- File DateFormatAdjuster.java
added - % Done changed from 50 to 60
Attached is a class DateFormatAdjuster.java with the reorderForDateFormatAssignment method, which does format adjustment compatible with both OE date format declaration and date attribute assignment adjustment.
#9 Updated by Vladimir Tsichevski over 1 year ago
- % Done changed from 60 to 70
- File test-date-format-formatting-adjustment.p
added
Attached is a test-date-format-formatting-adjustment.p 4gl procedure, which proves the hypothesis that format adjustments applied during date formatting are identical to those applied in date format declarations and date format assignments in OE for each possible SESSION:DATE-FORMAT setting.
#10 Updated by Vladimir Tsichevski over 1 year ago
Update: Aside from one exception, date format components can consist of any positive number of nines, resulting in an unlimited number of possible formats. Fortunately, this does not appear to affect the adjustment rules. The critical component length for adjustments remains four nines, consistent with existing behavior. The exception, where the leftmost component may be an empty string (e.g., ".99.9999"), is most probably an implementation bug in OE and we will not consider valid in our context.
#11 Updated by Vladimir Tsichevski over 1 year ago
- File TestDateFormatAdjustment.cls added
- File date_format_assignment_adjusted_ymd.i added
- File date_format_assignment_adjusted_ydm.i added
- File date_format_assignment_adjusted_myd.i added
- File date_format_assignment_adjusted_mdy.i added
- File date_format_assignment_adjusted_dym.i added
- File date_format_assignment_adjusted_dmy.i added
Date format adjustment implemented in 9855a rev. 15830. The result passes TestDateFormatAdjustment.cls tests.
#12 Updated by Vladimir Tsichevski over 1 year ago
- % Done changed from 70 to 90
- Status changed from WIP to Review
- reviewer Hynek Cihlar added
Hynek, please, review.
The remaining things:
- I didn’t sort fields and methods in the modified classes to keep the changes easier to review.
- Conduct a similar investigation for
datetimeformats, as I suspect they will require changes analogous to those made for date formats.
#13 Updated by Vladimir Tsichevski over 1 year ago
I found that date.getDateOrderNative() returns date order strings like "mdy", so I can now eliminate the Order enum I added to convert the 3-byte array into a string representation.
The change is in 9855a rev. 15831.
#14 Updated by Vladimir Tsichevski over 1 year ago
In revision 15832, a regression was resolved in the ParsedDateFormat.toString() method, which had incorrectly inserted zero-code characters into no-separator formats (e.g., "999999") where separators were absent, rather than leaving them out.
#15 Updated by Vladimir Tsichevski over 1 year ago
- Related to Bug #7515: FILL-IN: editing dates issues added
#16 Updated by Hynek Cihlar about 1 year ago
Code review 9855a.
The changes look good. Please also regression test ChUI beside GUI.
Anything left? Should the issue be marked as 100%?
#17 Updated by Hynek Cihlar about 1 year ago
+Hynek
#18 Updated by Vladimir Tsichevski about 1 year ago
Hynek Cihlar wrote:
Code review 9855a.
The changes look good. Please also regression test ChUI beside GUI.
I need to ask somebody to run ChUI regression test on my behalf, since this does not work on my workstation.
Anything left? Should the issue be marked as 100%?
As I mentioned in #9855-12:
- Sort class body members in the modified classes.
- Conduct a similar investigation for
datetimeanddatetime-tzformats. I will create a new task for this work.
#19 Updated by Hynek Cihlar about 1 year ago
Vladimir Tsichevski wrote:
I need to ask somebody to run ChUI regression test on my behalf, since this does not work on my workstation.
I'll run it.
#20 Updated by Vladimir Tsichevski about 1 year ago
Vladimir Tsichevski wrote:
Hynek Cihlar wrote:
Code review 9855a.
The changes look good. Please also regression test ChUI beside GUI.
I need to ask somebody to run ChUI regression test on my behalf, since this does not work on my workstation.
Anything left? Should the issue be marked as 100%?
As I mentioned in #9855-12:
- Sort class body members in the modified classes.
Done in 9855a rev. 16000.
#21 Updated by Vladimir Tsichevski about 1 year ago
- Related to Bug #10197: Datetime, datetime-tz FILL-IN: adjusts DATETIME format to SESSION:DATE-FORMAT order added
#22 Updated by Vladimir Tsichevski about 1 year ago
Vladimir Tsichevski wrote:
- Conduct a similar investigation for
datetimeanddatetime-tzformats. I will create a new task for this work.
Created the #10197 for this work.
#23 Updated by Vladimir Tsichevski about 1 year ago
- % Done changed from 90 to 100
#24 Updated by Hynek Cihlar about 1 year ago
Vladimir Tsichevski wrote:
Done in 9855a rev. 16000.
The line final byte[] orderBytes = date.getDateComponentOrder(); was removed in the commit, was this expected? Otherwise the changes look OK.
#25 Updated by Vladimir Tsichevski about 1 year ago
Hynek Cihlar wrote:
Vladimir Tsichevski wrote:
Done in 9855a rev. 16000.
The line
final byte[] orderBytes = date.getDateComponentOrder();was removed in the commit, was this expected? Otherwise the changes look OK.
Yes, this variable is not used anymore.
#26 Updated by Hynek Cihlar about 1 year ago
9855a passed ChUI regression tests.
#27 Updated by Vladimir Tsichevski about 1 year ago
Hynek Cihlar wrote:
9855a passed ChUI regression tests.
I think, this change can be merged then.
#28 Updated by Hynek Cihlar about 1 year ago
- Status changed from Review to Merge Pending
Please go ahead and merge 9855a.
#29 Updated by Vladimir Tsichevski about 1 year ago
Hynek Cihlar wrote:
Please go ahead and merge 9855a.
Merged as trunk rev. 16001.
#30 Updated by Greg Shah about 1 year ago
- Status changed from Merge Pending to Test