@@ -22,18 +22,20 @@ let unsafe_digit n = Char.unsafe_chr (Char.code '0' + n)
22
22
let put_2d s ofs n =
23
23
Bytes. unsafe_set s ofs (unsafe_digit (n / 10 ));
24
24
Bytes. unsafe_set s (ofs+ 1 ) (unsafe_digit (n mod 10 ))
25
- let replace_year_2019 s year =
26
- if year <> 2019 then
25
+
26
+ let replace_year_2020 s t =
27
+ let year = t.Unix. tm_year + 1900 in
28
+ if year <> 2020 then
27
29
begin
28
- if year > = 2010 && year < 2020 then
30
+ if year > = 2020 && year < 2030 then
29
31
Bytes. unsafe_set s 3 (unsafe_digit (year mod 10 ))
30
32
else
31
33
Bytes. unsafe_blit (Bytes. unsafe_of_string @@ if year > = 1000 then string_of_int year else sprintf " %04u" year) 0 s 0 4
32
34
end
33
35
34
36
let fast_to_string =
35
37
(* "%04u-%02u-%02uT%02u:%02u:%02u%s" *)
36
- let template = " 2019 -__-__T__:__:__" in
38
+ let template = " 2020 -__-__T__:__:__" in
37
39
let template_z = template ^ " Z" in
38
40
let last_time = ref 0 in
39
41
let last_gmt = ref true in
@@ -45,7 +47,7 @@ let fast_to_string =
45
47
let open Unix in
46
48
let t = (if gmt then gmtime else localtime) f in
47
49
let s = Bytes. of_string (if gmt then template_z else template) in
48
- replace_year_2019 s (t.tm_year + 1900 ) ;
50
+ replace_year_2020 s t ;
49
51
put_2d s 5 (t.tm_mon+ 1 );
50
52
put_2d s 8 t.tm_mday;
51
53
put_2d s 11 t.tm_hour;
@@ -72,45 +74,45 @@ let gmt_string_ms = to_string ~gmt:true ~ms:true
72
74
73
75
(* * YYYY-MM-DD *)
74
76
let format_date_w3 =
75
- let template = " 2019 -__-__" in
77
+ let template = " 2020 -__-__" in
76
78
fun t ->
77
79
let open Unix in
78
80
let s = Bytes. of_string template in
79
- replace_year_2019 s (t.tm_year + 1900 ) ;
81
+ replace_year_2020 s t ;
80
82
put_2d s 5 (t.tm_mon+ 1 );
81
83
put_2d s 8 t.tm_mday;
82
84
Bytes. unsafe_to_string s
83
85
84
86
(* * YYYYMMDD *)
85
87
let format_date8 =
86
- let template = " 2019____ " in
88
+ let template = " 2020____ " in
87
89
fun t ->
88
90
let open Unix in
89
91
let s = Bytes. of_string template in
90
- replace_year_2019 s (t.tm_year + 1900 ) ;
92
+ replace_year_2020 s t ;
91
93
put_2d s 4 (t.tm_mon+ 1 );
92
94
put_2d s 6 t.tm_mday;
93
95
Bytes. unsafe_to_string s
94
96
95
97
(* * YYYYMMDDhh *)
96
98
let format_date8h =
97
- let template = " 2019______ " in
99
+ let template = " 2020______ " in
98
100
fun t ->
99
101
let open Unix in
100
102
let s = Bytes. of_string template in
101
- replace_year_2019 s (t.tm_year + 1900 ) ;
103
+ replace_year_2020 s t ;
102
104
put_2d s 4 (t.tm_mon+ 1 );
103
105
put_2d s 6 t.tm_mday;
104
106
put_2d s 8 t.tm_hour;
105
107
Bytes. unsafe_to_string s
106
108
107
109
(* * YYYYMMDDhhmm *)
108
110
let format_date8hm =
109
- let template = " 2019________ " in
111
+ let template = " 2020________ " in
110
112
fun t ->
111
113
let open Unix in
112
114
let s = Bytes. of_string template in
113
- replace_year_2019 s (t.tm_year + 1900 ) ;
115
+ replace_year_2020 s t ;
114
116
put_2d s 4 (t.tm_mon+ 1 );
115
117
put_2d s 6 t.tm_mday;
116
118
put_2d s 8 t.tm_hour;
@@ -119,11 +121,11 @@ let format_date8hm =
119
121
120
122
(* * YYYYMMDDhhmmss *)
121
123
let format_date8hms =
122
- let template = " 2019__________ " in
124
+ let template = " 2020__________ " in
123
125
fun t ->
124
126
let open Unix in
125
127
let s = Bytes. of_string template in
126
- replace_year_2019 s (t.tm_year + 1900 ) ;
128
+ replace_year_2020 s t ;
127
129
put_2d s 4 (t.tm_mon+ 1 );
128
130
put_2d s 6 t.tm_mday;
129
131
put_2d s 8 t.tm_hour;
@@ -132,12 +134,12 @@ let format_date8hms =
132
134
Bytes. unsafe_to_string s
133
135
134
136
(* * YYYY-MM-DD hh:mm:ss *)
135
- let format_date8hms =
136
- let template = " 2019 -__-__ __:__:__" in
137
+ let format_basic =
138
+ let template = " 2020 -__-__ __:__:__" in
137
139
fun t ->
138
140
let open Unix in
139
141
let s = Bytes. of_string template in
140
- replace_year_2019 s (t.tm_year + 1900 ) ;
142
+ replace_year_2020 s t ;
141
143
put_2d s 5 (t.tm_mon+ 1 );
142
144
put_2d s 8 t.tm_mday;
143
145
put_2d s 11 t.tm_hour;
0 commit comments