Skip to content

Commit 58ccfa2

Browse files
travistryanformio
authored andcommitted
FIO-5750: Fixing timezones in emails.
1 parent 6773e1f commit 58ccfa2

3 files changed

Lines changed: 30 additions & 22 deletions

File tree

src/components/_classes/component/Component.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { GlobalFormio as Formio } from '../../../Formio';
88
import * as FormioUtils from '../../../utils/utils';
99
import Validator from '../../../validator/Validator';
1010
import {
11-
fastCloneDeep, boolValue, getComponentPath, isInsideScopingComponent,
11+
fastCloneDeep, boolValue, getComponentPath, isInsideScopingComponent, currentTimezone
1212
} from '../../../utils/utils';
1313
import Element from '../../../Element';
1414
import ComponentModal from '../componentModal/ComponentModal';
@@ -1031,6 +1031,28 @@ export default class Component extends Element {
10311031
return this.options.submissionTimezone;
10321032
}
10331033

1034+
get timezone() {
1035+
if (this.component.timezone) {
1036+
return this.component.timezone;
1037+
}
1038+
if (this.component.displayInTimezone === 'utc') {
1039+
return 'UTC';
1040+
}
1041+
const submissionTimezone = this.submissionTimezone;
1042+
if (
1043+
submissionTimezone &&
1044+
(
1045+
(this.component.displayInTimezone === 'submission') ||
1046+
((this.options.pdf || this.options.server) && (this.component.displayInTimezone === 'viewer'))
1047+
)
1048+
) {
1049+
return submissionTimezone;
1050+
}
1051+
1052+
// Return current timezone if none are provided.
1053+
return currentTimezone();
1054+
}
1055+
10341056
loadRefs(element, refs) {
10351057
for (const ref in refs) {
10361058
const refType = refs[ref];

src/components/datetime/DateTime.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,12 @@ export default class DateTimeComponent extends Input {
168168
}
169169

170170
getValueAsString(value) {
171-
const format = FormioUtils.convertFormatToMoment(this.component.format);
172-
if (value && !this.attached && this.submissionTimezone) {
173-
return FormioUtils.momentDate(value, format, this.submissionTimezone).format(format);
171+
let format = FormioUtils.convertFormatToMoment(this.component.format);
172+
format += format.match(/z$/) ? '' : ' z';
173+
const timezone = this.timezone;
174+
if (value && !this.attached && timezone) {
175+
return _.trim(FormioUtils.momentDate(value, format, timezone).format(format));
174176
}
175-
return (value ? moment(value).format(format) : value) || '';
177+
return (value ? _.trim(moment(value).format(format)) : value) || '';
176178
}
177179
}

src/widgets/CalendarWidget.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
convertFormatToFlatpickr,
55
convertFormatToMask,
66
convertFormatToMoment,
7-
currentTimezone,
87
formatDate,
98
formatOffset,
109
getBrowserInfo,
@@ -228,23 +227,8 @@ export default class CalendarWidget extends InputWidget {
228227
});
229228
}
230229

231-
defineTimezone() {
232-
if (this.settings.timezone) {
233-
return this.settings.timezone;
234-
}
235-
if (this.settings.displayInTimezone === 'submission') {
236-
return this.componentInstance.submissionTimezone;
237-
}
238-
if (this.settings.displayInTimezone === 'utc') {
239-
return 'UTC';
240-
}
241-
242-
// Return current timezone if none are provided.
243-
return currentTimezone();
244-
}
245-
246230
get timezone() {
247-
return this.defineTimezone();
231+
return this.componentInstance.timezone;
248232
}
249233

250234
get defaultSettings() {

0 commit comments

Comments
 (0)