vlunar

package
v2.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 4 Imported by: 0

README

Carbon

Carbon Release Go Test Go Report Card Go Coverage Goproxy.cn Carbon Doc License

Introduction

A simple, semantic and developer-friendly golang package for time, has been included by awesome-go

github.com/golang-module/carbon

gitee.com/golang-module/carbon

Vietnamese Lunar
Convert Solar into VLunar
// Get Lunar year of animal
carbon.Parse("2024-01-25 13:14:15").VLunar().Animal() // Mão

// Get lunar festival
carbon.Parse("2021-02-12 13:14:15").VLunar().Festivals() // []{{Day: 1, Month: 1, Name: "Tết Nguyên Đán"}}

// Get lunar luck hours
carbon.Parse("2020-05-01 13:14:15").VLunar().LuckyHours() // []{{Chi: "Dần", From: 3, To: 5}, {Chi: "Thìn", From: 7, To: 9}, {Chi: "Tỵ", From: 9, To: 11}, {Chi: "Thân", From: 15, To: 17}, {Chi: "Dậu", From: 17, To: 19}, {Chi: "Hợi", From: 21, To: 23}},

// Get lunar solar term
carbon.Parse("2025-03-10 13:14:15").VLunar().SolarTerm() // {Longitude: 345, Name: "Kinh trập"}

// Get lunar year, month, day, hour, minute and second
carbon.Parse("2020-08-05 13:14:15").VLunar().DateTime() // 2020, 6, 16, 13, 14, 15
// Get lunar year, month and day
carbon.Parse("2020-08-05 13:14:15").VLunar().Date() // 2020, 6, 16
// Get lunar hour, minute and second
carbon.Parse("2020-08-05 13:14:15").VLunar().Time() // 13, 14, 15

// Get lunar year
carbon.Parse("2020-08-05 13:14:15").VLunar().Year() // 2020
// Get lunar month
carbon.Parse("2020-08-05 13:14:15").VLunar().Month() // 6
// Get lunar leap month
carbon.Parse("2020-08-05 13:14:15").VLunar().LeapMonth() // 4
// Get lunar day
carbon.Parse("2020-08-05 13:14:15").VLunar().Day() // 16
// Get lunar date as YYYY-MM-DD HH::ii::ss format string
fmt.Printf("%s", carbon.Parse("2020-08-05 13:14:15").VLunar()) // 2020-06-16 13:14:15

// Get lunar year as string
carbon.Parse("2021-05-01 13:14:15").VLunar().ToYearString() // Tân Sửu
// Get lunar month as string
carbon.Parse("2020-12-01 13:14:15").VLunar().ToMonthString() // Đinh Hợi
// Get lunar day as string
carbon.Parse("2020-08-01 13:14:15").VLunar().ToDayString() // Bính Tý
// Get lunar date as string
carbon.Parse("2020-01-01 13:14:15").VLunar().ToDateString() // Ngày 07 tháng 12 năm 2019

// Whether is a lunar leap year
carbon.Parse("2020-08-05 13:14:15").VLunar().IsLeapYear() // true
// Whether is a lunar leap month
carbon.Parse("2020-08-05 13:14:15").VLunar().IsLeapMonth() // false

// Whether is a lunar year of the rat
carbon.Parse("2020-08-05 13:14:15").VLunar().IsRatYear() // true
// Whether is a lunar year of the ox
carbon.Parse("2020-08-05 13:14:15").VLunar().IsOxYear() // false
// Whether is a lunar year of the tiger
carbon.Parse("2020-08-05 13:14:15").VLunar().IsTigerYear() // false
// Whether is a lunar year of the rabbit
carbon.Parse("2020-08-05 13:14:15").VLunar().IsRabbitYear() // false
// Whether is a lunar year of the dragon
carbon.Parse("2020-08-05 13:14:15").VLunar().IsDragonYear() // false
// Whether is a lunar year of the snake
carbon.Parse("2020-08-05 13:14:15").VLunar().IsSnakeYear() // false
// Whether is a lunar year of the horse
carbon.Parse("2020-08-05 13:14:15").VLunar().IsHorseYear() // false
// Whether is a lunar year of the goat
carbon.Parse("2020-08-05 13:14:15").VLunar().IsGoatYear() // false
// Whether is a lunar year of the monkey
carbon.Parse("2020-08-05 13:14:15").VLunar().IsMonkeyYear() // false
// Whether is a lunar year of the rooster
carbon.Parse("2020-08-05 13:14:15").VLunar().IsRoosterYear() // false
// Whether is a lunar year of the dog
carbon.Parse("2020-08-05 13:14:15").VLunar().IsDogYear() // false
// Whether is a lunar year of the dig
carbon.Parse("2020-08-05 13:14:15").VLunar().IsPigYear() // false

Convert Lunar into Solar
// Convert the Vietnamese Lunar Calendar December 11, 2023 to the Solar Calendar
carbon.CreateFromVLunar(2023, 12, 11, 0, 0, 0, false).ToDateTimeString() // 2024-01-21 00:00:00
// Convert Vietnamese lunar calendar February 11, 2023 to Solar calendar
carbon.CreateFromVLunar(2023, 2, 11, 0, 0, 0, false).ToDateTimeString() // 2024-03-02 00:00:00
// Convert the Vietnamese Lunar Calendar Leap February 11, 2024 to the Solar Calendar
carbon.CreateFromVLunar(2023, 2, 11, 0, 0, 0, true).ToDateTimeString() // 2023-04-01 00:00:00

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PI = math.Pi
)

Functions

This section is empty.

Types

type Festival

type Festival struct {
	Day   int
	Month int
	Name  string
}

type Gregorian

