vcalendar

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 3 Imported by: 0

README

Build Status Go Report Card Sourcegraph Release Codecov

About vcalendar

Sử dụng để chuyển đổi từ ngày Dương Lịch sang ngày Âm Lịch và ngược lại

Install package

go get github.com/go-dyn/vcalendar

Sử dụng

Khởi tạo
lunar := vcalendar.New(time.Now().In(vcalendar.VietnamLocation()))

fmt.Printf("Âm lịch: ngày %02d, tháng %02d, năm %d\n", l.Day, l.Month, l.Year) // Âm lịch: ngày 03, tháng 05, năm 2023

// Can chi
fmt.Printf("Âm lịch: ngày %s, tháng %s, năm %s\n", l.DayAlias(), l.MonthAlias(), l.YearAlias()) // Âm lịch: ngày Kỷ Dậu, tháng Mậu Ngọ, năm Quý Mão

// Chuyển đổi
solar := lunar.ToSolar()
fmt.Println(solar.Weekday()) // Thứ Hai
fmt.Println(solar.String()) // Thứ Hai, ngày 20, tháng 06, năm 2023
Sử dụng hàm convert trực tiếp

Đổi từ ngày Dương Lịch sang ngày Âm Lịch
leap có giá trị 1 nếu tháng đó là tháng nhuận

timeLoc, _ := time.LoadLocation("Asia/Ho_Chi_Minh")
today := time.Now().In(timeLoc)
tz := 7 // GMT +7
lunD, lunM, lunY, leap := vcalendar.Solar2Lunar(today.Day(), int(today.Month()), today.Year(), tz)

Đổi từ ngày Âm Lịch sang ngày Dương Lịch

lunD, lunM, lunY, leap := 1, 1, 2023, 0
tz := 7 // GMT +7
d, m, y := vcalendar.Lunar2Solar(lunD, lunM, lunY, leap, tz)

Todo

  • Đổi từ ngày dương lịch sang ngày âm lịch và ngược lại
  • Đổi ngày tháng năm ra can chi
  • Tính giờ hoàng đạo trong ngày
  • Ngày lễ đặc biệt trong lịch âm
  • Tính tiết khí

Tài liệu tham khảo

Documentation

Index

Constants

View Source
const PI float64 = 3.141592653589793

Variables

View Source
var (
	CAN         = [10]string{"Giáp", "Ất", "Bính", "Đinh", "Mậu", "Kỷ", "Canh", "Tân", "Nhâm", "Quý"}
	CHI         = [12]string{"Tý", "Sửu", "Dần", "Mão", "Thìn", "Tỵ", "Ngọ", "Mùi", "Thân", "Dậu", "Tuất", "Hợi"}
	WEEKS       = [7]string{"Chủ Nhật", "Thứ Hai", "Thứ Ba", "Thứ Tư", "Thứ Năm", "Thứ Sáu", "Thứ Bảy"}
	MONTHS      = [12]string{"Giêng", "Hai", "Ba", "Tư", "Năm", "Sáu", "Bảy", "Tám", "Chín", "Mười", "Một", "Chạp"}
	SOLAR_TERMS = []SolarTerm{
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
	}
	LUCKY_HOURS       = [6]string{"110100101100", "001101001011", "110011010010", "101100110100", "001011001101", "010010110011"}
	VIETNAM_TIME_ZONE = "Asia/Ho_Chi_Minh"
	YEARLY_EVENTS     = []YearEvent{
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
		{
			// contains filtered or unexported fields
		},
	}
)

Functions

func Lunar2Solar

func Lunar2Solar(lunarDay, lunarMonth, lunarYear, lunarLeap, tz int) (d, m, y int)

The function Lunar2Solar converts a given Lunar date (lunarDay, lunarMonth, lunarYear, lunarLeap) in the Vietnamese Lunar calendar into the corresponding Solar date (d, m, y). The time zone (tz) is used to calculate the date in the Solar calendar.

func Solar2Lunar

func Solar2Lunar(dd, mm, yy, tz int) (lunarD, lunarM, lunarY, lunarLeap int)

The function Solar2Lunar converts a given Solar date (dd, mm, yy) into the corresponding Lunar date (lunarD, lunarM, lunarY) in the Vietnamese Lunar calendar. It also determines if the given Lunar month is a leap month or not (lunarLeap). The time zone (tz) is used to calculate the date in the Lunar calendar.

func VietnamLocation

func VietnamLocation() *time.Location

VietnamLocation returns the *time.Location for Vietnam

Types

type Calendar added in v1.1.0

type Calendar struct {
	Day   int
	Month int
	Year  int
	// contains filtered or unexported fields
}

type LuckyHourDetail added in v1.1.0

type LuckyHourDetail struct {
	Chi  string
	From int
	To   int
}

type Lunar

type Lunar struct {
	Leap bool
	// contains filtered or unexported fields
}

func New

func New(t time.Time) Lunar

func NewWithLunar

func NewWithLunar(d, m, y int, l bool, loc time.Location) Lunar

func (*Lunar) DayAlias

func (l *Lunar) DayAlias() string

func (*Lunar) Events added in v1.1.0

func (l *Lunar) Events() []YearEvent

func (*Lunar) LuckyHour added in v1.1.0

func (l *Lunar) LuckyHour() string

func (*Lunar) LuckyHourDetail added in v1.1.0

func (l *Lunar) LuckyHourDetail() []LuckyHourDetail

func (*Lunar) MonthAlias

func (l *Lunar) MonthAlias() string

func (*Lunar) Next

func (l *Lunar) Next() *Lunar

TODO: implement function

func (*Lunar) SolarTerms added in v1.1.0

func (l *Lunar) SolarTerms() SolarTerm

func (*Lunar) String

func (l *Lunar) String() string

func (*Lunar) ToSolar

func (l *Lunar) ToSolar() Solar

func (*Lunar) Weekday

func (l *Lunar) Weekday() int

func (*Lunar) WeekdayDisplay added in v1.1.0

func (l *Lunar) WeekdayDisplay() string

func (*Lunar) YearAlias

func (l *Lunar) YearAlias() string

type Solar

type Solar struct {
	// contains filtered or unexported fields
}

func (*Solar) String

func (s *Solar) String() string

func (*Solar) Weekday

func (s *Solar) Weekday() string

type SolarTerm added in v1.1.0

type SolarTerm struct {
	// contains filtered or unexported fields
}

type YearEvent added in v1.1.0

type YearEvent struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL