UNPKG

@shipengine/connect

Version:

The official developer tooling for building ShipEngine connect apps

95 lines 3.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTimeTitle = exports.initializeTimeStamps = void 0; const luxon_1 = require("luxon"); // TODO: ASSUMPTION: currently all the timestamps are based off of the origin addresses' timezone, research whether that is common for most carriers? function initializeTimeStamps() { const date = new Date(); // TODO: Get more business logic and see if these time stamps are accurate const yesterday = luxon_1.DateTime.local(date.getFullYear(), date.getMonth() + 1, date.getDate()) .plus({ hours: 12 }) .minus({ days: 1 }) .toISO(); const todayEarly = luxon_1.DateTime.local(date.getFullYear(), date.getMonth() + 1, date.getDate()) .plus({ hours: 6 }) .toISO(); const today = luxon_1.DateTime.local(date.getFullYear(), date.getMonth() + 1, date.getDate()) .plus({ hours: 12 }) .toISO(); const todayEvening = luxon_1.DateTime.local(date.getFullYear(), date.getMonth() + 1, date.getDate()) .plus({ hours: 18 }) .toISO(); const tomorrowEarlyAM = luxon_1.DateTime.local(date.getFullYear(), date.getMonth() + 1, date.getDate()) .plus({ days: 1, hours: 6 }) .toISO(); const tomorrowEarly = luxon_1.DateTime.local(date.getFullYear(), date.getMonth() + 1, date.getDate()) .plus({ days: 1, hours: 9 }) .toISO(); const tomorrow = luxon_1.DateTime.local(date.getFullYear(), date.getMonth() + 1, date.getDate()) .plus({ days: 1, hours: 12 }) .toISO(); const tomorrowEvening = luxon_1.DateTime.local(date.getFullYear(), date.getMonth() + 1, date.getDate()) .plus({ days: 1, hours: 18 }) .toISO(); const twoDays = luxon_1.DateTime.local(date.getFullYear(), date.getMonth() + 1, date.getDate()) .plus({ days: 2, hours: 12 }) .toISO(); const twoDaysEarly = luxon_1.DateTime.local(date.getFullYear(), date.getMonth() + 1, date.getDate()) .plus({ days: 2, hours: 9 }) .toISO(); const threeDays = luxon_1.DateTime.local(date.getFullYear(), date.getMonth() + 1, date.getDate()) .plus({ days: 3 }) .toISO(); const timeStamps = { yesterday, todayEarly, today, todayEvening, tomorrowEarly, tomorrowEarlyAM, tomorrow, tomorrowEvening, twoDays, twoDaysEarly, threeDays, }; for (const key of Object.keys(timeStamps)) { if (Reflect.get(timeStamps, key) === null) { throw new Error(`Unable to properly instantiate ${key} time stamp`); } } return timeStamps; } exports.initializeTimeStamps = initializeTimeStamps; function getTimeTitle(date, timeStamps) { if (date === timeStamps.yesterday) { return 'Yesterday'; } if (date === timeStamps.todayEarly) { return 'Today Early'; } if (date === timeStamps.today) { return 'Today'; } if (date === timeStamps.todayEvening) { return 'Today Evening'; } if (date === timeStamps.tomorrowEarly) { return 'Tomorrow Early'; } if (date === timeStamps.tomorrowEarlyAM) { return 'Tomorrow Early'; } if (date === timeStamps.tomorrow) { return 'Tomorrow'; } if (date === timeStamps.twoDays) { return 'Two Days'; } if (date === timeStamps.twoDaysEarly) { return 'Two Days Early'; } return 'Three Days'; } exports.getTimeTitle = getTimeTitle; //# sourceMappingURL=time-stamps.js.map