-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #407 from Enterprise-CMCS/master
Release to val
- Loading branch information
Showing
11 changed files
with
126 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,55 @@ | ||
import moment from "moment-timezone"; | ||
import * as fedHolidays from '@18f/us-federal-holidays'; | ||
import * as fedHolidays from "@18f/us-federal-holidays"; | ||
|
||
// Takes a local epoch for a moment in time, and returns the UTC epoch for that same moment | ||
export const offsetToUtc = (date: Date): Date => { | ||
return new Date(date.getTime() - date.getTimezoneOffset() * 60000); | ||
}; | ||
|
||
// This manually accounts for the offset between the client's timezone and UTC. | ||
export const offsetForUtc = (date: Date): Date => { | ||
return new Date(date.getTime() - (date.getTimezoneOffset() * 60000)); | ||
} | ||
// Takes a UTC epoch for a moment in time, and returns the local epoch for that same moment | ||
export const offsetFromUtc = (date: Date): Date => { | ||
return new Date(date.getTime() + date.getTimezoneOffset() * 60000); | ||
}; | ||
|
||
// This creates a Date for midnight today, then accounts for timezone offset. | ||
export const seaToolFriendlyTimestamp = (date?: Date): number => { | ||
// If you don't pass a date, we assume you want today the timestamp for today, midnight, utc. | ||
if(!date) { | ||
if (!date) { | ||
date = new Date(); | ||
date.setHours(0,0,0,0); | ||
date.setHours(0, 0, 0, 0); | ||
} | ||
return offsetForUtc(date).getTime(); | ||
return offsetToUtc(date).getTime(); | ||
}; | ||
|
||
// This takes an epoch string and converts it to a standard format for display | ||
export const formatSeatoolDate = (date: string): string => { | ||
return moment(date).tz("UTC").format("MM/DD/yyyy") | ||
} | ||
return moment(date).tz("UTC").format("MM/DD/yyyy"); | ||
}; | ||
|
||
export const getNextBusinessDayTimestamp = (date: Date = new Date()): number => { | ||
let localeStringDate = date.toLocaleString("en-US", { timeZone: "America/New_York", dateStyle: "short" }); | ||
let localeStringHours24 = date.toLocaleString("en-US", { timeZone: "America/New_York", hour: 'numeric', hour12: false }); | ||
export const getNextBusinessDayTimestamp = ( | ||
date: Date = new Date() | ||
): number => { | ||
let localeStringDate = date.toLocaleString("en-US", { | ||
timeZone: "America/New_York", | ||
dateStyle: "short", | ||
}); | ||
let localeStringHours24 = date.toLocaleString("en-US", { | ||
timeZone: "America/New_York", | ||
hour: "numeric", | ||
hour12: false, | ||
}); | ||
let localeDate = new Date(localeStringDate); | ||
|
||
console.log(`Evaluating ${localeStringDate} at ${localeStringHours24}`); | ||
|
||
const after5pmEST = parseInt(localeStringHours24,10) >= 17 | ||
const isHoliday = fedHolidays.isAHoliday(localeDate) | ||
const isWeekend = !(localeDate.getDay() % 6) | ||
if(after5pmEST || isHoliday || isWeekend) { | ||
const after5pmEST = parseInt(localeStringHours24, 10) >= 17; | ||
const isHoliday = fedHolidays.isAHoliday(localeDate); | ||
const isWeekend = !(localeDate.getDay() % 6); | ||
if (after5pmEST || isHoliday || isWeekend) { | ||
let nextDate = localeDate; | ||
nextDate.setDate(nextDate.getDate() + 1); | ||
nextDate.setHours(12,0,0,0) | ||
console.log("Current date is not valid. Will try " + nextDate) | ||
return getNextBusinessDayTimestamp(nextDate) | ||
nextDate.setHours(12, 0, 0, 0); | ||
return getNextBusinessDayTimestamp(nextDate); | ||
} | ||
|
||
// Return the next business day's epoch for midnight UTC | ||
let ret = offsetForUtc(localeDate).getTime(); | ||
console.log('Current date is a valid business date. Will return ' + ret); | ||
let ret = offsetToUtc(localeDate).getTime(); | ||
return ret; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { response } from "../libs/handler"; | ||
import { APIGatewayEvent } from "aws-lambda"; | ||
import * as os from "../../../libs/opensearch-lib"; | ||
|
||
export const handler = async (event: APIGatewayEvent) => { | ||
if (!event.body) { | ||
return response({ | ||
statusCode: 400, | ||
body: { message: "Event body required" }, | ||
}); | ||
} | ||
try { | ||
const body = JSON.parse(event.body); | ||
const packageResult = await os.search(process.env.osDomain!, "main", { | ||
query: { | ||
match_phrase: { | ||
id: { | ||
query: body.id, | ||
}, | ||
}, | ||
}, | ||
}); | ||
if (packageResult?.hits.total.value == 0) { | ||
return response({ | ||
statusCode: 200, | ||
body: { message: "No record found for the given id", exists: false }, | ||
}); | ||
} else { | ||
return response({ | ||
statusCode: 200, | ||
body: { message: "Record found for the given id", exists: true }, | ||
}); | ||
} | ||
} catch (error) { | ||
console.error({ error }); | ||
return response({ | ||
statusCode: 500, | ||
body: { message: "Internal server error" }, | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { API } from "aws-amplify"; | ||
|
||
export const itemExists = async (id: string): Promise<boolean> => { | ||
const response = await API.post("os", "/itemExists", { body: { id } }); | ||
return response.exists; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters