Skip to content

Commit a429459

Browse files
TreeHunter9Artyom Ivanov
andauthored
Change some aspects of the string-to-date conversion with format to make it more similar to the SQL standard #2388 (#7881)
* Use current TimeStamp for data in stringToDate conversion if it's not specify Also fix RM pattern and change (A/P)M to (A/P).M. * Add more tests * Add TimeStamp validation Also move duplicated code to functions. * Add more unit tests for "YY" and "YYY" patterns * Use Callback for getting current date It's better because we can mock Callback for unit tests. * Fix exception and README description * Add ability to print blr_cast_format * Put a comment about new BLR in the right place * Add information about behavior of string to datetime conversion * Rework old patterns and add new ones Add A.M, P.M., RR and RRRR patterns. Rework YY, YYY, HH and HH12 patterns due to new patterns. Add restriction from SQL standard to format. Fix incorrect error message for mismatched pattern. Fix bug with 0 hours in HH12. * Add more unit tests * Update doc for cast format * Allow specification of log_level for BOOST_TESTS in make * Change enum class to enum in namespace * Switch from plain enum to constexpr values --------- Co-authored-by: Artyom Ivanov <artyom.ivanov@red-soft.ru>
1 parent b40c1e0 commit a429459

File tree

12 files changed

+969
-378
lines changed

12 files changed

+969
-378
lines changed

builds/posix/Makefile.in

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,18 +790,20 @@ install install-embedded silent_install package packages dist:
790790

791791
.PHONY: tests tests_process run_tests run_tests_process
792792

793+
log_level ?= all
794+
793795
tests:
794796
$(MAKE) TARGET?=$(DefaultTarget) tests_process
795797

796798
tests_process: $(COMMON_TEST) $(ENGINE_TEST) $(ISQL_TEST)
797799

798800
run_tests:
799-
$(MAKE) TARGET?=$(DefaultTarget) run_tests_process
801+
$(MAKE) TARGET?=$(DefaultTarget) LOG_LEVEL?=$(log_level) run_tests_process
800802

801803
run_tests_process: tests_process
802-
$(COMMON_TEST) --log_level=all
803-
$(ENGINE_TEST) --log_level=all
804-
$(ISQL_TEST) --log_level=all
804+
$(COMMON_TEST) --log_level=$(LOG_LEVEL)
805+
$(ENGINE_TEST) --log_level=$(LOG_LEVEL)
806+
$(ISQL_TEST) --log_level=$(LOG_LEVEL)
805807

806808

807809
#___________________________________________________________________________

doc/README.cast.format.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## 1. DATETIME TO STRING
22

3-
The following flags are currently implemented for datetime to string conversion:
3+
The following patterns are currently implemented for datetime to string conversion:
44
| Format Pattern | Description |
55
| -------------- | ----------- |
66
| YEAR | Year (1 - 9999) |
@@ -21,12 +21,13 @@ The following flags are currently implemented for datetime to string conversion:
2121
| DDD | Day of the Year (001 - 366) |
2222
| DY | Short name of the Day (Mon) |
2323
| J | Julian Day (number of days since January 1, 4712 BC) |
24-
| HH / HH12 | Hour of the Day (01 - 12) with period (AM, PM) |
24+
| HH / HH12 | Hour of the Day (01 - 12) without Period (for Period use A.M or P.M.) |
2525
| HH24 | Hour of the Day (00 - 23) |
2626
| MI | Minutes (00 - 59) |
2727
| SS | Seconds (00 - 59) |
2828
| SSSSS | Seconds after midnight (0 - 86399) |
2929
| FF1 - FF9 | Fractional seconds with the specified accuracy |
30+
| A.M. / P.M. | Period for 12 hours time (it doesn't matter which one is used, period will be inserted based on time) |
3031
| TZH | Time zone in Hours (-14 - 14) |
3132
| TZM | Time zone in Minutes (00 - 59) |
3233
| TZR | Time zone Name |
@@ -61,32 +62,47 @@ SELECT CAST(CURRENT_TIMESTAMP AS VARCHAR(45) FORMAT 'DD.MM.YEAR HH24:MI:SS "is"
6162

6263
## 2. STRING TO DATETIME
6364

64-
The following flags are currently implemented for string to datetime conversion:
65+
The following patterns are currently implemented for string to datetime conversion:
6566
| Format Pattern | Description |
6667
| ------------- | ------------- |
6768
| YEAR | Year |
6869
| YYYY | Last 4 digits of Year |
6970
| YYY | Last 3 digits of Year |
7071
| YY | Last 2 digits of Year |
7172
| Y | Last 1 digits of Year |
73+
| RR / RRRR | Round Year (further information below) |
7274
| MM | Month (1 - 12) |
7375
| MON | Short Month name (Apr) |
7476
| MONTH | Full Month name (APRIL) |
7577
| RM | Roman representation of the Month (I - XII) |
7678
| DD | Day of the Month (1 - 31) |
7779
| J | Julian Day (number of days since January 1, 4712 BC) |
78-
| HH / HH12 | Hour of the Day (1 - 12) with period (AM, PM) |
80+
| HH / HH12 | Hour of the Day (1 - 12) without Period (to specify Period use A.M or P.M.) |
7981
| HH24 | Hour of the Day (0 - 23) |
8082
| MI | Minutes (0 - 59) |
8183
| SS | Seconds (0 - 59) |
8284
| SSSSS | Seconds after midnight (0 - 86399) |
8385
| FF1 - FF4 | Fractional seconds with the specified accuracy |
86+
| A.M. / P.M. | Period for 12 hours time (it doesn't matter which one is used, period will be taken from input string) |
8487
| TZH | Time zone in Hours (-14 - 14) |
8588
| TZM | Time zone in Minutes (0 - 59) |
8689
| TZR | Time zone Name |
8790

8891
Dividers are the same as for datetime to string conversion and can also be omitted.
8992

93+
Year, month and day will be taken from current date if these components are not used in pattern (this applies only to data types that contain a date component).
94+
95+
Behavior of `RR`:
96+
- If the specified two-digit year is 00 to 49, then
97+
- If the last two digits of the current year are 00 to 49, then the returned year has the same first two digits as the current year.
98+
- If the last two digits of the current year are 50 to 99, then the first 2 digits of the returned year are 1 greater than the first 2 digits of the current year.
99+
- If the specified two-digit year is 50 to 99, then
100+
- If the last two digits of the current year are 00 to 49, then the first 2 digits of the returned year are 1 less than the first 2 digits of the current year.
101+
- If the last two digits of the current year are 50 to 99, then the returned year has the same first two digits as the current year.
102+
103+
Behavior of `RRRR`: Accepts either 4-digit or 2-digit input. If 2-digit, provides the same return as `RR`. If you do not want this functionality, then enter the 4-digit year.
104+
105+
90106
Example:
91107
```
92108
SELECT CAST('2000.12.08 12:35:30.5000' AS TIMESTAMP FORMAT 'YEAR.MM.DD HH24:MI:SS.FF4') FROM RDB$DATABASE;

src/common/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ const int HIGH_WORD = 0;
971971
#endif
972972
#endif
973973

974+
974975
inline const TEXT FB_SHORT_MONTHS[][4] =
975976
{
976977
"Jan", "Feb", "Mar",

0 commit comments

Comments
 (0)