This Gist was automatically created by Carbide, a free online programming environment.
Last active
January 7, 2019 17:10
-
-
Save carbide-public/3ffcb3defd1f3e891e5459e30ab4f8b9 to your computer and use it in GitHub Desktop.
untitled
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
import moment from 'moment-timezone'; | |
import verifyVisitationTime from './verifyVisitationTime'; | |
const visitationTime = moment("2019-01-07T11:00:00-06:00"); // now, for the local timezone. But you can change that with now.tz('Asia/Tokyo'); | |
const visitationTimef = visitationTime.format(); | |
const deliveryTime = moment("2019-01-07T15:00:00-06:00"); | |
const deliveryTimef = deliveryTime.format(); | |
const verified = verifyVisitationTime(deliveryTime, visitationTime); // true because more than three hours difference | |
const slowDeliveryTime = verifyVisitationTime(deliveryTime, visitationTime, 10); // false because less than 10 hours difference |
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
export const msPerSec = 1000; | |
export const secPerMin = 60; | |
export const minPerHour = 60; | |
export const toHours = (ms) => ms / msPerSec / secPerMin / minPerHour; | |
export default toHours; |
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
import moment from 'moment-timezone'; | |
import msToHours from './toHours'; | |
export const verifyVisitationTime = ( deliveryTime, visitationTime, minBusinessHrsForDelivery = 3 ) => { | |
const formatted = deliveryTime.format(); | |
const diff = deliveryTime - visitationTime; | |
const hours = msToHours(diff); | |
console.log(`hours: ${hours}`); | |
const verified = hours >= minBusinessHrsForDelivery; | |
return verified; | |
}; | |
export default verifyVisitationTime; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment