Skip to content

Commit 08bdedf

Browse files
committed
FEAT: Way to combine DATE! and TIME! without a variable
resolves: Oldes/Rebol-wishes#1
1 parent 432e8a3 commit 08bdedf

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/core/t-date.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,15 @@
435435

436436
if (IS_DATE(arg)) {
437437
*val = *arg;
438+
if (IS_TIME(++arg)) {
439+
// make date! [1-1-2000 100:0]
440+
// we must get date parts here so can be used
441+
// for time normalization later
442+
day = VAL_DAY(val) - 1;
443+
month = VAL_MONTH(val) - 1;
444+
year = VAL_YEAR(val);
445+
goto set_time;
446+
}
438447
return TRUE;
439448
}
440449

@@ -463,6 +472,7 @@
463472
day--;
464473
month--;
465474

475+
set_time:
466476
if (IS_TIME(arg)) {
467477
secs = VAL_TIME(arg);
468478
arg++;
@@ -812,7 +822,7 @@
812822
bp = Qualify_String(arg, 45, &len, FALSE); // can trap, ret diff str
813823
if (Scan_Date(bp, len, D_RET)) return R_RET;
814824
}
815-
else if (ANY_BLOCK(arg) && VAL_BLK_LEN(arg) >= 3) {
825+
else if (ANY_BLOCK(arg) && VAL_BLK_LEN(arg) >= 1) {
816826
if (MT_Date(D_RET, VAL_BLK_DATA(arg), REB_DATE)) {
817827
return R_RET;
818828
}

src/tests/units/date-test.r3

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ Rebol [
4343
===end-group===
4444

4545
===start-group=== "TO DATE!"
46+
--test-- "make date!"
47+
--assert 1-Feb-0003 = make date! [1 2 3]
48+
--assert 1-Feb-0003/4:00 = make date! [1 2 3 4:0]
49+
--assert 1-Feb-0003/4:00+5:00 = make date! [1 2 3 4:0 5:0]
50+
;@@ https://github.com/Oldes/Rebol-wishes/issues/1
51+
--assert 1-Jan-2000 = make date! [1-1-2000]
52+
--assert 1-Jan-2000/10:00 = make date! [1-1-2000 10:0]
53+
--assert 1-Jan-2000/10:00+2:00 = make date! [1-1-2000 10:0 2:0]
54+
--assert 5-Jan-2000/4:00 = make date! [1-1-2000 100:0]
55+
4656
--test-- "invalid input"
4757
;@@ https://github.com/Oldes/Rebol-issues/issues/878
4858
--assert error? try [to date! "31-2-2009"]
@@ -56,6 +66,12 @@ Rebol [
5666
--assert 1-Feb-0003 = #[date! 1 2 3]
5767
--assert 1-Feb-0003/4:00 = #[date! 1 2 3 4:0]
5868
--assert 1-Feb-0003/4:00+5:00 = #[date! 1 2 3 4:0 5:0]
69+
;@@ https://github.com/Oldes/Rebol-wishes/issues/1
70+
--assert 1-Jan-2000 = #[date! 1-1-2000]
71+
--assert 1-Jan-2000/10:00 = #[date! 1-1-2000 10:0]
72+
--assert 1-Jan-2000/10:00+2:00 = #[date! 1-1-2000 10:0 2:0]
73+
--assert 5-Jan-2000/4:00 = #[date! 1-1-2000 100:0]
74+
5975
--test-- "#[date!] invalid"
6076
--assert error? try [load {#[date!]}]
6177
--assert error? try [load {#[date! 1]}]

0 commit comments

Comments
 (0)