Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
gouguoyin committed Feb 5, 2024
1 parent 1c4ee8e commit cc3301f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion calendar/gregorian.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const (
RssLayout = time.RFC1123Z
RubyDateLayout = time.RubyDate
UnixDateLayout = time.UnixDate
W3cLayout = RFC3339Layout

RFC1036Layout = "Mon, 02 Jan 06 15:04:05 -0700"
RFC1123Layout = time.RFC1123
Expand Down Expand Up @@ -125,8 +126,11 @@ type Gregorian struct {
// NewGregorian returns a new Gregorian instance.
// 初始化 Gregorian 结构体
func NewGregorian(t time.Time) (g Gregorian) {
if t.IsZero() {
return
}
g.Time = t
return g
return
}

// Date gets gregorian year, month, and day like 2020, 8, 5.
Expand Down
13 changes: 7 additions & 6 deletions calendar/persian/persian.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package persian is part of the Carbon package.
package persian

import (
Expand Down Expand Up @@ -36,6 +35,9 @@ type Persian struct {
// FromGregorian creates a Gregorian instance from time.Time.
// 从标准 time.Time 创建 Gregorian 实例
func FromGregorian(t time.Time) (g Gregorian) {
if t.IsZero() {
return
}
g.Time = t
return
}
Expand Down Expand Up @@ -85,7 +87,6 @@ func (p Persian) ToGregorian() (g Gregorian) {
if p.IsZero() {
return
}
var year, month, day int
jdn := getPersianJdn(p.year, p.month, p.day)

l := jdn + 68569
Expand All @@ -94,12 +95,12 @@ func (p Persian) ToGregorian() (g Gregorian) {
i := 4000 * (l + 1) / 1461001
l = l - 1461*i/4 + 31
j := 80 * l / 2447
day = l - 2447*j/80
d := l - 2447*j/80
l = j / 11
month = j + 2 - 12*l
year = 100*(n-49) + i + l
m := j + 2 - 12*l
y := 100*(n-49) + i + l

g.Time = time.Date(year, time.Month(month), day, p.hour, p.minute, p.second, 0, time.Local)
g.Time = time.Date(y, time.Month(m), d, p.hour, p.minute, p.second, 0, time.Local)
return
}

Expand Down

0 comments on commit cc3301f

Please sign in to comment.