Skip to content

Commit 7293c83

Browse files
GFOP-162
1 parent 96e2c48 commit 7293c83

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

packages/ngx-calendar/src/lib/components/calendar/calendar.component.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class CalendarComponent implements OnInit, OnChanges {
6161
constructor(
6262
@Inject(CALENDAR_MONTH_LABELS) public moduleMonthLabels = CALENDAR_DEFAULT_MONTH_LABELS,
6363
@Inject(CALENDAR_WEEKDAY_LABELS) public moduleWeekdayLabels = CALENDAR_DEFAULT_WEEKDAY_LABELS,
64-
private calendarService: CalendarService
64+
private calendarService: CalendarService,
6565
) {}
6666

6767
public ngOnInit() {
@@ -153,10 +153,22 @@ export class CalendarComponent implements OnInit, OnChanges {
153153
pickDate(date: Date): void {
154154
const complete = this.activeView === CALENDAR_VIEW_MONTH;
155155

156-
this.selectDate.emit({
157-
date,
158-
complete,
159-
});
156+
if (complete) {
157+
const year = date.getFullYear();
158+
const month = date.getMonth();
159+
const day = date.getDate();
160+
const timezoneAwareDate = new Date(DateHelper.toUtcMidnightInBrussels(year, month, day));
161+
162+
this.selectDate.emit({
163+
date: timezoneAwareDate,
164+
complete,
165+
});
166+
} else {
167+
this.selectDate.emit({
168+
date,
169+
complete,
170+
});
171+
}
160172

161173
if (!complete) {
162174
this.activeDate = date;

packages/ngx-forms/src/lib/datepicker/components/datepicker/datepicker.component.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class DatepickerComponent implements OnInit, OnChanges, OnDestroy, Contro
9494
@Inject(DATEPICKER_ERROR_LABELS) private errorLabels = DATEPICKER_DEFAULT_ERROR_LABELS,
9595
public calendarService: CalendarService,
9696
private formBuilder: UntypedFormBuilder,
97-
private ref: ChangeDetectorRef
97+
private ref: ChangeDetectorRef,
9898
) {}
9999

100100
public ngOnInit(): void {
@@ -108,7 +108,10 @@ export class DatepickerComponent implements OnInit, OnChanges, OnDestroy, Contro
108108
const date = DateHelper.parseDate(format, 'yyyy-MM-dd');
109109
if (date) {
110110
this.selectedDate = date;
111-
this.onChange(date.toISOString());
111+
const year = date.getFullYear();
112+
const month = date.getMonth();
113+
const day = date.getDate();
114+
this.onChange(DateHelper.toUtcMidnightInBrussels(year, month, day));
112115
} else {
113116
// Change value with original value (and not null or '') so we can add an error in the validate function
114117
this.onChange(value);
@@ -138,7 +141,7 @@ export class DatepickerComponent implements OnInit, OnChanges, OnDestroy, Contro
138141
// Create an interval if min/max is filled in
139142
this.interval = IntervalBuilder.dateInterval(
140143
this.min ? new Date(this.min) : null,
141-
this.max ? new Date(this.max) : null
144+
this.max ? new Date(this.max) : null,
142145
)
143146
.not()
144147
.build();

packages/ngx-utils/src/lib/date/datehelper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import getLastWeekdayOfMonth from './helpers/getLastWeekdayOfMonth';
99
import getMonthLength from './helpers/getMonthLength';
1010
import getWeekday from './helpers/getWeekday';
1111
import parseDate from './helpers/parseDate';
12+
import toUtcMidnightInBrussels from './helpers/toUtcMidnightInBrussels';
1213
import updateDate from './helpers/updateDate';
1314
import updateMonth from './helpers/updateMonth';
1415

@@ -24,6 +25,7 @@ class DateHelper {
2425
static getMonthLength: any;
2526
static getWeekday: any;
2627
static parseDate: any;
28+
static toUtcMidnightInBrussels: any;
2729
static updateDate: any;
2830
static updateMonth: any;
2931
}
@@ -39,6 +41,7 @@ DateHelper.getLastWeekdayOfMonth = getLastWeekdayOfMonth;
3941
DateHelper.getMonthLength = getMonthLength;
4042
DateHelper.getWeekday = getWeekday;
4143
DateHelper.parseDate = parseDate;
44+
DateHelper.toUtcMidnightInBrussels = toUtcMidnightInBrussels;
4245
DateHelper.updateDate = updateDate;
4346
DateHelper.updateMonth = updateMonth;
4447

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function toUtcMidnightInBrussels(year: number, month: number, day: number): string {
2+
const utcDate = new Date(Date.UTC(year, month, day, 0, 0, 0));
3+
const brusselsDate = new Date(utcDate.toLocaleString('en-US', { timeZone: 'Europe/Brussels' }));
4+
const utcBrusselsDate = new Date(brusselsDate.toLocaleString('en-US', { timeZone: 'UTC' }));
5+
const offset = utcDate.getTime() - utcBrusselsDate.getTime();
6+
7+
const brusselsMidnight = new Date(utcDate.getTime() + offset);
8+
9+
return brusselsMidnight.toISOString();
10+
}

packages/ngx-utils/src/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export { default as getLastWeekdayOfMonth } from './lib/date/helpers/getLastWeek
4646
export { default as getMonthLength } from './lib/date/helpers/getMonthLength';
4747
export { default as getWeekday } from './lib/date/helpers/getWeekday';
4848
export { default as parseDate } from './lib/date/helpers/parseDate';
49+
export { default as toUtcMidnightInBrussels } from './lib/date/helpers/toUtcMidnightInBrussels';
4950
export { default as updateDate } from './lib/date/helpers/updateDate';
5051
export { default as updateMonth } from './lib/date/helpers/updateMonth';
5152

0 commit comments

Comments
 (0)