wareki

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: ISC Imports: 2 Imported by: 0

README

go-wareki

usage

loc, _ := time.LoadLocation("Asia/Tokyo")
t := wareki.New(time.Date(2019, 10, 2, 0, 0, 0, 0, loc))
e := t.Era()
if e == wareki.EraNotFound {
	return
}
fmt.Printf("%s%02d年%s", e.KanjiName, t.YearEra(), t.Format("01月02日"))

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	JST = time.FixedZone("Asia/Tokyo", 9*60*60)
	// Eras means list of era, this will be used by searching
	// refer from: https://ja.wikipedia.org/wiki/%E5%85%83%E5%8F%B7%E4%B8%80%E8%A6%A7_(%E6%97%A5%E6%9C%AC)
	// ! we can override this for other GENGOs
	Eras = map[eraID]Era{
		"meiji":  {ShortName: "M", KanjiName: "明治", StartedAt: time.Date(1868, 10, 23, 0, 0, 0, 0, JST)},
		"taisho": {ShortName: "T", KanjiName: "大正", StartedAt: time.Date(1912, 7, 30, 0, 0, 0, 0, JST)},
		"showa":  {ShortName: "S", KanjiName: "昭和", StartedAt: time.Date(1926, 12, 25, 0, 0, 0, 0, JST)},
		"heisei": {ShortName: "H", KanjiName: "平成", StartedAt: time.Date(1989, 1, 8, 0, 0, 0, 0, JST)},
		"reiwa":  {ShortName: "R", KanjiName: "令和", StartedAt: time.Date(2019, 5, 1, 0, 0, 0, 0, JST)},
	}
	// EraOrder must be correct, this will be used as order when searching
	// ! we can override this for other GENGOs
	EraOrder = []eraID{"reiwa", "heisei", "showa", "taisho", "meiji"}
	// EraNotFound using to era error type
	EraNotFound Era
)

Functions

This section is empty.

Types

type Era

type Era struct {
	ShortName string
	KanjiName string
	StartedAt time.Time
}

func (Era) String

func (e Era) String() string

type Time

type Time struct {
	time.Time
}

func Date

func Date(era string, year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) Time

Date returns wareki.Time by func that looks like time.Date

Date("R", 1, 10, 2, 0, 0, 0, 0, JST) Date("令和", 1, 10, 2, 0, 0, 0, 0, JST)

func New

func New(t time.Time) Time

New return wareki.Time in JST time zone

func (Time) Era

func (t Time) Era() Era

Era returns a year era name what belongs to

func (Time) YearEra

func (t Time) YearEra() int

YearEra returns year number in era this will return -1 when era was not found

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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