Module: AkatoshBot::Time

Defined in:
lib/akatosh_bot.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.tamriel(time = self.utc, opts = {}) ⇒ Object



45
46
47
# File 'lib/akatosh_bot.rb', line 45

def self.tamriel time = self.utc, opts = {}
  time.tamriel opts
end

Instance Method Details

#tamriel(opts = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/akatosh_bot.rb', line 5

def tamriel opts = {}
  d = mday
  e = opts[:era].is_a?(Fixnum) ? opts[:era] : 4
  i = opts[:year]
  m = month
  w = wday
  y = year
  # Time.wday is (0..7)
  tam_wday = %w[
    Sundas
    Morndas
    Tirdas
    Middas
    Turdas
    Fredas
    Loredas
  ][w]
  datesuf = %w[th st nd rd][d / 10 != 1 && d % 10 < 4 ? d % 10 : 0]
  # Time.month is (1..12)
  tam_month = [
    "Morning Star",
    "Sun's Dawn",
    "First Seed",
    "Rain's Hand",
    "Second Seed",
    "Midyear",
    "Sun's Height",
    "Last Seed",
    "Hearthfire",
    "Frostfall",
    "Sun's Dusk",
    "Evening Star"
  ][m - 1]
  # If passed a string, print it verbatim
  # Elsif passed a number, print it in the current (4th) era
  # Elsif passed a boolean, use it to determine whether to print the year
  tam_year = i.is_a?(String) ? ", #{i}" : i ? ", #{e}E#{i.is_a?(Fixnum) ? i : y - 1810}" : ""
  "#{tam_wday}, #{d}#{datesuf} of #{tam_month}#{tam_year}"
end