Skip to content

Commit

Permalink
chore: validate that we are running on a UTC system (#1046)
Browse files Browse the repository at this point in the history
If not, the output of `node-ical` cannot be trusted, and it's
very confusing when that happens. Until the bug gets fixed upstream,
or we switch libraries, let's just throw a loud and accurate error.


-----

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
rix0rrr committed Oct 14, 2021
1 parent 9031548 commit 482d699
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/__tests__/expected.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4288,7 +4288,7 @@ Resources:
Properties:
Code:
S3Bucket: cdk-hnb659fds-assets-712950704752-us-east-1
S3Key: ff9251e1c9991e0788c269b3f4daac2ef4701a3e98de0bb0a1aedae2bb35a514.zip
S3Key: d81bf2d4c389ecd69472cf4b27599e1ffbe0c1543104f45d035834e863f64ca7.zip
Role:
Fn::GetAtt:
- CodeCommitPipelineChangeControllerFunctionServiceRoleF02841DB
Expand Down
7 changes: 7 additions & 0 deletions lib/change-control-lambda/time-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Events = { [uuid: string]: CalendarEvent };
* @returns the events that represent the blocked time, or `undefined` if `now` is not "blocked".
*/
export function shouldBlockPipeline(icalData: string | Buffer, now = new Date(), advanceMarginSec = 3600): CalendarEvent | undefined {
validateTz();
const events: Events = ical.parseICS(icalData.toString('utf8'));
const blocks = containingEventsWithMargin(events, now, advanceMarginSec);
return blocks.length > 0 ? blocks[0] : undefined;
Expand Down Expand Up @@ -140,3 +141,9 @@ function overlaps(left: { start: Date; end: Date }, right: { start: Date; end: D
function isBetween(date: Date, left: Date, right: Date): boolean {
return date >= left && date <= right;
}

function validateTz() {
if (new Date().getTimezoneOffset() !== 0) {
throw new Error('Because of a bug in "node-ical", this module can only be used when the system time zone is set to UTC. Run this command again with "TZ=UTC"');
}
}

0 comments on commit 482d699

Please sign in to comment.