-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse.go
More file actions
37 lines (33 loc) · 1.05 KB
/
parse.go
File metadata and controls
37 lines (33 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package gotime
import (
"time"
"github.com/maniartech/gotime/v2/internal/nites"
)
// Parse parses a date-time string according to the specified layout format.
// The layout uses NITES (Natural and Intuitive Time Expression Syntax) format
// specifiers like "yyyy-mm-dd" instead of Go's reference time format.
//
// Example:
//
// parsed, err := gotime.Parse("yyyy-mm-dd", "2022-12-31")
// if err != nil {
// // handle error
// }
// // parsed: 2022-12-31 00:00:00 +0000 UTC
func Parse(layout, value string) (time.Time, error) {
return nites.Parse(layout, value)
}
// ParseInLocation parses a date-time string according to the specified layout format
// and returns the time in the specified location/timezone.
//
// Example:
//
// ist := time.FixedZone("IST", 5*60*60+30*60)
// parsed, err := gotime.ParseInLocation("yyyy-mm-dd", "2022-12-31", ist)
// if err != nil {
// // handle error
// }
// // parsed: 2022-12-31 00:00:00 +0530 IST
func ParseInLocation(layout, value string, loc *time.Location) (time.Time, error) {
return nites.ParseInLocation(layout, value, loc)
}