Class: Clock::Localized

Inherits:
Object
  • Object
show all
Includes:
Clock
Defined in:
lib/clock/localized.rb,
lib/clock/localized/timezone.rb

Defined Under Namespace

Modules: Defaults, Substitute Classes: Timezone

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Clock

#canonize, #elapsed_milliseconds, included, #iso8601, local, localized, #now, #parse, #timestamp, utc

Methods included from Now

#now

Methods included from Canonize

#canonize

Methods included from ISO8601

#iso8601, #precision

Methods included from Parse

#parse

Methods included from ElapsedMilliseconds

#elapsed_milliseconds

Methods included from Timestamp

#timestamp

Constructor Details

#initialize(timezone) ⇒ Localized

Returns a new instance of Localized.



7
8
9
# File 'lib/clock/localized.rb', line 7

def initialize(timezone)
  @timezone = timezone
end

Instance Attribute Details

#timezoneObject (readonly)

Returns the value of attribute timezone.



5
6
7
# File 'lib/clock/localized.rb', line 5

def timezone
  @timezone
end

Class Method Details

.build(timezone_identifier = nil, utc_reference: nil) ⇒ Object



11
12
13
14
# File 'lib/clock/localized.rb', line 11

def self.build(timezone_identifier=nil, utc_reference: nil)
  timezone = Timezone.build timezone_identifier, utc_reference: utc_reference
  new(timezone)
end

.canonize(time, system_time) ⇒ Object



26
27
28
29
# File 'lib/clock/localized.rb', line 26

def self.canonize(time, system_time)
  time = time.utc
  system_time.utc_to_local time
end

.configure(receiver, timezone_identifier = nil) ⇒ Object



16
17
18
19
20
# File 'lib/clock/localized.rb', line 16

def self.configure(receiver, timezone_identifier=nil)
  instance = build(timezone_identifier)
  receiver.clock = instance
  instance
end

.iso8601(time, precision: nil, system_time: nil) ⇒ Object



31
32
33
34
35
36
# File 'lib/clock/localized.rb', line 31

def self.iso8601(time, precision: nil, system_time: nil)
  time ||= now time, system_time: system_time
  utc_time = time.utc
  local_time = system_time.utc_to_local utc_time
  local_time.iso8601 precision
end

Instance Method Details

#system_timeObject



22
23
24
# File 'lib/clock/localized.rb', line 22

def system_time
  timezone
end