gengou

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: BSD-2-Clause Imports: 3 Imported by: 0

README

gengou (元号)

find japanese era names from dates

usage

now := time.Time.now()
era, err := gengou.Find(now).Name

can properly calculate the era year as well:

// returns "平成31年"
gengou.EraYear(time.Parse("2006.01.02 MST", "2019.04.30 JST"))

// returns "令和元年"
gengou.EraYear(time.Parse("2006.01.02 MST", "2019.05.01 JST"))

// returns "令和2年"
gengou.EraYear(time.Parse("2006.01.02 MST", "2020.01.01 JST"))

cli

% date
2024年 12月21日 土曜日 14時00分20秒 JST
% gengou
令和6年
% gengou -w
令和6年
% gengou -w 2019.04.30 2019.05.01
平成31年
令和元年
% gengou -f 2006 1991 # go date layouts
平成3年

Documentation

Index

Examples

Constants

View Source
const Version = "0.0.8"

Variables

View Source
var Eras = []Era{}/* 243 elements not displayed */

Functions

func EraDate added in v0.0.2

func EraDate(t time.Time) string
Example
package main

import (
	"blekksprut.net/gengou"
	"fmt"
	"time"
)

var layout = "2006.01.02 MST"

func main() {
	date, _ := time.Parse(layout, "1991.07.29 JST")
	fmt.Println(gengou.EraDate(date))
}
Output:

平成3年7月29日

func EraYear

func EraYear(t time.Time) string

Types

type Era

type Era struct {
	Name, Kana string
	Y, M, D    int
	Date       *time.Time
}

func Find

func Find(t time.Time) (*Era, error)
Example
package main

import (
	"blekksprut.net/gengou"
	"fmt"
	"time"
)

func main() {
	now := time.Now()
	era, err := gengou.Find(now)
	if err != nil {
		panic(err)
	}
	fmt.Println(era.Name)
}
Output:

令和

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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