Class: Time

Inherits:
Object show all
Defined in:
runtime/ext/time.rb,
runtime/ext/time.rbs

Overview

Time — the date helpers. Every method delegates to Snails::DateAndTime::Calculations, which owns the civil-calendar arithmetic: day shifts walk the calendar (DST cannot move the clock), month steps clamp to the target month's last day, and rendering keeps the receiver's zone (the process zone, UTC, or a fixed offset).

The reopen makes Time-typed parameter slots strict program-wide: a known-type non-Time argument is a build refusal, an unknown-type one a boundary TypeError before the body runs — so no method needs an in-body guard.

Zone conversion lives in Snails::TimeZone, not here.

Instance Method Summary collapse

Instance Method Details

#beginning_of_day ⇒ Time

midnight in the receiver's zone; a UTC receiver stays UTC and a fixed-offset receiver keeps that offset.

Returns:

  • (Time) —

    this instant's day at midnight



48
# File 'runtime/ext/time.rb', line 48

def beginning_of_day: () -> Time

#beginning_of_hour ⇒ Time

minutes and below zeroed.

Returns:

  • (Time) —

    this instant at the start of its hour



33
# File 'runtime/ext/time.rb', line 33

def beginning_of_hour: () -> Time

#beginning_of_minute ⇒ Time

seconds and sub-seconds zeroed.

Returns:

  • (Time) —

    this instant at the start of its minute



19
# File 'runtime/ext/time.rb', line 19

def beginning_of_minute: () -> Time

#beginning_of_month ⇒ Time

the 1st at midnight.

Returns:

  • (Time) —

    the 1st of this instant's month at midnight



97
# File 'runtime/ext/time.rb', line 97

def beginning_of_month: () -> Time

#beginning_of_week ⇒ Time

