Skip to content

Commit

Permalink
merge agreenspan24:ag/timezone-fixes into stage-main-10-a
Browse files Browse the repository at this point in the history
  • Loading branch information
schuyler1d committed Dec 3, 2020
2 parents aba1cea + eb6b4dc commit 08b11ce
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 63 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ EMAIL_HOST_USER=
EMAIL_HOST_PORT=
EMAIL_FROM=
TWILIO_MESSAGE_VALIDITY_PERIOD=
DST_REFERENCE_TIMEZONE='America/New_York'
DST_REFERENCE_TIMEZONE='US/Eastern'
DEFAULT_TZ='US/Eastern'
PASSPORT_STRATEGY=local
TEXTER_SIDEBOXES=celebration-gif,default-dynamicassignment,default-releasecontacts,contact-reference,tag-contact,freshworks-widget,default-editinitial,take-conversations
OWNER_CONFIGURABLE=ALL
28 changes: 10 additions & 18 deletions __test__/lib/dst-helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,18 @@ describe("test DstHelper", () => {

it("helps us figure out if we're in DST in February in New York", () => {
MockDate.set("2018-02-01T15:00:00Z");
let d = new DateTime(
new Date(),
DateFunctions.Get,
zone("America/New_York")
);
expect(DstHelper.isOffsetDst(d.offset(), "America/New_York")).toBeFalsy();
expect(DstHelper.isDateTimeDst(d, "America/New_York")).toBeFalsy();
expect(DstHelper.isDateDst(new Date(), "America/New_York")).toBeFalsy();
let d = new DateTime(new Date(), DateFunctions.Get, zone("US/Eastern"));
expect(DstHelper.isOffsetDst(d.offset(), "US/Eastern")).toBeFalsy();
expect(DstHelper.isDateTimeDst(d, "US/Eastern")).toBeFalsy();
expect(DstHelper.isDateDst(new Date(), "US/Eastern")).toBeFalsy();
});

it("helps us figure out if we're in DST in July in New York", () => {
MockDate.set("2018-07-21T15:00:00Z");
let d = new DateTime(
new Date(),
DateFunctions.Get,
zone("America/New_York")
);
expect(DstHelper.isOffsetDst(d.offset(), "America/New_York")).toBeTruthy();
expect(DstHelper.isDateTimeDst(d, "America/New_York")).toBeTruthy();
expect(DstHelper.isDateDst(new Date(), "America/New_York")).toBeTruthy();
let d = new DateTime(new Date(), DateFunctions.Get, zone("US/Eastern"));
expect(DstHelper.isOffsetDst(d.offset(), "US/Eastern")).toBeTruthy();
expect(DstHelper.isDateTimeDst(d, "US/Eastern")).toBeTruthy();
expect(DstHelper.isDateDst(new Date(), "US/Eastern")).toBeTruthy();
});

it("helps us figure out if we're in DST in February in Sydney", () => {
Expand Down Expand Up @@ -89,8 +81,8 @@ describe("test DstHelper", () => {
});

it("correctly reports a timezone's offset and whether it has DST", () => {
expect(DstHelper.getTimezoneOffsetHours("America/New_York")).toEqual(-5);
expect(DstHelper.timezoneHasDst("America/New_York")).toBeTruthy();
expect(DstHelper.getTimezoneOffsetHours("US/Eastern")).toEqual(-5);
expect(DstHelper.timezoneHasDst("US/Eastern")).toBeTruthy();
expect(DstHelper.getTimezoneOffsetHours("US/Arizona")).toEqual(-7);
expect(DstHelper.timezoneHasDst("US/Arizona")).toBeFalsy();
expect(DstHelper.getTimezoneOffsetHours("Europe/Paris")).toEqual(1);
Expand Down
64 changes: 36 additions & 28 deletions __test__/lib/timezones.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const buildIsBetweenTextingHoursExpectWithNoOffset = (start, end) => {
0,
0,
false,
makeCampignTextingHoursConfig(true, start, end, "America/New_York")
makeCampignTextingHoursConfig(true, start, end, "US/Eastern")
)
)
);
Expand Down Expand Up @@ -566,7 +566,11 @@ describe("test defaultTimezoneIsBetweenTextingHours", () => {

describe("test convertOffsetsToStrings", () => {
it("works", () => {
let test_offsets = [[1, true], [2, false], [-1, true]];
let test_offsets = [
[1, true],
[2, false],
[-1, true]
];
let strings_returned = convertOffsetsToStrings(test_offsets);
expect(strings_returned).toHaveLength(3);
expect(strings_returned[0]).toBe("1_1");
Expand Down Expand Up @@ -664,7 +668,7 @@ describe("test getContactTimezone", () => {
true,
14,
16,
"America/New_York"
"US/Eastern"
),
{}
)
Expand Down Expand Up @@ -885,7 +889,11 @@ describe("test defaultTimezoneIsBetweenTextingHours", () => {

describe("test convertOffsetsToStrings", () => {
it("works", () => {
let test_offsets = [[1, true], [2, false], [-1, true]];
let test_offsets = [
[1, true],
[2, false],
[-1, true]
];
let strings_returned = convertOffsetsToStrings(test_offsets);
expect(strings_returned).toHaveLength(3);
expect(strings_returned[0]).toBe("1_1");
Expand Down Expand Up @@ -983,7 +991,7 @@ describe("test getContactTimezone", () => {
true,
14,
16,
"America/New_York"
"US/Eastern"
),
{}
)
Expand All @@ -1004,7 +1012,7 @@ describe("test getContactTimezone", () => {
true,
14,
16,
"America/New_York"
"US/Eastern"
),
{}
)
Expand All @@ -1024,7 +1032,7 @@ describe("test getContactTimezone", () => {
true,
14,
16,
"America/New_York"
"US/Eastern"
),
{}
)
Expand All @@ -1044,37 +1052,37 @@ describe("test getUtcFromOffsetAndHour", () => {

it("returns the correct UTC during northern hemisphere summer", () => {
MockDate.set("2018-07-01T11:00:00.000-05:00");
expect(
getUtcFromOffsetAndHour(-5, true, 12, "America/New_York").unix()
).toEqual(moment("2018-07-01T16:00:00.000Z").unix());
expect(getUtcFromOffsetAndHour(-5, true, 12, "US/Eastern").unix()).toEqual(
moment("2018-07-01T16:00:00.000Z").unix()
);
});

it("returns the correct UTC during northern hemisphere summer with result being next day", () => {
MockDate.set("2018-07-01T11:00:00.000-05:00");
expect(
getUtcFromOffsetAndHour(-5, true, 23, "America/New_York").unix()
).toEqual(moment("2018-07-02T03:00:00.000Z").unix());
expect(getUtcFromOffsetAndHour(-5, true, 23, "US/Eastern").unix()).toEqual(
moment("2018-07-02T03:00:00.000Z").unix()
);
});

it("returns the correct UTC during northern hemisphere winter", () => {
MockDate.set("2018-02-01T11:00:00.000-05:00");
expect(
getUtcFromOffsetAndHour(-5, true, 12, "America/New_York").unix()
).toEqual(moment("2018-02-01T17:00:00.000Z").unix());
expect(getUtcFromOffsetAndHour(-5, true, 12, "US/Eastern").unix()).toEqual(
moment("2018-02-01T17:00:00.000Z").unix()
);
});

it("returns the correct UTC during northern hemisphere summer if offset doesn't have DST", () => {
MockDate.set("2018-07-01T11:00:00.000-05:00");
expect(
getUtcFromOffsetAndHour(-5, false, 12, "America/New_York").unix()
).toEqual(moment("2018-07-01T17:00:00.000Z").unix());
expect(getUtcFromOffsetAndHour(-5, false, 12, "US/Eastern").unix()).toEqual(
moment("2018-07-01T17:00:00.000Z").unix()
);
});

it("returns the correct UTC during northern hemisphere winter if offset doesn't have DST", () => {
MockDate.set("2018-02-01T11:00:00.000-05:00");
expect(
getUtcFromOffsetAndHour(-5, false, 12, "America/New_York").unix()
).toEqual(moment("2018-02-01T17:00:00.000Z").unix());
expect(getUtcFromOffsetAndHour(-5, false, 12, "US/Eastern").unix()).toEqual(
moment("2018-02-01T17:00:00.000Z").unix()
);
});
});

Expand All @@ -1085,21 +1093,21 @@ describe("test getUtcFromTimezoneAndHour", () => {

it("returns the correct UTC during northern hemisphere summer", () => {
MockDate.set("2018-07-01T11:00:00.000-05:00");
expect(getUtcFromTimezoneAndHour("America/New_York", 12).unix()).toEqual(
expect(getUtcFromTimezoneAndHour("US/Eastern", 12).unix()).toEqual(
moment("2018-07-01T16:00:00.000Z").unix()
);
});

it("returns the correct UTC during northern hemisphere summer with result being next day", () => {
MockDate.set("2018-07-01T11:00:00.000-05:00");
expect(getUtcFromTimezoneAndHour("America/New_York", 23).unix()).toEqual(
expect(getUtcFromTimezoneAndHour("US/Eastern", 23).unix()).toEqual(
moment("2018-07-02T03:00:00.000Z").unix()
);
});

it("returns the correct UTC during northern hemisphere winter", () => {
MockDate.set("2018-02-01T11:00:00.000-05:00");
expect(getUtcFromTimezoneAndHour("America/New_York", 12).unix()).toEqual(
expect(getUtcFromTimezoneAndHour("US/Eastern", 12).unix()).toEqual(
moment("2018-02-01T17:00:00.000Z").unix()
);
});
Expand Down Expand Up @@ -1171,7 +1179,7 @@ describe("test getSendBeforeTimewUtc", () => {
overrideOrganizationTextingHours: true,
textingHoursEnforced: true,
textingHoursEnd: 21,
timezone: "America/New_York"
timezone: "US/Eastern"
}
).unix()
).toEqual(moment("2018-09-04T01:00:00.000Z").unix());
Expand All @@ -1190,14 +1198,14 @@ describe("test getSendBeforeTimewUtc", () => {
overrideOrganizationTextingHours: true,
textingHoursEnforced: true,
textingHoursEnd: 21,
timezone: "America/New_York"
timezone: "US/Eastern"
}
).unix()
).toEqual(moment("2018-09-04T01:00:00.000Z").unix());
});

it("returns correct time if campaign does not override and TZ is set", () => {
tzHelpers.getProcessEnvTz.mockImplementation(() => "America/New_York");
tzHelpers.getProcessEnvTz.mockImplementation(() => "US/Eastern");
expect(
getSendBeforeTimeUtc(
{},
Expand Down
2 changes: 1 addition & 1 deletion __test__/lib/tz-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ jest.unmock("../../src/lib/tz-helpers");

describe("test getProcessEnvDstReferenceTimezone", () => {
it("works", () => {
expect(getProcessEnvDstReferenceTimezone()).toEqual("America/New_York");
expect(getProcessEnvDstReferenceTimezone()).toEqual("US/Eastern");
});
});
8 changes: 7 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,13 @@
"DST_REFERENCE_TIMEZONE": {
"description": "Timezone to use to determine whether DST is in effect for a date",
"required": true,
"value": "America/New_York"
"value": "US/Eastern"
},

"DEFAULT_TZ": {
"description": "Timezone",
"required": true,
"value": "US/Eastern"
},

"HEROKU_APP_NAME": {
Expand Down
6 changes: 3 additions & 3 deletions deploy/lambda-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"ROLLBAR_CLIENT_TOKEN": "set_this_in_production",
"ROLLBAR_ACCESS_TOKEN": "set_this_in_production",
"ROLLBAR_ENDPOINT": "https://api.rollbar.com/api/1/item/",
"DST_REFERENCE_TIMEZONE": "America/New_York",
"TZ": "America/New_York",
"PHONE_NUMBER_COUNTRY": "US"
"PHONE_NUMBER_COUNTRY": "US",
"DST_REFERENCE_TIMEZONE": "US/Eastern",
"TZ": "US/Eastern"
}
2 changes: 1 addition & 1 deletion deploy/spoke-pm2.config.js.template
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const env_production = {
ROLLBAR_ACCESS_TOKEN:'',
ROLLBAR_ENDPOINT:'https://api.rollbar.com/api/1/item/',
ALLOW_SEND_ALL: false,
DST_REFERENCE_TIMEZONE: 'America/New_York'
DST_REFERENCE_TIMEZONE: 'US/Eastern'
}

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion docs/HOWTO_TEXTING_HOURS_ENFORCEMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Spoke will not send texts to contacts before the start time or after the end tim

If the `TZ` environment variable is set, Spoke will assume that all contacts are located in the time zone specified by the variable. The current time in that time zone -- with Daylight Savings applied if it is summer in that area and the time zone has Daylight Savings Time -- is considered the current time for purposes of deciding whether it is OK to send texts.

The timezone in New York City is specified by the string `America/New_York`. Other time zone names are listed [here.](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
The timezone in New York City is specified by the string `US/Eastern`. Other time zone names are listed [here.](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)

## Contact ZIP code

Expand Down
2 changes: 1 addition & 1 deletion docs/REFERENCE-environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
| DOWNTIME | When enabled it will redirect users to a /downtime page. If set to a string, it will show the string as a message to users on the downtime page. Use this to take the system down for maintenance. It will NOT stop graphql requests and will NOT stop users that are already in the app. |
| DOWNTIME_NO_DB | On AWS Lambda this blocks the site from loading the app at all and swaps out a system that redirects users to /downtime. This is useful for DB maintenance. For non-Lambda environments, just run the src/server/downtime app instead of src/server/index default app |
| DOWNTIME_TEXTER | Setting DOWNTIME_TEXTER to a text message (without quotes, please) will give the message as a text to texters when they arrive on the site, but the admin pages will still be accessible. This could be useful if you want to stop new texters from landing on the site and texting, while you debug things. |
| DST_REFERENCE_TIMEZONE | Timezone to use to determine whether DST is in effect. If it's DST in this timezone, we assume it's DST everywhere. _Default_: "America/New_York". (The default will work for any campaign in the US. For example, if the campaign is in Australia, use "Australia/Sydney" or some other timezone in Australia. Note that DST is opposite in the northern and souther hemispheres.) |
| DST_REFERENCE_TIMEZONE | Timezone to use to determine whether DST is in effect. If it's DST in this timezone, we assume it's DST everywhere. _Default_: "US/Eastern". (The default will work for any campaign in the US. For example, if the campaign is in Australia, use "Australia/Sydney" or some other timezone in Australia. Note that DST is opposite in the northern and souther hemispheres.) |
| EMAIL_FROM | Email from address. _Required to send email from either Mailgun **or** a custom SMTP server_. |
| EMAIL_HOST | Email server host. _Required for custom SMTP server usage_. |
| EMAIL_HOST_PASSWORD | Email server password. _Required for custom SMTP server usage_. |
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
JOBS_SAME_PROCESS: "1",
RETHINK_KNEX_NOREFS: "1", // avoids db race conditions
DEFAULT_SERVICE: "fakeservice",
DST_REFERENCE_TIMEZONE: "America/New_York",
DST_REFERENCE_TIMEZONE: "US/Eastern",
DATABASE_SETUP_TEARDOWN_TIMEOUT: 60000,
PASSPORT_STRATEGY: "local",
SESSION_SECRET: "it is JUST a test! -- it better be!",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/__mocks__/tz-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const tzHelpers = jest.genMockFromModule("../tz-helpers");

tzHelpers.getProcessEnvDstReferenceTimezone = () => "America/New_York";
tzHelpers.getProcessEnvDstReferenceTimezone = () => "US/Eastern";

module.exports = tzHelpers;
5 changes: 4 additions & 1 deletion src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export {
getUtcFromOffsetAndHour,
getSendBeforeTimeUtc
} from "./timezones";
export { getProcessEnvTz } from "./tz-helpers";
export {
getProcessEnvTz,
getProcessEnvDstReferenceTimezone
} from "./tz-helpers";
export { DstHelper } from "./dst-helper";
export { isClient } from "./is-client";
import { log } from "./log";
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tz-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export function getProcessEnvDstReferenceTimezone() {
return (
process.env.DST_REFERENCE_TIMEZONE ||
global.DST_REFERENCE_TIMEZONE ||
"America/New_York"
"US/Eastern"
);
}
3 changes: 2 additions & 1 deletion src/server/api/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,8 @@ const rootMutations = {
response_window: getConfig("DEFAULT_RESPONSEWINDOW", organization, {
default: 48
}),
use_own_messaging_service: false
use_own_messaging_service: false,
timezone: getConfig("DST_REFERENCE_TIMEZONE", organization)
});
const newCampaign = await campaignInstance.save();
await r.knex("campaign_admin").insert({
Expand Down
7 changes: 4 additions & 3 deletions src/server/middleware/render-index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { hasConfig, getConfig } from "../api/lib/config";
import { getProcessEnvTz, getProcessEnvDstReferenceTimezone } from "../../lib";

const canGoogleImport = hasConfig("GOOGLE_SECRET");

Expand Down Expand Up @@ -83,11 +84,11 @@ export default function renderIndex(html, css, assetMap) {
window.TERMS_REQUIRE=${getConfig("TERMS_REQUIRE", null, {
truthy: 1
}) || false}
window.TZ="${process.env.TZ || ""}"
window.TZ="${getProcessEnvTz() || ""}"
window.CONTACT_LOADERS="${process.env.CONTACT_LOADERS ||
"csv-upload,test-fakedata,datawarehouse"}"
window.DST_REFERENCE_TIMEZONE="${process.env.DST_REFERENCE_TIMEZONE ||
"America/New_York"}"
window.DST_REFERENCE_TIMEZONE="${getProcessEnvDstReferenceTimezone() ||
"US/Eastern"}"
window.PASSPORT_STRATEGY="${process.env.PASSPORT_STRATEGY || "auth0"}"
window.PEOPLE_PAGE_CAMPAIGN_FILTER_SORT = "${process.env
.PEOPLE_PAGE_CAMPAIGN_FILTER_SORT || ""}"
Expand Down

0 comments on commit 08b11ce

Please sign in to comment.