class BBS::Season
The time of day, the season and the holidays at a place, for choosing the layers of a BBS::Art: the sky of a scene at dawn, by day, at dusk or at night, snow in winter, a pumpkin at the end of October, fireworks on New Year’s Eve, bunting in the week of a game jam.
Pure and deterministic: everything follows from the instant (at, default now), the time zone and the place, so a test passes the time it wants.
s = BBS::Season.now # Budapest, now s.time_of_day # => :night s.layers # => [:snow] art.with(*s.layers) BBS::Season.now(at: Time.utc(2026, 12, 31, 21), jam: Date.new(2027, 1, 8)..Date.new(2027, 1, 10)) # => fireworks and snow, at night
The times of day follow the sun: :dawn is the hour around sunrise (TWILIGHT minutes either side), :day until the hour around sunset, :dusk, and :night after it. Sunrise and sunset are worked out for latitude and longitude (Budapest by default) to within a few minutes.
The layers, a Symbol each:
:snow-
December to February
:pumpkin-
PUMPKIN: the last week of October
:fireworks-
New Year’s Eve, and the small hours of New Year’s Day (until
FIREWORKS_UNTIL) :bunting-
the days of
jam, a Range of Date
Constants
- FIREWORKS_UNTIL
-
The hour of New Year’s Day the fireworks stop.
- LATITUDE
-
Budapest’s latitude.
- LONGITUDE
-
Budapest’s longitude.
- OFFSET_RE
-
A fixed offset written as a time zone: +01:00, -0530.
- PUMPKIN
-
The days of the pumpkin: the month and the days of the month.
- SEASONS
-
The seasons by month (meteorological: winter is December to February).
- SNOW
-
The months of the snow.
- TWILIGHT
-
The minutes on either side of sunrise that are dawn, and of sunset that are dusk.
- ZONES
-
The time zones known without the
tzinfogem: name => [standard offset in seconds, whether it keeps EU summer time].
Attributes
The holiday and season layers in effect, an Array of Symbol (see the class description).
:winter, :spring, :summer or :autumn.
Today’s sunrise and sunset, local Times (nil on a day the sun does not rise or set).
Today’s sunrise and sunset, local Times (nil on a day the sun does not rise or set).
The local time (a Time with the zone’s offset).
:dawn, :day, :dusk or :night.
Public Class Methods
# File lib/bbs/season.rb, line 95 def initialize(time, jam: nil, latitude: LATITUDE, longitude: LONGITUDE) @time = time @latitude = latitude @season = SEASONS.fetch(time.month) @sunrise, @sunset = local_sun(latitude, longitude) @time_of_day = find_time_of_day @layers = find_layers(jam) end
Source
# File lib/bbs/season.rb, line 89 def self.now(tz: 'Europe/Budapest', at: Time.now, jam: nil, latitude: LATITUDE, longitude: LONGITUDE) new(at.getlocal(offset(tz, at.getutc)), jam: jam, latitude: latitude, longitude: longitude) end
The Season at at (a Time, default now) in time zone tz.
- tz
-
a zone name: one of
ZONES, any IANA name when thetzinfogem is installed, or a fixed offset ('+01:00'); or an object withutc_offset_at/ a TZInfo::Timezone - jam
-
the days of a game jam, a Range of Date (or of
'YYYY-MM-DD'Strings), for:bunting;nilfor none - latitude
-
the place’s latitude, for the sun
- longitude
-
the place’s longitude, east positive
Raises ArgumentError for a time zone it does not know.
Public Instance Methods
Source
# File lib/bbs/season.rb, line 105 def dawn? = @time_of_day == :dawn
Whether it is dawn.
Source
# File lib/bbs/season.rb, line 108 def day? = @time_of_day == :day
Whether it is day.
Source
# File lib/bbs/season.rb, line 111 def dusk? = @time_of_day == :dusk
Whether it is dusk.
Source
# File lib/bbs/season.rb, line 117 def layer?(name) = @layers.include?(name.to_sym)
Whether layer name (a Symbol or String) is in effect.
Source
# File lib/bbs/season.rb, line 122 def names = [@time_of_day, @season, *@layers]
Every name in effect: the time of day, the season and the layers, for art.with(*season.names) when an art has layers by those names.
Source
# File lib/bbs/season.rb, line 114 def night? = @time_of_day == :night
Whether it is night.