Skip to content

Commit

Permalink
Add AsTimeRawWithLoc and fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
neomantra committed Nov 28, 2023
1 parent 8e5bf13 commit 420e341
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ymdflag.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,13 @@ func (ymd *YMDFlag) UpdateNilToNow(location *time.Location) {
}

// AsTime returns the YMDFlag as a `time.Time“ in local time. Use `AsTimeWithLoc` to specify a location.
// If the YMDFlag's `yyyymmdd` is 0, then a zero time in that location is returned.
// If the YMDFlag's `yyyymmdd` is 0, then the YMDFlag is updated with the current date in the Local timezone.
func (ymd *YMDFlag) AsTime() time.Time {
return ymd.AsTimeWithLoc(nil)
}

// AsTime returns the YMDFlag as a `time.Time` in the specified location.
// If the YMDFlag's `yyyymmdd` is 0, then a zero time in that location is returned.
// AsTimeWithLoc returns the YMDFlag as a `time.Time` in the specified location.
// If the YMDFlag's `yyyymmdd` is 0, then the YMDFlag is updated with the current date in the specified location.
// If `location“ is nil, then `time.Local` is used.
func (ymd *YMDFlag) AsTimeWithLoc(location *time.Location) time.Time {
if location == nil {
Expand All @@ -221,6 +221,16 @@ func (ymd *YMDFlag) AsTimeWithLoc(location *time.Location) time.Time {
return YMDToTime(ymd.yyyymmdd, location)
}

// AsTimeRawWithLoc returns the YMDFlag as a `time.Time` in the specified location.
// If the YMDFlag's `yyyymmdd` is 0, then a zero time in that location is returned. No auto-update is performed.
// If `location“ is nil, then `time.Local` is used.
func (ymd *YMDFlag) AsTimeRawWithLoc(location *time.Location) time.Time {
if location == nil {
location = time.Local
}
return YMDToTime(ymd.yyyymmdd, location)
}

//////////////////////////////////////////////////////////////////////////////

// isInt checks if a string can be converted safely to an int
Expand Down

0 comments on commit 420e341

Please sign in to comment.