vanatime

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 10 Imported by: 3

README

Build Status GoDoc

go-vanatime

Go library for dealing with Vana'diel time from Final Fantasy XI. Converting between realtime and Vana'diel time, and so on.

Examples

See _example directory.

// Current Vana'diel time
vt := vanatime.Now()
fmt.Println(vt)
//=> 1313-04-13 21:20:27 Lightsday Waxing Crescent (33%)

// From the earth time
et := time.Now()
vt = vanatime.FromEarth(et)
fmt.Println(et)
fmt.Println(vt)
//=> 2018-11-05 21:58:25.119486 +0900 JST m=+0.000910642
//=> 1313-04-13 21:20:27 Lightsday Waxing Crescent (33%)

// Specified Vana'diel time
vt = vanatime.Date(1300, 2, 3, 0, 0, 0, 0)
fmt.Println(vt)
//=> 1300-02-03 00:00:00 Firesday Waning Gibbous (76%)

// Weekday and MoonPhase in Japanese
fmt.Println(
    vt.Weekday().StringLocale("ja"),
    vt.Moon().Phase().StringLocale("ja"),
)
//=> 火曜日 居待月

// To the earth time
et = vt.Earth()
fmt.Println(et)
//=> 2018-04-29 21:07:12 +0900 JST

// Add 3 days
vt = vt.Add(3 * vanatime.Day)
fmt.Println(vt)
//=> 1300-02-06 00:00:00 Windsday Waning Gibbous (69%)

// Formatting
fmt.Println(vt.Strftime("%Y/%m/%d %H:%M:%S"))
//=> 1300/02/06 00:00:00

License

MIT

Author

pasela

Documentation

Index

Constants

View Source
const (
	Microsecond Duration = 1
	Millisecond          = 1000 * Microsecond
	Second               = 1000 * Millisecond
	Minute               = 60 * Second
	Hour                 = 60 * Minute
	Day                  = 24 * Hour
	Week                 = 8 * Day
	Month                = 30 * Day
	Year                 = 360 * Day
)
View Source
const (
	TimeScale         int   = 25 // Vana'diel time goes 25 times faster than the Earth
	BaseYear          int   = 886
	BaseTime          int64 = (int64(BaseYear) * int64(Year)) / int64(TimeScale)
	EarthBaseTime     int64 = 1009810800 * int64(Second) // 2002-01-01 00:00:00.000 JST
	VanaEarthDiffTime int64 = BaseTime - EarthBaseTime
	MoonCycleDays     int   = 84 // Vana'diel moon cycle lasts 84 days
)

Variables

This section is empty.

Functions

func After added in v0.2.0

func After(d Duration) <-chan Time

After waits for the duration to elapse and then sends the current time on the returned channel. It is equivalent to NewTimer(d).C. The underlying Timer is not recovered by the garbage collector until the timer fires. If efficiency is a concern, use NewTimer instead and call Timer.Stop if the timer is no longer needed.

func Sleep added in v0.2.0

func Sleep(d Duration)

Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately.

func Tick added in v0.2.0

func Tick(d Duration) <-chan Time

Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. While Tick is useful for clients that have no need to shut down the Ticker, be aware that without a way to shut it down the underlying Ticker cannot be recovered by the garbage collector; it "leaks". Unlike NewTicker, Tick will return nil if d <= 0.

Types

type Duration

type Duration int64

A Duration represents the elapsed vana'diel time between two instants as an int64 microsecond count.

func ParseDuration

func ParseDuration(s string) (Duration, error)

ParseDuration parses a duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "us" (or "µs"), "ms", "s", "m", "h".

func Since

func Since(t Time) Duration

Since returns the time elapsed since t. It is shorthand for time.Now().Sub(t).

func Until

func Until(t Time) Duration

Until returns the duration until t. It is shorthand for t.Sub(time.Now()).

func (Duration) Hours

func (d Duration) Hours() float64

Hours returns the duration as a floating point number of hours.

func (Duration) Microseconds

func (d Duration) Microseconds() int64

Microseconds returns the duration as an integer microsecond count.

func (Duration) Minutes

func (d Duration) Minutes() float64

Minutes returns the duration as a floating point number of minutes.

func (Duration) Round

func (d Duration) Round(m Duration) Duration

Round returns the result of rounding d to the nearest multiple of m. The rounding behavior for halfway values is to round away from zero. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, Round returns the maximum (or minimum) duration. If m <= 0, Round returns d unchanged.

func (Duration) Seconds

func (d Duration) Seconds() float64

Seconds returns the duration as a floating point number of seconds.

func (Duration) String

func (d Duration) String() string

String returns a string representing the duration in the form "72h3m0.5s". Leading zero units are omitted. As a special case, durations less than one second format use a smaller unit (milli-, microseconds) to ensure that the leading digit is non-zero. The zero duration formats as 0s.

func (Duration) Truncate

func (d Duration) Truncate(m Duration) Duration

Truncate returns the result of rounding d toward zero to a multiple of m. If m <= 0, Truncate returns d unchanged.

type Moon

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

