Skip to content

Commit dd7b236

Browse files
committed
Fixes lint
1 parent 6b22347 commit dd7b236

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

packages/scenario/test/bind-types.test.ts

+18-21
Original file line numberDiff line numberDiff line change
@@ -668,17 +668,15 @@ describe('Data (<bind type>) type support', () => {
668668
expect(answer.stringValue).toBe('');
669669
});
670670

671-
it.each([
672-
'13:30:55',
673-
'2025-23-23',
674-
'ZYX',
675-
'2025-03-07T14:30:00+invalid',
676-
])('has null when incorrect value is passed', (expression) => {
677-
scenario.answer('/root/date-value', expression);
678-
answer = getTypedInputNodeAnswer('/root/date-value', 'date');
679-
expect(answer.value).toBeNull();
680-
expect(answer.stringValue).toBe('');
681-
});
671+
it.each(['13:30:55', '2025-23-23', 'ZYX', '2025-03-07T14:30:00+invalid'])(
672+
'has null when incorrect value is passed',
673+
(expression) => {
674+
scenario.answer('/root/date-value', expression);
675+
answer = getTypedInputNodeAnswer('/root/date-value', 'date');
676+
expect(answer.value).toBeNull();
677+
expect(answer.stringValue).toBe('');
678+
}
679+
);
682680

683681
it.each([
684682
{
@@ -693,7 +691,9 @@ describe('Data (<bind type>) type support', () => {
693691
},
694692
{
695693
expression: '2025-03-07T14:30:00-08:00[America/Los_Angeles]',
696-
expectedAsObject: Temporal.ZonedDateTime.from('2025-03-07T14:30:00-08:00[America/Los_Angeles]'),
694+
expectedAsObject: Temporal.ZonedDateTime.from(
695+
'2025-03-07T14:30:00-08:00[America/Los_Angeles]'
696+
),
697697
expectedAsText: '2025-03-07T14:30:00-08:00[America/Los_Angeles]',
698698
},
699699
{
@@ -706,15 +706,12 @@ describe('Data (<bind type>) type support', () => {
706706
expectedAsObject: Temporal.PlainDateTime.from('2025-03-07T14:30:00'),
707707
expectedAsText: '2025-03-07T14:30:00',
708708
},
709-
])(
710-
'sets value with valid date',
711-
({ expression, expectedAsObject, expectedAsText }) => {
712-
scenario.answer('/root/date-value', expression);
713-
answer = getTypedInputNodeAnswer('/root/date-value', 'date');
714-
expect(answer.value).to.deep.equal(expectedAsObject);
715-
expect(answer.stringValue).toEqual(expectedAsText);
716-
}
717-
);
709+
])('sets value with valid date', ({ expression, expectedAsObject, expectedAsText }) => {
710+
scenario.answer('/root/date-value', expression);
711+
answer = getTypedInputNodeAnswer('/root/date-value', 'date');
712+
expect(answer.value).to.deep.equal(expectedAsObject);
713+
expect(answer.stringValue).toEqual(expectedAsText);
714+
});
718715
});
719716
});
720717

packages/xforms-engine/src/lib/codecs/Date/Datetime.ts

+27-16
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@ import {
55
ISO_DATE_TIME_LIKE_PATTERN,
66
} from '@getodk/common/constants/datetime.ts';
77

8-
export type DatetimeRuntimeValue = Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime | null;
8+
export type DatetimeRuntimeValue =
9+
| Temporal.PlainDate
10+
| Temporal.PlainDateTime
11+
| Temporal.ZonedDateTime
12+
| null;
913

10-
export type DatetimeInputValue = Date | Temporal.PlainDate | Temporal.PlainDateTime | Temporal.ZonedDateTime | string | null;
14+
export type DatetimeInputValue =
15+
| Date
16+
| Temporal.PlainDate
17+
| Temporal.PlainDateTime
18+
| Temporal.ZonedDateTime
19+
| string
20+
| null;
1121

1222
export class Datetime {
13-
1423
static parseString(value: string): DatetimeRuntimeValue {
15-
if (value == null || typeof value !== 'string' || !ISO_DATE_OR_DATE_TIME_LIKE_PATTERN.test(value)) {
24+
if (
25+
value == null ||
26+
typeof value !== 'string' ||
27+
!ISO_DATE_OR_DATE_TIME_LIKE_PATTERN.test(value)
28+
) {
1629
return null;
1730
}
1831

@@ -47,18 +60,16 @@ export class Datetime {
4760
}
4861

4962
if (value instanceof Date) {
50-
return Temporal.ZonedDateTime
51-
.from({
52-
timeZoneId: Temporal.Now.timeZoneId(),
53-
year: value.getFullYear(),
54-
month: value.getMonth() + 1,
55-
day: value.getDate(),
56-
hour: value.getHours(),
57-
minute: value.getMinutes(),
58-
second: value.getSeconds(),
59-
millisecond: value.getMilliseconds(),
60-
})
61-
.toString();
63+
return Temporal.ZonedDateTime.from({
64+
timeZoneId: Temporal.Now.timeZoneId(),
65+
year: value.getFullYear(),
66+
month: value.getMonth() + 1,
67+
day: value.getDate(),
68+
hour: value.getHours(),
69+
minute: value.getMinutes(),
70+
second: value.getSeconds(),
71+
millisecond: value.getMilliseconds(),
72+
}).toString();
6273
}
6374

6475
const parsedValue = Datetime.parseString(value);

0 commit comments

Comments
 (0)