-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptime_mongth.go
More file actions
233 lines (216 loc) · 3.71 KB
/
ptime_mongth.go
File metadata and controls
233 lines (216 loc) · 3.71 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// This package jalaali conversion inspired from github.com/yaa110/go-persian-calendar library.
//
// Copyright (c) 2016 Navid Fathollahzade
package jalaali
import (
"slices"
"strings"
)
// A Month specifies a month of the year starting from Farvardin = 1.
type Month int
// List of months in Persian calendar.
const (
Farvardin Month = 1 + iota
Ordibehesht
Khordad
Tir
Mordad
Shahrivar
Mehr
Aban
Azar
Dey
Bahman
Esfand
)
// List of Dari months in Persian calendar.
const (
Hamal Month = 1 + iota
Sur
Jauza
Saratan
Asad
Sonboleh
Mizan
Aqrab
Qos
Jady
Dolv
Hut
)
var months = []string{
"فروردین",
"اردیبهشت",
"خرداد",
"تیر",
"مرداد",
"شهریور",
"مهر",
"آبان",
"آذر",
"دی",
"بهمن",
"اسفند",
}
var shortMonths = []string{
"فرو",
"ارد",
"خرد",
"تیر",
"مرد",
"شهر",
"مهر",
"آبا",
"آذر",
"دی",
"بهم",
"اسف",
}
var dariMonths = []string{
"حمل",
"ثور",
"جوزا",
"سرطان",
"اسد",
"سنبله",
"میزان",
"عقرب",
"قوس",
"جدی",
"دلو",
"حوت",
}
var shortDariMonths = []string{
"حمل",
"ثور",
"جوز",
"سرط",
"اسد",
"سنب",
"میز",
"عقر",
"قوس",
"جدی",
"دلو",
"حوت",
}
// {days, leap_days, days_before_start}
var monthMeta = [12][3]int{
{31, 31, 0}, // Farvardin
{31, 31, 31}, // Ordibehesht
{31, 31, 62}, // Khordad
{31, 31, 93}, // Tir
{31, 31, 124}, // Mordad
{31, 31, 155}, // Shahrivar
{30, 30, 186}, // Mehr
{30, 30, 216}, // Aban
{30, 30, 246}, // Azar
{30, 30, 276}, // Dey
{30, 30, 306}, // Bahman
{29, 30, 336}, // Esfand
}
// String returns the Persian name of the month.
func (m Month) String() string {
switch {
case m < 1:
return months[0]
case m > 11:
return months[11]
default:
return months[m-1]
}
}
// String returns the Persian short name of the month.
func (m Month) Short() string {
switch {
case m < 1:
return shortMonths[0]
case m > 11:
return shortMonths[11]
default:
return shortMonths[m-1]
}
}
// Dari returns the Dari name of the month.
func (m Month) Dari() string {
switch {
case m < 1:
return dariMonths[0]
case m > 11:
return dariMonths[11]
default:
return dariMonths[m-1]
}
}
// Dari returns the Dari short name of the month.
func (m Month) DariShort() string {
switch {
case m < 1:
return shortDariMonths[0]
case m > 11:
return shortDariMonths[11]
default:
return shortDariMonths[m-1]
}
}
func monthsStr() string {
return strings.Join(slices.Concat(months, dariMonths), "|")
}
func shortMonthsStr() string {
return strings.Join(slices.Concat(shortMonths, shortDariMonths), "|")
}
func parseMonth(values ...string) Month {
for _, month := range values {
switch month {
case "فروردین", "فرو":
return Farvardin
case "اردیبهشت", "ارد":
return Ordibehesht
case "خرداد", "خرد":
return Khordad
case "تیر":
return Tir
case "مرداد", "مرد":
return Mordad
case "شهریور", "شهر":
return Shahrivar
case "مهر":
return Mehr
case "آبان", "آبا":
return Aban
case "آذر":
return Azar
case "دی":
return Dey
case "بهمن", "بهم":
return Bahman
case "اسفند", "اسف":
return Esfand
case "حمل":
return Hamal
case "ثور":
return Sur
case "جوزا", "جوز":
return Jauza
case "سرطان", "سرط":
return Saratan
case "اسد":
return Asad
case "سنبله", "سنب":
return Sonboleh
case "میزان", "میز":
return Mizan
case "عقرب", "عقر":
return Aqrab
case "قوس":
return Qos
case "جدی":
return Jady
case "دلو":
return Dolv
case "حوت":
return Hut
}
}
return 0
}