Skip to content

Commit 4a61936

Browse files
committed
plugin: fix date time parsing
In the new API, the datetime field doesn't exist. Instead its aliased to date, so we need to check for 'T' to see if this is a datetime or a date string
1 parent 3f8ffe2 commit 4a61936

File tree

5 files changed

+37
-54
lines changed

5 files changed

+37
-54
lines changed

plugin/src/api/domain/dueDate.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export type DueDate = {
22
isRecurring: boolean;
33
date: string;
4-
datetime?: string;
54
};

plugin/src/data/dueDate.test.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ describe("parse", () => {
5555
{
5656
description: "should parse a due date with time",
5757
input: {
58-
date: "2024-02-01",
59-
datetime: "2024-02-01T12:00:00",
58+
date: "2024-02-01T12:00:00",
6059
isRecurring: false,
6160
},
6261
expected: {
@@ -73,8 +72,7 @@ describe("parse", () => {
7372
{
7473
description: "should parse a due date with time and timezone",
7574
input: {
76-
date: "2024-02-01",
77-
datetime: "2024-02-01T12:00:00Z",
75+
date: "2024-02-01T12:00:00Z",
7876
isRecurring: false,
7977
},
8078
expected: {
@@ -108,8 +106,7 @@ describe("parse", () => {
108106
{
109107
description: "should parse a due date for today with time",
110108
input: {
111-
date: "2024-01-01",
112-
datetime: "2024-01-01T12:00:00",
109+
date: "2024-01-01T12:00:00",
113110
isRecurring: false,
114111
},
115112
expected: {
@@ -143,9 +140,8 @@ describe("parse", () => {
143140
{
144141
description: "should parse a due date for tomorrow with time",
145142
input: {
146-
date: "2024-01-02",
143+
date: "2024-01-02T12:00:00",
147144
isRecurring: false,
148-
datetime: "2024-01-02T12:00:00",
149145
},
150146
expected: {
151147
start: {
@@ -178,9 +174,8 @@ describe("parse", () => {
178174
{
179175
description: "should parse a due date for yesterday with time",
180176
input: {
181-
date: "2023-12-31",
177+
date: "2023-12-31T12:00:00",
182178
isRecurring: false,
183-
datetime: "2023-12-31T12:00:00",
184179
},
185180
expected: {
186181
start: {
@@ -213,9 +208,8 @@ describe("parse", () => {
213208
{
214209
description: "should parse a due date for next week with time",
215210
input: {
216-
date: "2024-01-06",
211+
date: "2024-01-06T12:00:00",
217212
isRecurring: false,
218-
datetime: "2024-01-06T12:00:00",
219213
},
220214
expected: {
221215
start: {
@@ -248,9 +242,8 @@ describe("parse", () => {
248242
{
249243
description: "should parse a due date for last week with time",
250244
input: {
251-
date: "2023-12-29",
245+
date: "2023-12-29T12:00:00",
252246
isRecurring: false,
253-
datetime: "2023-12-29T12:00:00",
254247
},
255248
expected: {
256249
start: {
@@ -283,9 +276,8 @@ describe("parse", () => {
283276
{
284277
description: "should parse a date not this year with time",
285278
input: {
286-
date: "2025-01-01",
279+
date: "2025-01-01T12:00:00",
287280
isRecurring: false,
288-
datetime: "2025-01-01T12:00:00",
289281
},
290282
expected: {
291283
start: {
@@ -318,9 +310,8 @@ describe("parse", () => {
318310
{
319311
description: "should parse a date that's overdue with time",
320312
input: {
321-
date: "2023-06-01",
313+
date: "2023-06-01T12:00:00",
322314
isRecurring: false,
323-
datetime: "2023-06-01T12:00:00",
324315
},
325316
expected: {
326317
start: {
@@ -358,8 +349,7 @@ describe("parse with duration", () => {
358349
description: "should parse a due date with 30 minutes duration",
359350
input: {
360351
due: {
361-
date: "2024-02-01",
362-
datetime: "2024-02-01T12:00:00",
352+
date: "2024-02-01T12:00:00",
363353
isRecurring: false,
364354
},
365355
duration: {
@@ -388,8 +378,7 @@ describe("parse with duration", () => {
388378
description: "should parse a due date with 2 days duration",
389379
input: {
390380
due: {
391-
date: "2024-02-01",
392-
datetime: "2024-02-01T12:00:00",
381+
date: "2024-02-01T12:00:00",
393382
isRecurring: false,
394383
},
395384
duration: {
@@ -418,8 +407,7 @@ describe("parse with duration", () => {
418407
description: "should parse a due date that crosses to next day with duration",
419408
input: {
420409
due: {
421-
date: "2024-02-01",
422-
datetime: "2024-02-01T23:00:00",
410+
date: "2024-02-01T23:00:00",
423411
isRecurring: false,
424412
},
425413
duration: {

plugin/src/data/dueDate.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ export type DueDate = {
2828

2929
const parseDueDate = (dueDate: ApiDueDate, duration?: ApiDuration): DueDate => {
3030
let start: ZonedDateTime | CalendarDate;
31-
if (dueDate.datetime !== undefined) {
32-
// If the datetime comes with a trailing Z, then the task has a fixed timezone. We repsect
31+
const hasTime = dueDate.date.includes("T");
32+
if (hasTime) {
33+
// If the datetime comes with a trailing Z, then the task has a fixed timezone. We respect
3334
// this and convert it into their local timezone. Otherwise, it is a floating timezone and we
3435
// simply parse it as a local datetime.
35-
if (dueDate.datetime.endsWith("Z")) {
36-
start = parseAbsolute(dueDate.datetime, timezone());
36+
if (dueDate.date.endsWith("Z")) {
37+
start = parseAbsolute(dueDate.date, timezone());
3738
} else {
38-
start = fromDate(parseDateTime(dueDate.datetime).toDate(timezone()), timezone());
39+
start = fromDate(parseDateTime(dueDate.date).toDate(timezone()), timezone());
3940
}
4041
} else {
4142
start = parseDate(dueDate.date);

plugin/src/data/transformations/sorting.test.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,13 @@ describe("sortTasks", () => {
141141
makeTask("d", {
142142
due: {
143143
isRecurring: false,
144-
date: "2020-03-15",
145-
datetime: "2020-03-15T15:00:00",
144+
date: "2020-03-15T15:00:00",
146145
},
147146
}),
148147
makeTask("e", {
149148
due: {
150149
isRecurring: false,
151-
date: "2020-03-15",
152-
datetime: "2020-03-15T13:00:00",
150+
date: "2020-03-15T13:00:00",
153151
},
154152
}),
155153
],
@@ -158,15 +156,13 @@ describe("sortTasks", () => {
158156
makeTask("e", {
159157
due: {
160158
isRecurring: false,
161-
date: "2020-03-15",
162-
datetime: "2020-03-15T13:00:00",
159+
date: "2020-03-15T13:00:00",
163160
},
164161
}),
165162
makeTask("d", {
166163
due: {
167164
isRecurring: false,
168-
date: "2020-03-15",
169-
datetime: "2020-03-15T15:00:00",
165+
date: "2020-03-15T15:00:00",
170166
},
171167
}),
172168
makeTask("c", {
@@ -190,15 +186,13 @@ describe("sortTasks", () => {
190186
makeTask("e", {
191187
due: {
192188
isRecurring: false,
193-
date: "2020-03-15",
194-
datetime: "2020-03-15T13:00:00",
189+
date: "2020-03-15T13:00:00",
195190
},
196191
}),
197192
makeTask("d", {
198193
due: {
199194
isRecurring: false,
200-
date: "2020-03-15",
201-
datetime: "2020-03-15T15:00:00",
195+
date: "2020-03-15T15:00:00",
202196
},
203197
}),
204198
makeTask("c", {
@@ -233,15 +227,13 @@ describe("sortTasks", () => {
233227
makeTask("d", {
234228
due: {
235229
isRecurring: false,
236-
date: "2020-03-15",
237-
datetime: "2020-03-15T15:00:00",
230+
date: "2020-03-15T15:00:00",
238231
},
239232
}),
240233
makeTask("e", {
241234
due: {
242235
isRecurring: false,
243-
date: "2020-03-15",
244-
datetime: "2020-03-15T13:00:00",
236+
date: "2020-03-15T13:00:00",
245237
},
246238
}),
247239
],

plugin/src/ui/createTaskModal/DueDateSelector.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,18 @@ const getLabel = (selected: DueDate | undefined) => {
187187
return t().createTaskModal.dateSelector.emptyDate;
188188
}
189189

190+
let dateString: string;
191+
if (selected.timeInfo !== undefined) {
192+
dateString = toZoned(
193+
toCalendarDateTime(selected.date, selected.timeInfo.time),
194+
timezone(),
195+
).toAbsoluteString();
196+
} else {
197+
dateString = selected.date.toString();
198+
}
199+
190200
const apiDueDate: ApiDueDate = {
191-
date: selected.date.toString(),
192-
datetime:
193-
selected.timeInfo !== undefined
194-
? toZoned(
195-
toCalendarDateTime(selected.date, selected.timeInfo.time),
196-
timezone(),
197-
).toAbsoluteString()
198-
: undefined,
201+
date: dateString,
199202
isRecurring: false,
200203
};
201204

0 commit comments

Comments
 (0)