Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //get duration between 0:00:00 UTC and start shift by UTC
- func getUTCDiffStartShift(loc string, startShift time.Duration) (time.Duration, error) {
- locDiff, err := getLocationDiff(loc)
- if err != nil {
- return time.Duration(0), fmt.Errorf("can not diff between 0:00:00 and start shift: %v", err)
- }
- return startShift - locDiff, nil
- }
- //get different between UTC and location as duration
- func getLocationDiff(loc string) (time.Duration, error) {
- location, err := time.LoadLocation(loc)
- if err != nil {
- return time.Duration(0), err
- }
- in := time.Now().In(location)
- locDiff, err := strconv.ParseFloat(in.Format("-07"), 64)
- if err != nil {
- return time.Duration(0), err
- }
- return time.Duration(locDiff) * time.Hour, nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement