Skip to content

Commit 342c9d3

Browse files
committed
Add Kurdish date formatting and custom error types
Introduces KFormat for Kurdish date formatting with Kurdish digits and custom error types for invalid year, month, day, and date. Updates KurdishToGregorian to use new error types. Expands README with usage examples and documents the new formatting method.
1 parent 0bf0a91 commit 342c9d3

6 files changed

Lines changed: 378 additions & 13 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ coverage.*
1717
*.coverprofile
1818
profile.cov
1919

20+
21+
22+
2023
# Dependency directories (remove the comment below to include it)
2124
# vendor/
2225

@@ -30,3 +33,6 @@ go.work.sum
3033
# Editor/IDE
3134
# .idea/
3235
# .vscode/
36+
37+
# Example binaries
38+
cmd/

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ func main() {
4343
} else {
4444
fmt.Printf("Gregorian date: %s\n", g.Format("2006-01-02"))
4545
}
46+
47+
// Create a specific Kurdish date and convert to Gregorian
48+
// Note: Dialect is optional and not used in conversion, only Epoch matters
49+
specificKurdish := kurdical.KurdishDate{
50+
Year: 2725,
51+
Month: 9,
52+
Day: 24,
53+
Dialect: kurdical.Sorani, // Optional
54+
Epoch: kurdical.MedianKingdom,
55+
}
56+
gregorianSpecific, err := kurdical.KurdishToGregorian(specificKurdish)
57+
if err != nil {
58+
fmt.Println("Error:", err)
59+
} else {
60+
fmt.Printf("Kurdish 2725-09-24 to Gregorian: %s\n", gregorianSpecific.Format("2006-01-02"))
61+
}
4662
}
4763
```
4864

@@ -58,6 +74,7 @@ func main() {
5874

5975
- `GregorianToKurdish(t time.Time, dialect Dialect, epoch Epoch) KurdishDate`
6076
- `KurdishToGregorian(k KurdishDate) (time.Time, error)`
77+
- `(k KurdishDate) KFormat(layout string) (string, error)`: Formats the Kurdish date using Go time layout strings with Persian digits
6178

6279
## Kurdish Calendar Details
6380

conversions.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package kurdical
22

33
import (
4-
"fmt"
54
"time"
65
)
76

@@ -166,15 +165,6 @@ func mod(a, b int) int {
166165
return a % b
167166
}
168167

169-
// ErrorInvalidYear represents an error for invalid year.
170-
type ErrorInvalidYear struct {
171-
Year int
172-
}
173-
174-
func (e *ErrorInvalidYear) Error() string {
175-
return fmt.Sprintf("invalid year: %d", e.Year)
176-
}
177-
178168
// isSolarHijriLeap determines if a Solar Hijri year is leap.
179169
func isSolarHijriLeap(year int) bool {
180170
leap, _, _, err := jalCal(year)

errors.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package kurdical
2+
3+
import "fmt"
4+
5+
// ErrorInvalidYear represents an error for invalid year in Jalaali calculations.
6+
type ErrorInvalidYear struct {
7+
Year int
8+
}
9+
10+
func (e *ErrorInvalidYear) Error() string {
11+
return fmt.Sprintf("invalid year: %d", e.Year)
12+
}
13+
14+
// ErrorInvalidMonth represents an error for invalid month.
15+
type ErrorInvalidMonth struct {
16+
Month int
17+
}
18+
19+
func (e *ErrorInvalidMonth) Error() string {
20+
return fmt.Sprintf("invalid month: %d", e.Month)
21+
}
22+
23+
// ErrorInvalidDay represents an error for invalid day.
24+
type ErrorInvalidDay struct {
25+
Day int
26+
}
27+
28+
func (e *ErrorInvalidDay) Error() string {
29+
return fmt.Sprintf("invalid day: %d", e.Day)
30+
}
31+
32+
// ErrorInvalidDate represents an error for invalid date combination.
33+
type ErrorInvalidDate struct {
34+
Year int
35+
Month int
36+
Day int
37+
}
38+
39+
func (e *ErrorInvalidDate) Error() string {
40+
return fmt.Sprintf("invalid date: year=%d, month=%d, day=%d", e.Year, e.Month, e.Day)
41+
}

0 commit comments

Comments
 (0)