Skip to content

Instantly share code, notes, and snippets.

@aeppert
Created January 12, 2017 21:14
Show Gist options
  • Select an option

  • Save aeppert/5b2eba9e966f418e15fbc807bbf757db to your computer and use it in GitHub Desktop.

Select an option

Save aeppert/5b2eba9e966f418e15fbc807bbf757db to your computer and use it in GitHub Desktop.
Return the time.Time between passed in time and duration string (m,h,s, etc.)
package main
import (
"fmt"
"time"
)
func getDurationDiff(t time.Time, duration string) (time.Time, error) {
dur, err := time.ParseDuration(fmt.Sprintf("-%s", duration))
if err != nil {
return time.Now(), err
}
then := t.Add(dur)
return then, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment