-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructor.go
More file actions
60 lines (50 loc) · 1.45 KB
/
constructor.go
File metadata and controls
60 lines (50 loc) · 1.45 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package jalaali
import "time"
// New create new jalaali instance from time.
func New(t time.Time) Jalaali {
if t.Year() < 1097 {
return new(jTime)
} else {
driver := new(jTime)
driver.setTime(t)
return driver
}
}
// NewTz create new jalaali instance from time.
// If location is nil then the local time is used.
func NewTz(t time.Time, loc *time.Location) Jalaali {
if loc == nil {
return New(t)
}
return New(t.In(loc))
}
// Date create a new jalaali instance from jalaali date.
//
// year, month and day represent a day in Persian calendar.
//
// hour, min minute, sec seconds, nsec nanoseconds offsets represent a moment in time.
//
// loc is a pointer to time.Location, if loc is nil then the local time is used.
func Date(year int, month Month, day, hour, min, sec, nsec int, loc *time.Location) Jalaali {
driver := new(jTime)
driver.set(year, month, day, hour, min, sec, nsec, loc)
return driver
}
// Unix create a new jalaali instance from unix timestamp.
//
// sec seconds and nsec nanoseconds since January 1, 1970 UTC.
func Unix(sec, nsec int64) Jalaali {
return New(time.Unix(sec, nsec))
}
// Now create a new jalaali instance from current time.
func Now() Jalaali {
return New(time.Now())
}
// TehranTz get tehran time zone.
func TehranTz() *time.Location {
return time.FixedZone("Asia/Tehran", 12600) // UTC + 03:30
}
// KabulTz get kabul time zone.
func KabulTz() *time.Location {
return time.FixedZone("Asia/Kabul", 16200) // UTC + 04:30
}