Sha256: da04d1e1336596d4485eb3375d266e8f37fc0e024e00a3d34e61c3c6147afbcf

Contents?: true

Size: 1.16 KB

Versions: 83

Compression:

Stored size: 1.16 KB

Contents

def with_timezone(name, offset = nil, daylight_saving_zone = "")
  zone = name.dup

  if (offset)
    # TZ convention is backwards
    offset = -offset

    zone << offset.to_s
    zone << ":00:00"
  end
  zone << daylight_saving_zone

  old = ENV["TZ"]
  ENV["TZ"] = zone

  begin
    yield
  ensure
    ENV["TZ"] = old
  end
end

# Returns the given time in the same format as returned by
# Time.at(seconds).inspect on MRI 1.8
def localtime_18(seconds)
  platform_is :os => [:darwin, :bsd] do
    return `LC_ALL=C date -r #{seconds} +'%a %b %d %H:%M:%S %z %Y'`.chomp
  end

  platform_is :os => :linux do
    return `LC_ALL=C date -d @#{seconds} +'%a %b %d %H:%M:%S %z %Y'`.chomp
  end

  return `LC_ALL=C date -j -f "%s" #{seconds} "+%a %b %d %H:%M:%S %z %Y"`.chomp
end

# Returns the given time in the same format as returned by
# Time.at(seconds).inspect on MRI 1.9
def localtime_19(seconds)
  platform_is :os => [:darwin, :bsd] do
    return `LC_ALL=C date -r #{seconds} +'%F %H:%M:%S %z'`.chomp
  end

  platform_is :os => :linux do
    return `LC_ALL=C date -d @#{seconds} +'%F %H:%M:%S %z'`.chomp
  end

  return `LC_ALL=C date -j -f "%s" #{seconds} "+%F %H:%M:%S %z"`.chomp
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
rhodes-3.0.0.beta.6 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-3.0.0.beta.5 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-3.0.0.beta.4 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-3.0.0.beta.3 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-3.0.0.beta.2 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-3.0.0.beta.1 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.4.1 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.4.1.beta.1 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.4.0 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.4.0.beta.2 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.4.0.beta.1 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.3.2 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.3.2.beta.2 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.3.2.beta.1 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.3.1 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.3.1.beta.1 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.3.0 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.3.0.beta.3 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.3.0.beta.2 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.3.0.beta.1 spec/framework_spec/app/spec/core/time/fixtures/methods.rb