Monday, not Sunday (the calendar's week start).

Returns:

  • (Time) —

    the week's Monday



69
# File 'runtime/ext/time.rb', line 69

def beginning_of_week: () -> Time

#beginning_of_year ⇒ Time

January 1st at midnight.

Returns:

  • (Time) —

    January 1st of this instant's year at midnight



111
# File 'runtime/ext/time.rb', line 111

def beginning_of_year: () -> Time

#days_ago(n = 1) ⇒ Time

n civil days earlier at the same clock time.

Returns:

  • (Time) —

    this instant n civil days earlier



134
# File 'runtime/ext/time.rb', line 134

def days_ago: (?Integer n) -> Time

#days_since(n = 1) ⇒ Time

n civil days later at the same clock time.

Returns:

  • (Time) —

    this instant n civil days later



127
# File 'runtime/ext/time.rb', line 127

def days_since: (?Integer n) -> Time

#end_of_day ⇒ Time

23:59:59.999999999, the inclusive end.

Returns:

  • (Time) —

    this day's inclusive end



55
# File 'runtime/ext/time.rb', line 55

def end_of_day: () -> Time

#end_of_hour ⇒ Time

59:59.999999999, the inclusive end.

Returns:

  • (Time) —

    this hour's inclusive end



40
# File 'runtime/ext/time.rb', line 40

def end_of_hour: () -> Time

#end_of_minute ⇒ Time

59.999999999 seconds, the inclusive end.

Returns:

  • (Time) —

    this minute's inclusive end



26
# File 'runtime/ext/time.rb', line 26

def end_of_minute: () -> Time

#end_of_month ⇒ Time

the last day's inclusive end (leap years included).

Returns:

  • (Time) —

    this month's last day at its inclusive end



104
# File 'runtime/ext/time.rb', line 104

def end_of_month: () -> Time

#end_of_week ⇒ Time

the following Sunday's inclusive end.

Returns:

  • (Time) —

    the following Sunday's inclusive end



76
# File 'runtime/ext/time.rb', line 76

def end_of_week: () -> Time

#end_of_year ⇒ Time

December 31st's inclusive end.

Returns:

  • (Time) —

    December 31st's inclusive end



118
# File 'runtime/ext/time.rb', line 118

def end_of_year: () -> Time

#future? ⇒ Boolean

after now.

Returns:

  • (Boolean) —

    true when the receiver is after now



236
# File 'runtime/ext/time.rb', line 236

def future?: () -> bool

#in_time_zone(zone) ⇒ Time

the same instant rendered in zone (a name from the runtime's zone vocabulary, Snails::TimeZone::ZONE_NAMES, or an IANA identifier); nil renders in the current zone.

Returns:

  • (Time) —

    this instant rendered in zone



268
# File 'runtime/ext/time.rb', line 268

def in_time_zone: (String? zone) -> Time

#months_ago(n = 1) ⇒ Time

the calendar-month step back.

Returns:

  • (Time) —

    this instant n calendar months back



177
# File 'runtime/ext/time.rb', line 177

def months_ago: (?Integer n) -> Time

#months_since(n = 1) ⇒ Time

n calendar months forward, clamped to the target month's last day (Jan 31

  • 1 month is Feb 28).

Returns:

  • (Time) —

    this instant n calendar months forward



170
# File 'runtime/ext/time.rb', line 170

def months_since: (?Integer n) -> Time

#next_week ⇒ Time

the next week's Monday, not the receiver plus 7 days.

Returns:

  • (Time) —

    the next week's Monday



83
# File 'runtime/ext/time.rb', line 83

def next_week: () -> Time

#noon ⇒ Time

12:00:00 of the receiver's day.

Returns:

  • (Time) —

    this instant's day at 12:00:00



62
# File 'runtime/ext/time.rb', line 62

def noon: () -> Time

#on_wday?(wday) ⇒ Boolean

the weekday number matches (0 = Sunday).

Returns:

  • (Boolean) —

    true when the receiver falls on that weekday



257
# File 'runtime/ext/time.rb', line 257

def on_wday?: (Integer wday) -> bool

#on_weekday? ⇒ Boolean

the negation of on_weekend?.

Returns:

  • (Boolean) —

    true on any day but Saturday and Sunday



250
# File 'runtime/ext/time.rb', line 250

def on_weekday?: () -> bool

#on_weekend? ⇒ Boolean

Saturday or Sunday.

Returns:

  • (Boolean) —

    true when the receiver falls on Saturday or Sunday



243
# File 'runtime/ext/time.rb', line 243

def on_weekend?: () -> bool

#past? ⇒ Boolean

before now.

Returns:

  • (Boolean) —

    true when the receiver is before now



229
# File 'runtime/ext/time.rb', line 229

def past?: () -> bool

#prev_week ⇒ Time

the previous week's Monday.

Returns:

  • (Time) —

    the previous week's Monday



90
# File 'runtime/ext/time.rb', line 90

def prev_week: () -> Time

#same_day?(other) ⇒ Boolean

both fall on the same civil day, clock time irrelevant.

Returns:

  • (Boolean) —

    true when the two instants share a civil day



201
# File 'runtime/ext/time.rb', line 201

def same_day?: (Time other) -> bool

#to_fs(name) ⇒ String

:db is the stored datetime column form (UTC, microsecond precision), :iso8601 the JSON spelling: millisecond truncation and the zone's offset. The :db result is lexicographically ordered, so it sorts as text.

Parameters:

  • name (Symbol) —

    :db for the stored form, :iso8601 for the JSON spelling

Returns:

  • (String) —

    this instant in the requested spelling

Raises:

  • (ArgumentError) —

    name is neither :db nor :iso8601



280
# File 'runtime/ext/time.rb', line 280

def to_fs: (Symbol name) -> String

#today? ⇒ Boolean

same civil day as now.

Returns:

  • (Boolean) —

    true when the receiver falls on today's civil day



208
# File 'runtime/ext/time.rb', line 208

def today?: () -> bool

#tomorrow ⇒ Time

one civil day forward.

Returns:

  • (Time) —

    this instant one civil day forward



148
# File 'runtime/ext/time.rb', line 148

def tomorrow: () -> Time

#tomorrow? ⇒ Boolean

same civil day as one day forward from now.

Returns:

  • (Boolean) —

    true when the receiver falls on tomorrow's civil day



222
# File 'runtime/ext/time.rb', line 222

def tomorrow?: () -> bool

#weeks_ago(n = 1) ⇒ Time

n seven-day steps back.

Returns:

  • (Time) —

    this instant n seven-day steps back



162
# File 'runtime/ext/time.rb', line 162

def weeks_ago: (?Integer n) -> Time

#weeks_since(n = 1) ⇒ Time

n seven-day steps forward.

Returns:

  • (Time) —

    this instant n seven-day steps forward



155
# File 'runtime/ext/time.rb', line 155

def weeks_since: (?Integer n) -> Time

#years_ago(n = 1) ⇒ Time

the calendar-year step back.

Returns:

  • (Time) —

    this instant n calendar years back



192
# File 'runtime/ext/time.rb', line 192

def years_ago: (?Integer n) -> Time

#years_since(n = 1) ⇒ Time

n calendar years forward, clamped like a month step (Feb 29 in a leap year lands on Feb 28).

Returns:

  • (Time) —

    this instant n calendar years forward



185
# File 'runtime/ext/time.rb', line 185

def years_since: (?Integer n) -> Time

#yesterday ⇒ Time

one civil day back.

Returns:

  • (Time) —

    this instant one civil day back



141
# File 'runtime/ext/time.rb', line 141

def yesterday: () -> Time

#yesterday? ⇒ Boolean

same civil day as one day back from now.

Returns:

  • (Boolean) —

    true when the receiver falls on yesterday's civil day



215
# File 'runtime/ext/time.rb', line 215

def yesterday?: () -> bool