-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjalaali.go
79 lines (66 loc) · 1.43 KB
/
jalaali.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package jalaali
import (
"strconv"
"time"
)
// A simple wrapper around Golang default time package. You have all the functionality of
// default time package and functionalities needed for Jalaali calender.
type Jalaali struct {
time.Time
}
// From initialize new instance of Jalaali from a time instance.
func From(t time.Time) Jalaali {
return Jalaali{t}
}
// Now with return Jalaali instance of current time.
func Now() Jalaali {
return From(time.Now())
}
// A Month specifies a month of the year (Farvardin = 1, ...).
type Month int
const (
Farvardin Month = 1 + iota
Ordibehesht
Khordad
Tir
Mordad
Shahrivar
Mehr
Aban
Azar
Dey
Bahman
Esfand
)
var months = []string{
"فروردین", "اردیبهشت", "خرداد",
"تیر", "مرداد", "شهریور",
"مهر", "آبان", "آذر",
"دی", "بهمن", "اسفند",
}
func (m Month) String() string {
if Farvardin <= m && m <= Esfand {
return months[m-1]
}
return "%!Month(" + strconv.Itoa(int(m)) + ")"
}
// A Weekday specifies a day of the week (Shanbe = 0, ...).
type Weekday int
const (
Shanbe Weekday = iota
IekShanbe
DoShanbe
SeShanbe
ChaharShanbe
PanjShanbe
Jome
)
var days = []string{
"شنبه", "یکشنبه", "دوشنبه", "سهشنبه", "چهارشنبه", "پنجشنبه", "جمعه",
}
func (d Weekday) String() string {
if Shanbe <= d && d <= Jome {
return days[d]
}
return "%!Weekday(" + strconv.Itoa(int(d)) + ")"
}