gengou

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: BSD-2-Clause Imports: 3 Imported by: 0

README

gengou (元号)

find japanese era names from dates

gengou in action

usage

now := 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年
$ gengou -d # show the full date
令和6年12月27日

installation

go
go install blekksprut.net/gengou/cmd/gengou@latest
arch linux

gengou is available as a package in the AUR

it can be installed with an AUR helper (e.g. yay):

$ yay -S gengou

Documentation

Overview

Package gengou implements functions for converting dates to the Japanese era calendar scheme.

Index

Examples

Constants

View Source
const Offset = 9 * 60 * 60
View Source
const Version = "0.1.0"

Variables

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

All Japanese eras, from 大化 to 令和.

Functions

func EraDate added in v0.0.2

func EraDate(t time.Time) string

EraDate returns the full era name and date corresponding to t

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 EraDateWithZeros added in v0.0.9

func EraDateWithZeros(t time.Time) string

EraDateWithZeros returns the era year and zero-prefixed month and day for t

func EraYear

func EraYear(t time.Time) string

EraYear returns the era name and year corresponding to t

Types

type Era

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

Represents a Japanese era.

func Find

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

Find returns the Era matching time t. Reports an error if the date is before the first era (大化).

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
gengou command

Jump to

Keyboard shortcuts

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