Documentation ¶
Index ¶
- Constants
- func After(d Duration) <-chan Time
- func Sleep(d Duration)
- func Tick(d Duration) <-chan Time
- type Duration
- type Moon
- type MoonPhase
- type Ticker
- type Time
- func (t Time) Add(d Duration) Time
- func (t Time) AddDate(years int, months int, days int) Time
- func (t Time) After(u Time) bool
- func (t Time) Before(u Time) bool
- func (t Time) Clock() (hour, min, sec int)
- func (t Time) Date() (year, mon, day, yday int)
- func (t Time) Day() int
- func (t Time) Earth() time.Time
- func (t Time) Equal(u Time) bool
- func (t Time) Hour() int
- func (t Time) Int64() int64
- func (t Time) IsZero() bool
- func (t Time) Microsecond() int
- func (t Time) Minute() int
- func (t Time) Month() int
- func (t Time) Moon() Moon
- func (t Time) Round(d Duration) Time
- func (t Time) Second() int
- func (t Time) Strftime(format string) string
- func (t Time) String() string
- func (t Time) Sub(u Time) Duration
- func (t Time) Truncate(d Duration) Time
- func (t Time) Weekday() Weekday
- func (t Time) Year() int
- func (t Time) YearDay() int
- type Timer
- type Weekday
Constants ¶
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 )
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
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
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 ¶
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 (Duration) Microseconds ¶
Microseconds returns the duration as an integer microsecond count.
func (Duration) Round ¶
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) 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.
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
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.
type Time ¶
type Time struct {
// contains filtered or unexported fields
}
A Time represents an instant in Vana'diel time with microsecond precision.
func FromInt64 ¶
FromInt64 returns the Time corresponding to the given Vana'diel time (since C.E. 0001-01-01 00:00:00).
func (Time) AddDate ¶
AddDate returns the time corresponding to adding the given number of years, months and days to t.
func (Time) Microsecond ¶
Microsecond returns the microsecond offset within the second specified by t, in the range [0, 999999].
func (Time) Minute ¶
Minute returns the minute offset within the hour specified by t, in the range [0, 59].
func (Time) Round ¶
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 ¶
Second returns the second offset within the minute specified by t, in the range [0, 59].
func (Time) Strftime ¶
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) Sub ¶
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 ¶
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.
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
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
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
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
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.