Skip to content

Commit

Permalink
Timezone fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrand committed Jan 21, 2021
1 parent 18449c9 commit 867b31c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
24 changes: 11 additions & 13 deletions src/lib/timezones.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { DstHelper } from "./dst-helper";
import { getConfig } from "../server/api/lib/config";

const TIMEZONE_CONFIG = {
const TIMEZONE_US_FALLBACK_WINDOW = {
missingTimeZone: {
offset: -5, // EST
hasDST: true,
Expand All @@ -31,8 +31,8 @@ export const getContactTimezone = (campaign, location) => {
const hasDST = DstHelper.timezoneHasDst(getProcessEnvTz());
timezoneData = { offset, hasDST };
} else {
const offset = TIMEZONE_CONFIG.missingTimeZone.offset;
const hasDST = TIMEZONE_CONFIG.missingTimeZone.hasDST;
const offset = TIMEZONE_US_FALLBACK_WINDOW.missingTimeZone.offset;
const hasDST = TIMEZONE_US_FALLBACK_WINDOW.missingTimeZone.hasDST;
timezoneData = { offset, hasDST };
}
returnLocation.timezone = timezoneData;
Expand Down Expand Up @@ -97,24 +97,22 @@ export const getSendBeforeTimeUtc = (
const defaultTimezone = getProcessEnvTz(
getConfig("DEFAULT_TZ", organization)
);
if (defaultTimezone) {
return getUtcFromTimezoneAndHour(
defaultTimezone,
organization.textingHoursEnd
);
}

if (contactTimezone && contactTimezone.offset) {
return getUtcFromOffsetAndHour(
contactTimezone.offset,
contactTimezone.hasDST,
organization.textingHoursEnd,
getProcessEnvDstReferenceTimezone()
);
} else if (defaultTimezone) {
return getUtcFromTimezoneAndHour(
defaultTimezone,
organization.textingHoursEnd
);
} else {
return getUtcFromOffsetAndHour(
TIMEZONE_CONFIG.missingTimeZone.offset,
TIMEZONE_CONFIG.missingTimeZone.hasDST,
TIMEZONE_US_FALLBACK_WINDOW.missingTimeZone.offset,
TIMEZONE_US_FALLBACK_WINDOW.missingTimeZone.hasDST,
organization.textingHoursEnd,
getProcessEnvDstReferenceTimezone()
);
Expand Down Expand Up @@ -202,7 +200,7 @@ export const isBetweenTextingHours = (offsetData, config) => {
offsetData,
config.textingHoursStart,
config.textingHoursEnd,
TIMEZONE_CONFIG.missingTimeZone,
TIMEZONE_US_FALLBACK_WINDOW.missingTimeZone,
getProcessEnvDstReferenceTimezone()
);
};
Expand Down
5 changes: 2 additions & 3 deletions src/lib/tz-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ export function getProcessEnvTz(defaultTimezone) {
// TZ is a reserved env var in Lambda and always returns :UTC
return (
defaultTimezone ||
(process.env.TZ === ":UTC"
? process.env.DEFAULT_TZ
: process.env.DEFAULT_TZ || process.env.TZ)
process.env.DEFAULT_TZ ||
(process.env.TZ === ":UTC" ? undefined : process.env.TZ)
);
}

Expand Down

0 comments on commit 867b31c

Please sign in to comment.