Class: Synthra::Types::AddressLocation::Timezone

Inherits:
Base
  • Object
show all
Defined in:
lib/synthra/types/address_location/locations.rb

Overview

Timezone type

Constant Summary collapse

TIMEZONES =

Common IANA timezone identifiers

Returns:

  • (Array<String>)

    list of timezone identifiers

[
  "America/New_York",
  "America/Chicago",
  "America/Denver",
  "America/Los_Angeles",
  "Europe/London",
  "Europe/Paris",
  "Europe/Berlin",
  "Asia/Tokyo",
  "Asia/Shanghai",
  "Asia/Dubai",
  "Australia/Sydney",
  "Australia/Melbourne",
  "America/Toronto",
  "America/Mexico_City",
  "America/Sao_Paulo",
  "Africa/Johannesburg",
  "Pacific/Auckland"
].freeze

Instance Method Summary collapse

Instance Method Details

#generate_edge(rng, context, args) ⇒ Object



396
397
398
# File 'lib/synthra/types/address_location/locations.rb', line 396

def generate_edge(rng, context, args)
  ["UTC", "GMT", "Z"].sample(random: rng.instance_variable_get(:@random))
end

#generate_invalid(rng, context, args) ⇒ Object



400
401
402
# File 'lib/synthra/types/address_location/locations.rb', line 400

def generate_invalid(rng, context, args)
  [nil, 123, [], {}].sample(random: rng.instance_variable_get(:@random))
end

#generate_random(rng, context, args) ⇒ String

Generate random timezone

Parameters:

Returns:

  • (String)

    generated timezone identifier



381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/synthra/types/address_location/locations.rb', line 381

def generate_random(rng, context, args)
  # Try Faker first
  adapter = faker_adapter(context)
  if adapter
    adapter.time_zone

  else
    Faker::Address.time_zone
  end

rescue StandardError
  rng.sample(TIMEZONES)
end