Class: Jamf::TimeZone

Inherits:
JSONObject show all
Defined in:
lib/jamf/api/json_objects/time_zone.rb

Overview

A Time Zone known to Jamf Pro

Constant Summary collapse

OBJECT_MODEL =

Object Model / Attributes See APIObject class documentation for details of how the OBJECT_MODEL hash works.

{

  # @!attribute [r] zoneId
  #   @return [String]
  zoneId: {
    class: :string,
    identifier: :primary,
    read_only: true,
    aliases: [:id]
  },

  # @!attribute displayName
  #   @return [String]
  displayName: {
    class: :string,
    identifier: true,
    read_only: true,
    aliases: [:name]
  },

  # @!attribute [r] region
  #   @return [String]
  region: {
    class: :string,
    read_only: true
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Jamf::JSONObject

Instance Attribute Details

#regionString (readonly)

Returns:



# File 'lib/jamf/api/json_objects/time_zone.rb', line 56

Instance Method Details

#localtime(othertime) ⇒ Time

Give a Time object, whats the matching local time in this TimeZone?

Parameters:

  • othertime (Time)

    a Time or Jamf::Timestamp object

Returns:

  • (Time)

    othertime, in the local time in this time zone



99
100
101
# File 'lib/jamf/api/json_objects/time_zone.rb', line 99

def localtime(othertime)
  othertime.getlocal utc_offset
end

#utc_offsetInteger

Returns The offset from UTC, in seconds.

Returns:

  • (Integer)

    The offset from UTC, in seconds



83
84
85
86
87
88
89
90
91
# File 'lib/jamf/api/json_objects/time_zone.rb', line 83

def utc_offset
  return @utc_offset if @utc_offset

  sign = utc_offset_str[0]
  secs = utc_offset_str[1..2].to_i * 3600
  secs += utc_offset_str[3..4].to_i * 60
  # negate if needed
  @utc_offset =  sign == '+' ? secs : -secs
end

#utc_offset_strString

The offset from UTC, as a string.

This is as it would appear at the end of an ISO8601 formatted time, e.g. -0945 or +1200

Note that ISO8601 accepts the formats: /-hh:mm, /-hhmm, or +/-hh

Returns:

  • (String)

    The offset from UTC, as a string



74
75
76
77
78
79
# File 'lib/jamf/api/json_objects/time_zone.rb', line 74

def utc_offset_str
  return @utc_offset_str if @utc_offset_str

  displayName =~ /\(([+-]\d{4})\)/
  @utc_offset_str = Regexp.last_match[1]
end