type Gregorian struct {
	calendar.Gregorian
}

Gregorian defines a Gregorian struct.

func NewGregorian

func NewGregorian(t time.Time) (g Gregorian)

NewGregorian returns a new Gregorian instance. 初始化 Gregorian 结构体

func (Gregorian) ToLunar

func (g Gregorian) ToLunar() (v VLunar)

ToLunar Convert Gregorian calendar into Vietnamese Lunar calendar 将 公历 转化为 农历

type LuckyHour

type LuckyHour struct {
	Chi  string
	From int
	To   int
}

type SolarTerm

type SolarTerm struct {
	Longitude int
	Name      string
}

type VLunar

type VLunar struct {
	Error error
	// contains filtered or unexported fields
}

VLunar defines a Lunar struct.

func NewLunar

func NewLunar(year, month, day, hour, minute, second int, isLeapMonth bool) (v VLunar)

NewLunar returns a new Lunar instance. 初始化 Lunar 结构体

func (VLunar) Animal

func (v VLunar) Animal() string

Animal gets lunar animal name like "Tý".

func (VLunar) Date

func (v VLunar) Date() (year, month, day int)

Date gets lunar year, month and day like 2020, 8, 5.

func (VLunar) DateTime

func (v VLunar) DateTime() (year, month, day, hour, minute, second int)

DateTime gets lunar year, month, day, hour, minute, and second like 2020, 8, 5, 13, 14, 15.

func (VLunar) Day

func (v VLunar) Day() int

Day gets lunar day like 5.

func (VLunar) DayAnimal

func (v VLunar) DayAnimal() string

func (VLunar) DayHeavenStem

func (v VLunar) DayHeavenStem() string

func (VLunar) Festivals

func (v VLunar) Festivals() (events []Festival)

Festival gets lunar festival name like "Trung thu".

func (VLunar) IsCatYear

func (v VLunar) IsCatYear() bool

IsRabbitYear reports whether is year of Rabbit.

func (VLunar) IsDogYear

func (v VLunar) IsDogYear() bool

IsDogYear reports whether is year of Dog.

func (VLunar) IsDragonYear

func (v VLunar) IsDragonYear() bool

IsDragonYear reports whether is year of Dragon.

func (VLunar) IsGoatYear

func (v VLunar) IsGoatYear() bool

IsGoatYear reports whether is year of Goat.

func (VLunar) IsHorseYear

func (v VLunar) IsHorseYear() bool

IsHorseYear reports whether is year of Horse.

func (VLunar) IsLeapMonth

func (v VLunar) IsLeapMonth() bool

IsLeapMonth reports whether is leap month.

func (VLunar) IsLeapYear

func (v VLunar) IsLeapYear() bool

IsLeapYear reports whether is leap year.

func (VLunar) IsMonkeyYear

func (v VLunar) IsMonkeyYear() bool

IsMonkeyYear reports whether is year of Monkey.

func (VLunar) IsOxYear

func (v VLunar) IsOxYear() bool

IsOxYear reports whether is year of Ox.

func (VLunar) IsPigYear

func (v VLunar) IsPigYear() bool

IsPigYear reports whether is year of Pig.

func (VLunar) IsRatYear

func (v VLunar) IsRatYear() bool

IsRatYear reports whether is year of Rat.

func (VLunar) IsRoosterYear

func (v VLunar) IsRoosterYear() bool

IsRoosterYear reports whether is year of Rooster.

func (VLunar) IsSnakeYear

func (v VLunar) IsSnakeYear() bool

IsSnakeYear reports whether is year of Snake.

func (VLunar) IsTigerYear

func (v VLunar) IsTigerYear() bool

IsTigerYear reports whether is year of Tiger.

func (VLunar) LeapMonth

func (v VLunar) LeapMonth() int

LeapMonth gets lunar leap month like 8.

func (VLunar) LuckyHour

func (v VLunar) LuckyHour() string

func (VLunar) LuckyHours

func (v VLunar) LuckyHours() (ret []LuckyHour)

func (VLunar) Month

func (v VLunar) Month() int

Month gets lunar month like 8.

func (VLunar) MonthAnimal

func (v VLunar) MonthAnimal() string

func (VLunar) MonthHeavenStem

func (v VLunar) MonthHeavenStem() string

func (VLunar) SolarTerm

func (v VLunar) SolarTerm() SolarTerm

func (VLunar) String

func (v VLunar) String() string

String outputs a string in YYYY-MM-DD HH::ii::ss format, implement Stringer interface.

func (VLunar) Time

func (v VLunar) Time() (hour, minute, second int)

Time gets lunar hour, minute, and second like 13, 14, 15.

func (VLunar) ToDateString

func (v VLunar) ToDateString() string

ToDateString outputs a string in lunar date format like "Ngày 16 tháng 9 năm 2020".

func (VLunar) ToDayString

func (v VLunar) ToDayString() (day string)

ToDayString outputs a string in lunar day format like "Giáp Tý".

func (VLunar) ToGregorian

func (v VLunar) ToGregorian() (g Gregorian)

ToLunar Convert Vietnamese lunar calendar into Gregorian calendar 将 农历 转化为 公历

func (VLunar) ToMonthString

func (v VLunar) ToMonthString() string

ToMonthString outputs a string in lunar month format like "Giáp Tý".

func (VLunar) ToYearString

func (v VLunar) ToYearString() string

ToYearString outputs a string in lunar year format like "Giáp Tý".

func (VLunar) Year

func (v VLunar) Year() int

Year gets lunar year like 2020.

func (VLunar) YearHeavenStem

func (v VLunar) YearHeavenStem() string

Jump to

Keyboard shortcuts

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