Class: Reprise::TimeZoneIdentifier Private

Inherits:
Object
  • Object
show all
Defined in:
lib/reprise/time_zone_identifier.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

UTC_TIME_ZONE_IDENTIFIER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

github.com/rails/rails/blob/19eebf6d33dd15a0172e3ed2481bec57a89a2404/activesupport/lib/active_support/values/time_zone.rb#L76

"Etc/UTC"

Instance Method Summary collapse

Constructor Details

#initialize(time_zone: nil, datetime_source:) ⇒ TimeZoneIdentifier

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TimeZoneIdentifier.

Parameters:

  • time_zone (String) (defaults to: nil)

    Must be an unambiguous, valid Rails time zone string or IANA time-zone identifier according to ActiveSupport::TimeZone::find_tzinfo. See github.com/tzinfo/tzinfo/issues/53

  • datetime_source (Time, ActiveSupport::TimeWithZone)

    A time value from which the time zone will be inferred. Only considered if no explicit time_zone option is given.



21
22
23
24
# File 'lib/reprise/time_zone_identifier.rb', line 21

def initialize(time_zone: nil, datetime_source:)
  @time_zone = time_zone
  @datetime_source = datetime_source
end

Instance Method Details

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Defaults to UTC if no time zone is passed and the datetime source lacks time zone information.

Returns:

  • (String)

    IANA Time Zone Database identifier

Raises:



29
30
31
32
33
34
35
36
# File 'lib/reprise/time_zone_identifier.rb', line 29

def to_s
  return ActiveSupport::TimeZone.find_tzinfo(time_zone).identifier if time_zone
  return datetime_source.time_zone.tzinfo.identifier if datetime_source.is_a?(ActiveSupport::TimeWithZone)

  UTC_TIME_ZONE_IDENTIFIER
rescue TZInfo::InvalidTimezoneIdentifier
  raise InvalidTimeZoneError, invalid_time_zone_identifier_error
end