Skip to content

Instantly share code, notes, and snippets.

@capaj
Created October 19, 2020 12:34
Show Gist options
  • Save capaj/2435a3e0615987b9165e26c561626382 to your computer and use it in GitHub Desktop.
Save capaj/2435a3e0615987b9165e26c561626382 to your computer and use it in GitHub Desktop.
import moment from 'moment-timezone'
export const shiftUtcDayTimeToTimezone = (
utcDayTime: string,
timezone: string
) => {
const offsetMinutes = moment.tz(moment.utc(), timezone).utcOffset()
const [hours, minutes] = utcDayTime.split(':')
const quotient = Math.floor(offsetMinutes / 60)
const remainder = offsetMinutes % 60
return `${Number(hours) + quotient}:${Number(minutes) + remainder}`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment