CLI interface to medialist (fossil mirror)
Revision | 85e9274d4ae6cd7d5a839cf647cdf96860777643 (tree) |
---|---|
Zeit | 2021-09-21 19:28:36 |
Autor | mio <stigma@disr...> |
Commiter | mio |
Simplify date formats in add.d and update.d
FossilOrigin-Name: 75e01670133063769c149d4be4c1e79374bc8d46c528e3619acf04fff67266f9
@@ -40,7 +40,6 @@ private enum NUMBER_OF_HEADERS = 6; | ||
40 | 40 | import std.file : exists, isFile; |
41 | 41 | import std.path : buildPath; |
42 | 42 | import std.stdio : File, stderr, writefln; |
43 | - import std.datetime.systime : Clock; | |
44 | 43 | import std.string : strip, split, toLower; |
45 | 44 | import std.typecons : tuple, Tuple; |
46 | 45 |
@@ -167,13 +166,14 @@ private enum NUMBER_OF_HEADERS = 6; | ||
167 | 166 | } |
168 | 167 | |
169 | 168 | import std.array : replicate; |
170 | - import std.format : format; | |
169 | + import std.datetime.date : Date; | |
170 | + import std.datetime.systime : Clock; | |
171 | 171 | |
172 | 172 | size_t previous_indent = 0; |
173 | 173 | |
174 | - immutable currentTime = Clock.currTime(); | |
175 | - immutable currentTimeString = format("%d-%d-%d", currentTime.year, | |
176 | - currentTime.month, currentTime.day); | |
174 | + immutable currentDT = Clock.currTime(); | |
175 | + immutable currentDateString = Date(currentDT.year, currentDT.month, | |
176 | + currentDT.day).toISOExtString(); | |
177 | 177 | |
178 | 178 | foreach (header_pair; header_positions) |
179 | 179 | { |
@@ -197,14 +197,14 @@ private enum NUMBER_OF_HEADERS = 6; | ||
197 | 197 | break; |
198 | 198 | case "start_date": |
199 | 199 | if (status.toLower == "watching" || status.toLower == "reading") |
200 | - f.write(currentTimeString); | |
200 | + f.write(currentDateString); | |
201 | 201 | break; |
202 | 202 | case "end_date": |
203 | 203 | if (status.toLower == "complete") |
204 | - f.write(currentTimeString); | |
204 | + f.write(currentDateString); | |
205 | 205 | break; |
206 | 206 | case "last_updated": |
207 | - f.write(currentTimeString); | |
207 | + f.write(currentDateString); | |
208 | 208 | break; |
209 | 209 | default: |
210 | 210 | // should be impossible, unless D changes the default for string. |
@@ -36,6 +36,8 @@ import std.typecons : Tuple; | ||
36 | 36 | handle_update(string program_name, string[] args, string data_dir) |
37 | 37 | { |
38 | 38 | import std.conv : ConvException, parse; |
39 | + import std.datetime.date : Date; | |
40 | + import std.datetime.systime : Clock; | |
39 | 41 | import std.file : exists, isFile, readText; |
40 | 42 | import std.format : format; |
41 | 43 | import std.path : buildPath; |
@@ -47,6 +49,9 @@ handle_update(string program_name, string[] args, string data_dir) | ||
47 | 49 | string title = ""; |
48 | 50 | string status = ""; |
49 | 51 | string progress = ""; |
52 | + auto currentDateTime = Clock.currTime(); | |
53 | + Date currentDate = Date(currentDateTime.year, currentDateTime.month, | |
54 | + currentDateTime.day); | |
50 | 55 | |
51 | 56 | if (args[0] == "-h" || args[0] == "--help") { |
52 | 57 | display_usage(program_name); |
@@ -139,12 +144,8 @@ handle_update(string program_name, string[] args, string data_dir) | ||
139 | 144 | string oldStatus = ""; |
140 | 145 | |
141 | 146 | import std.array : replicate; |
142 | - import std.datetime.systime : Clock; | |
143 | - import std.format : format; | |
144 | - | |
145 | - immutable currentTime = Clock.currTime(); | |
146 | - immutable currentTimeString = format("%d-%d-%d", currentTime.year, | |
147 | - currentTime.month, currentTime.day); | |
147 | + | |
148 | + string currentDateString = currentDate.toISOExtString(); | |
148 | 149 | |
149 | 150 | foreach (sectionIndent, section; sections) |
150 | 151 | { |
@@ -171,13 +172,13 @@ handle_update(string program_name, string[] args, string data_dir) | ||
171 | 172 | updatedLine ~= progress; |
172 | 173 | break; |
173 | 174 | case MLHeaders.lastUpdated: |
174 | - updatedLine ~= currentTimeString; | |
175 | + updatedLine ~= currentDateString; | |
175 | 176 | break; |
176 | 177 | case MLHeaders.startDate: |
177 | 178 | if ((oldStatus == "plan-to-read" || oldStatus == "plan-to-watch") |
178 | 179 | && (status.toLower == "reading" || status.toLower == "watching")) |
179 | 180 | { |
180 | - updatedLine ~= currentTimeString; | |
181 | + updatedLine ~= currentDateString; | |
181 | 182 | } |
182 | 183 | else |
183 | 184 | { |
@@ -189,7 +190,7 @@ handle_update(string program_name, string[] args, string data_dir) | ||
189 | 190 | if ((oldStatus == "reading" || oldStatus == "watching") |
190 | 191 | && (status.toLower == "complete")) |
191 | 192 | { |
192 | - updatedLine ~= currentTimeString; | |
193 | + updatedLine ~= currentDateString; | |
193 | 194 | } |
194 | 195 | else |
195 | 196 | { |