func (Moon) Percent

func (m Moon) Percent() int

func (Moon) Phase

func (m Moon) Phase() MoonPhase

func (Moon) String

func (m Moon) String() string

func (Moon) TimeOfMoon

func (m Moon) TimeOfMoon() int64

type MoonPhase

type MoonPhase int
const (
	// 新月
	NewMoon MoonPhase = iota

	// 三日月
	WaxingCrescent1

	// 七日月
	WaxingCrescent2

	// 上弦の月
	FirstQuarter

	// 十日夜
	WaxingGibbous1

	// 十三夜
	WaxingGibbous2

	// 満月
	FullMoon

	// 十六夜
	WaningGibbous1

	// 居待月
	WaningGibbous2

	// 下弦の月
	LastQuarter

	// 二十日余月
	WaningCrescent1

	// 二十六夜
	WaningCrescent2
)

func (MoonPhase) String

func (m MoonPhase) String() string

func (MoonPhase) StringLocale

func (m MoonPhase) StringLocale(locale string) string

type Ticker added in v0.2.0

type Ticker struct {
	C <-chan Time
	// contains filtered or unexported fields
}

A Ticker holds a channel that delivers `ticks' of a clock at intervals.

func NewTicker added in v0.2.0

func NewTicker(d Duration) *Ticker

NewTicker returns a new Ticker containing a channel that will send the time with a period specified by the duration argument. It adjusts the intervals or drops ticks to make up for slow receivers. The duration d must be greater than zero; if not, NewTicker will panic. Stop the ticker to release associated resources.

func (*Ticker) Stop added in v0.2.0

func (t *Ticker) Stop()

Stop turns off a ticker. After Stop, no more ticks will be sent. Stop does not close the channel, to prevent a concurrent goroutine reading from the channel from seeing an erroneous "tick".

type Time

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

A Time represents an instant in Vana'diel time with microsecond precision.

func Date

func Date(year, mon, day, hour, min, sec, usec int) Time

Date returns the Time corresponding to given arguments.

func FromEarth

func FromEarth(earth time.Time) Time

FromEarth returns the Time corresponding to the given Earth time.

func FromInt64

func FromInt64(time int64) Time

FromInt64 returns the Time corresponding to the given Vana'diel time (since C.E. 0001-01-01 00:00:00).

func Now

func Now() Time

Now returns the current Vana'diel time.

func (Time) Add

func (t Time) Add(d Duration) Time

Add returns the time t+d.

func (Time) AddDate

func (t Time) AddDate(years int, months int, days int) Time

AddDate returns the time corresponding to adding the given number of years, months and days to t.

func (Time) After

func (t Time) After(u Time) bool

After reports whether the time instant t is after u.

func (Time) Before

func (t Time) Before(u Time) bool

Before reports whether the time instant t is before u.

func (Time) Clock

func (t Time) Clock() (hour, min, sec int)

Clock returns the hour, minute, and second within the day specified by t.

func (Time) Date

func (t Time) Date() (year, mon, day, yday int)

Date returns the year, month, day and day of the year in which t occurs.

func (Time) Day

func (t Time) Day() int

Day returns the day of the month specified by t.

func (Time) Earth

func (t Time) Earth() time.Time

Earth returns the time of Earth.

func (Time) Equal

func (t Time) Equal(u Time) bool

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

func (Time) Hour

func (t Time) Hour() int

Hour returns the hour within the day specified by t, in the range [0, 23].

func (Time) Int64

func (t Time) Int64() int64

Int64 returns t as a int64 since C.E. 0001-01-01 00:00:00.

func (Time) IsZero

func (t Time) IsZero() bool

IsZero reports whether t represents the zero time instant.

func (Time) Microsecond

func (t Time) Microsecond() int

Microsecond returns the microsecond offset within the second specified by t, in the range [0, 999999].

func (Time) Minute

func (t Time) Minute() int

Minute returns the minute offset within the hour specified by t, in the range [0, 59].

func (Time) Month

func (t Time) Month() int

Month returns the month of the year specified by t.

func (Time) Moon

func (t Time) Moon() Moon

Moon returns the moon specified by t.

func (Time) Round

func (t Time) Round(d Duration) Time

Round returns the result of rounding t to the nearest multiple of d. The rounding behavior for halfway values is to round up.

Round operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Round(Hour) may return a time with a non-zero minute.

func (Time) Second

func (t Time) Second() int

Second returns the second offset within the minute specified by t, in the range [0, 59].

func (Time) Strftime

func (t Time) Strftime(format string) string

Strftime formats Vana'diel time according to the directives in the format string. The directives begins with a percent (%) character. Any text not listed as a directive will be passed through to the output string.

The directive consists of a percent (%) character, zero or more flags, optional minimum field width and a conversion specifier as follows.

%<flags><width><conversion>

Flags:

  • don't pad a numerical output. _ use spaces for padding. 0 use zeros for padding. ^ upcase the result string. # change case.

The minimum field width specifies the minimum width.

Format directives:

Date (Year, Month, Day):
  %Y - Year with century (can be negative)
          -0001, 0000, 1995, 2009, 14292, etc.
  %C - year / 100 (round down.  20 in 2009)
  %y - year % 100 (00..99)

  %m - Month of the year, zero-padded (01..12)
          %_m  blank-padded ( 1..12)
          %-m  no-padded (1..12)

  %d - Day of the month, zero-padded (01..30)
          %-d  no-padded (1..30)
  %e - Day of the month, blank-padded ( 1..30)

  %j - Day of the year (001..360)

Time (Hour, Minute, Second, Subsecond):
  %H - Hour of the day, 24-hour clock, zero-padded (00..23)
  %k - Hour of the day, 24-hour clock, blank-padded ( 0..23)

  %M - Minute of the hour (00..59)

  %S - Second of the minute (00..59)

  %L - Millisecond of the second (000..999)
  %N - Fractional seconds digits, default is 6 digits (microsecond)
          %3N  millisecond (3 digits)
          %6N  microsecond (6 digits)

Weekday:
  %A - The full weekday name (``Firesday'')
          %^A  uppercased (``FIRESDAY'')
  %w - Day of the week (Firesday is 0, 0..7)

Seconds since the Epoch:
  %s - Number of seconds since 0001-01-01 00:00:00

Literal string:
  %n - Newline character (\n)
  %t - Tab character (\t)
  %% - Literal ``%'' character

Combination:
  %F - The ISO 8601 date format (%Y-%m-%d)
  %X - Same as %T
  %R - 24-hour time (%H:%M)
  %T - 24-hour time (%H:%M:%S)

func (Time) String

func (t Time) String() string

String returns the time formatted using the format string.

"%Y-%m-%d %H:%M:%S"

func (Time) Sub

func (t Time) Sub(u Time) Duration

Sub returns the duration t-u. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned. To compute t-d for a duration d, use t.Add(-d).

func (Time) Truncate

func (t Time) Truncate(d Duration) Time

Truncate returns the result of rounding t down to a multiple of d.

Truncate operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Truncate(Hour) may return a time with a non-zero minute.

func (Time) Weekday

func (t Time) Weekday() Weekday

Weekday returns the day of the week specified by t.

func (Time) Year

func (t Time) Year() int

Year returns the year in which t occurs.

func (Time) YearDay

func (t Time) YearDay() int

YearDay returns the day of the year specified by t, in the range [1,360].

type Timer added in v0.2.0

type Timer struct {
	C <-chan Time
	// contains filtered or unexported fields
}

The Timer type represents a single event. When the Timer expires, the current time will be sent on C, unless the Timer was created by AfterFunc. A Timer must be created with NewTimer or AfterFunc.

func AfterFunc added in v0.2.0

func AfterFunc(d Duration, f func()) *Timer

AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.

func NewTimer added in v0.2.0

func NewTimer(d Duration) *Timer

NewTimer creates a new Timer that will send the current time on its channel after at least duration d.

func (*Timer) Reset added in v0.2.0

func (t *Timer) Reset(d Duration) bool

Reset changes the timer to expire after duration d. It returns true if the timer had been active, false if the timer had expired or been stopped.

Resetting a timer must take care not to race with the send into t.C that happens when the current timer expires. If a program has already received a value from t.C, the timer is known to have expired, and t.Reset can be used directly. If a program has not yet received a value from t.C, however, the timer must be stopped and—if Stop reports that the timer expired before being stopped—the channel explicitly drained:

if !t.Stop() {
	<-t.C
}
t.Reset(d)

This should not be done concurrent to other receives from the Timer's channel.

Note that it is not possible to use Reset's return value correctly, as there is a race condition between draining the channel and the new timer expiring. Reset should always be invoked on stopped or expired channels, as described above. The return value exists to preserve compatibility with existing programs.

func (*Timer) Stop added in v0.2.0

func (t *Timer) Stop() bool

Stop prevents the Timer from firing. It returns true if the call stops the timer, false if the timer has already expired or been stopped. Stop does not close the channel, to prevent a read from the channel succeeding incorrectly.

To prevent a timer created with NewTimer from firing after a call to Stop, check the return value and drain the channel. For example, assuming the program has not received from t.C already:

if !t.Stop() {
	<-t.C
}

This cannot be done concurrent to other receives from the Timer's channel.

For a timer created with AfterFunc(d, f), if t.Stop returns false, then the timer has already expired and the function f has been started in its own goroutine; Stop does not wait for f to complete before returning. If the caller needs to know whether f is completed, it must coordinate with f explicitly.

type Weekday

type Weekday int

A Weekday specifies a day of the week in Vana'diel (Firesday = 0, ...).

const (
	Firesday Weekday = iota
	Earthsday
	Watersday
	Windsday
	Iceday
	Lightningday
	Lightsday
	Darksday
)

func (Weekday) String

func (w Weekday) String() string

String returns the English name of the day ("Firesday", "Earthsday", ...).

func (Weekday) StringLocale

func (w Weekday) StringLocale(locale string) string

String returns the name of the day by specified locale.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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