Skip to content

Commit 3822b56

Browse files
committed
FEAT: less strict to-date conversion
1 parent 901728e commit 3822b56

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

src/boot/sysobj.reb

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ catalog: object [
5656
alpha: #[bitset! #{00000000000000007FFFFFE07FFFFFE0}] ;A-Z a-z
5757
alpha-numeric: #[bitset! #{000000000000FFC07FFFFFE07FFFFFE0}] ;A-Z a-z 0-9
5858
hex-digits: #[bitset! #{000000000000FFC07E0000007E}] ;A-F a-f 0-9
59+
plus-minus: #[bitset! #{000000000014}] ;charset "+-"
5960
; chars which does not have to be url-encoded:
6061
uri: #[bitset! #{000000005BFFFFF5FFFFFFE17FFFFFE2}] ;A-Z a-z 0-9 !#$&'()*+,-./:;=?@_~
6162
uri-component: #[bitset! #{0000000041E6FFC07FFFFFE17FFFFFE2}] ;A-Z a-z 0-9 !'()*-._~

src/mezz/mezz-date.reb

+20-25
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,25 @@ to-idate: func [
4949
]
5050
]
5151

52-
to-date: wrap [
53-
digit: charset [#"0" - #"9"]
54-
alpha: charset [#"a" - #"z" #"A" - #"Z"]
55-
function [
56-
"Converts to date! value."
57-
value [any-type!] "May be also a standard Internet date string/binary"
58-
/utc "Returns the date with UTC zone"
59-
][
60-
if all [
61-
any [string? value binary? value]
62-
parse value [
63-
5 skip
64-
copy day: 1 2 digit space
65-
copy month: 3 alpha space
66-
copy year: 1 4 digit space
67-
copy time: to space space
68-
copy zone: to end
69-
]
70-
][
71-
if zone = "GMT" [zone: "+0"]
72-
value: to string! rejoin [day "-" month "-" year "/" time zone]
52+
to-date: function/with [
53+
"Converts to date! value."
54+
value [any-type!] "May be also a standard Internet date string/binary"
55+
/utc "Returns the date with UTC zone"
56+
][
57+
if all [
58+
any [string? value binary? value]
59+
parse value [
60+
5 skip
61+
copy day: 1 2 numeric sp
62+
copy month: 3 alpha sp
63+
copy year: 1 4 numeric sp
64+
copy time: to sp sp
65+
[copy zone: [plus-minus 4 numeric] | no-case "GMT" (zone: "+0")]
66+
to end ; ignore the rest (like comments in mime fields)!
7367
]
74-
75-
if all [value: to date! value utc] [ value/timezone: 0 ]
76-
value
68+
][
69+
value: to string! rejoin [day "-" month "-" year "/" time any [zone ""]]
7770
]
78-
]
71+
if all [value: to date! value utc] [ value/timezone: 0 ]
72+
value
73+
] system/catalog/bitsets

src/tests/units/date-test.r3

+1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ Rebol [
325325
--assert 28-Mar-2019/0:00 = to-date to-binary "Thu, 28 Mar 2019 00:00:00 +0000"
326326
--assert 4-Apr-2019/19:41:46 = to-date "Thu, 04 Apr 2019 19:41:46 GMT"
327327
--assert 1-Apr-2019/21:50:04 = to-date "Mon, 1 Apr 2019 21:50:04 GMT"
328+
--assert 30-Jul-2013/2:17:58-7:00 = to-date "Tue, 30 Jul 2013 02:17:58 -0700 (PDT)"
328329

329330

330331
===end-group===

0 commit comments

Comments
 (0)