koyomi

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: Apache-2.0 Imports: 11 Imported by: 2

README

koyomi -- 日本のこよみ

check vulns lint status GitHub license GitHub release

Migrated repository to github.com/goark/koyomi

国立天文台 天文情報センター 暦計算室」より日本の暦情報を取得する Go 言語用パッケージです。 Google Calendar を経由して取得しています。

取得可能な情報は以下の通りです。

const (
    Holiday   CalendarID = iota + 1 //国民の祝日および休日
    MoonPhase                       //朔弦望
    SolarTerm                       //二十四節気・雑節
    Eclipse                         //日食・月食・日面経過
    Planet                          //惑星現象
)

Usage

start, _ := koyomi.DateFrom("2019-05-01")
end := koyomi.NewDate(time.Date(2019, time.May, 31, 0, 0, 0, 0, koyomi.JST))
k, err := koyomi.NewSource(
    koyomi.WithCalendarID(koyomi.Holiday, koyomi.SolarTerm),
    koyomi.WithStartDate(start),
    koyomi.WithEndDate(end),
).Get()
if err != nil {
    return
}

csv, err := k.EncodeCSV()
if err != nil {
    return
}
io.Copy(os.Stdout, bytes.NewReader(csv))
//Output:
//"Date","Title"
//"2019-05-01","休日 (天皇の即位の日)"
//"2019-05-02","休日"
//"2019-05-02","八十八夜"
//"2019-05-03","憲法記念日"
//"2019-05-04","みどりの日"
//"2019-05-05","こどもの日"
//"2019-05-06","休日"
//"2019-05-06","立夏"
//"2019-05-21","小満"

Modules Requirement Graph

dependency.png

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	JST = time.FixedZone("JST", int(jstoffset)) // Japan standard Time
)

Functions

func WithCalendarID

func WithCalendarID(cid ...CalendarID) optFunc

WithCalendarID returns function for setting Reader

func WithEndDate

func WithEndDate(end DateJp) optFunc

WithEndDate returns function for setting Reader

func WithStartDate

func WithStartDate(start DateJp) optFunc

WithStartDate returns function for setting Reader

func WithTempDir

func WithTempDir(dir string) optFunc

WithTempDir returns function for setting Reader

Types

type CalendarID

type CalendarID int
const (
	Holiday   CalendarID = iota + 1 //国民の祝日および休日
	MoonPhase                       //朔弦望
	SolarTerm                       //二十四節気・雑節
	Eclipse                         //日食・月食・日面経過
	Planet                          //惑星現象
)

func (CalendarID) String

func (cid CalendarID) String() string

String is Stringer of CalendarID

func (CalendarID) URL

func (cid CalendarID) URL() string

URL returns URL string from CalendarID

type DateJp

type DateJp struct {
	time.Time
}

DateJp is wrapper class of time.Time

func DateFrom

func DateFrom(s string) (DateJp, error)

DateFrom returns DateJp instance from date string

func NewDate

func NewDate(tm time.Time) DateJp

NewDate returns DateJp instance

func (DateJp) After

func (t DateJp) After(dt DateJp) bool

After reports whether the DateJp instant t is after dt.

func (DateJp) Before

func (t DateJp) Before(dt DateJp) bool

Before reports whether the DateJp instant t is before dt.

func (DateJp) Equal

func (t DateJp) Equal(dt DateJp) bool

Equal reports whether t and dt represent the same time instant.

func (*DateJp) MarshalJSON

func (t *DateJp) MarshalJSON() ([]byte, error)

MarshalJSON returns time string with RFC3339 format

func (DateJp) String

func (t DateJp) String() string

func (*DateJp) UnmarshalJSON

func (t *DateJp) UnmarshalJSON(b []byte) error

UnmarshalJSON returns result of Unmarshal for json.Unmarshal()

type Event

type Event struct {
	Date  DateJp
	Title string
}

Event is koyomi event data

type Koyomi

type Koyomi struct {
	// contains filtered or unexported fields
}

Koyomi is array of Event

Example
package main

import (
	"bytes"
	"fmt"
	"io"
	"os"
	"time"

	"github.com/goark/koyomi"
)

func main() {
	start, _ := koyomi.DateFrom("2019-05-01")
	end := koyomi.NewDate(time.Date(2019, time.May, 31, 0, 0, 0, 0, koyomi.JST))
	k, err := koyomi.NewSource(
		koyomi.WithCalendarID(koyomi.Holiday, koyomi.SolarTerm),
		koyomi.WithStartDate(start),
		koyomi.WithEndDate(end),
	).Get()
	if err != nil {
		return
	}

	csv, err := k.EncodeCSV()
	if err != nil {
		return
	}
	if _, err := io.Copy(os.Stdout, bytes.NewReader(csv)); err != nil {
		fmt.Fprintln(os.Stderr, err)
		return
	}
}
Output:
"Date","Title"
"2019-05-01","休日 (天皇の即位の日)"
"2019-05-02","休日"
"2019-05-02","八十八夜"
"2019-05-03","憲法記念日"
"2019-05-04","みどりの日"
"2019-05-05","こどもの日"
"2019-05-06","休日"
"2019-05-06","立夏"
"2019-05-21","小満"

func (*Koyomi) Add

func (k *Koyomi) Add(kk *Koyomi)

Add adds other Kyomoi instance

func (*Koyomi) EncodeCSV

func (k *Koyomi) EncodeCSV() ([]byte, error)

func (*Koyomi) EncodeJSON

func (k *Koyomi) EncodeJSON() ([]byte, error)

func (*Koyomi) Events

func (k *Koyomi) Events() []Event

Events returns event array

func (*Koyomi) SortByDate

func (k *Koyomi) SortByDate()

SortByDate sorts event data by date

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source is information of data source for koyomi

func NewSource

func NewSource(opts ...optFunc) *Source

NewSource creates a new Source instance

func (*Source) Get

func (s *Source) Get() (*Koyomi, error)

Get returns koyomi data from calendar dources

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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