vcalendar

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 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

This section is empty.

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"}
	DaysOfWeek      = [7]string{"Thứ Hai", "Thứ Ba", "Thứ Tư", "Thứ Năm", "Thứ Sáu", "Thứ Bảy", "Chủ Nhật"}
	VietnamTimezone = "Asia/Ho_Chi_Minh"
)

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 Lunar

type Lunar struct {
	Day   int
	Month int
	Year  int
	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) MonthAlias

func (l *Lunar) MonthAlias() string

func (*Lunar) Next

func (l *Lunar) Next() *Lunar

TODO: implement function

func (*Lunar) String

func (l *Lunar) String() string

func (*Lunar) ToSolar

func (l *Lunar) ToSolar() Solar

func (*Lunar) Weekday

func (l *Lunar) Weekday() string

func (*Lunar) YearAlias

func (l *Lunar) YearAlias() string

type Solar

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

func (*Solar) String

func (s *Solar) String() string

func (*Solar) Weekday

func (s *Solar) Weekday() string

Jump to

Keyboard shortcuts

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