Skip to content

Commit c4f6bd1

Browse files
committed
ignore timezone in custom form
1 parent 41250e2 commit c4f6bd1

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/data/entry-form/CustomForm.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { convertAttributeValueToDate } from "$/data/utils";
1919
import templateVelocity from "$/data/entry-form/template.vm?raw";
2020
import templateJs from "$/data/entry-form/template.js?raw";
2121
import templateCss from "$/data/entry-form/template.css?raw";
22+
import { toISODateWithoutTimezone } from "$/utils/date";
2223

2324
function getCategoryCombo(dataSetElement: DataSetTemplate["dataSetElements"][0]) {
2425
const { categoryCombo } = dataSetElement;
@@ -454,8 +455,10 @@ function generatePeriodsFromAttributeValues(
454455
return [
455456
year,
456457
{
457-
start: convertAttributeValueToDate(startDate),
458-
end: convertAttributeValueToDate(endDate),
458+
start: toISODateWithoutTimezone(
459+
new Date(convertAttributeValueToDate(startDate))
460+
),
461+
end: toISODateWithoutTimezone(new Date(convertAttributeValueToDate(endDate))),
459462
},
460463
] as [string, TemplateDate];
461464
})

src/domain/entities/DatePeriod.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Struct } from "$/domain/entities/generic/Struct";
22
import { Config } from "$/domain/entities/Config";
3-
import { addToDate, formatDateToISO, getDiff, stringToTime } from "$/utils/date";
3+
import { addToDate, toISODateWithoutTimezone, getDiff, stringToTime } from "$/utils/date";
44
import _, { Collection } from "$/domain/entities/generic/Collection";
55
import { Maybe } from "$/utils/ts-utils";
66

@@ -71,8 +71,8 @@ export class DatePeriod extends Struct<DatePeriodAttrs>() {
7171
return MonthlyPeriodDetails.create({
7272
year: targetYear,
7373
month: targetMonth,
74-
startDate: formatDateToISO(openingDate),
75-
endDate: formatDateToISO(closingDate),
74+
startDate: toISODateWithoutTimezone(openingDate),
75+
endDate: toISODateWithoutTimezone(closingDate),
7676
});
7777
})
7878
.value();
@@ -113,7 +113,7 @@ export class DatePeriod extends Struct<DatePeriodAttrs>() {
113113
private buildShortFormat(date: string) {
114114
if (!date) return "";
115115

116-
const datePart = formatDateToISO(new Date(date)).split("T")[0];
116+
const datePart = toISODateWithoutTimezone(new Date(date)).split("T")[0];
117117
if (!datePart) return "";
118118
return datePart.replace(/-/g, "");
119119
}

src/utils/date.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function getDaysPerMonthYear(
100100
}));
101101
}
102102

103-
export function formatDateToISO(date: Date) {
103+
export function toISODateWithoutTimezone(date: Date) {
104104
const dateParts = [
105105
date.getFullYear(),
106106
String(date.getMonth() + 1).padStart(2, "0"),

0 commit comments

Comments
 (0)