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-2.0.2 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.rc2 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.rc1 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.beta11 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.beta10 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.beta9 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.beta8 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.beta7 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.beta6 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.beta4 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.beta3 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-1.5.5 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.beta2 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-2.0.0.beta1 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-1.5.4 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-1.5.3 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-1.5.2 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-1.5.1 spec/framework_spec/app/spec/core/time/fixtures/methods.rb
rhodes-1.5.0 spec/framework_spec/app/spec/core/time/fixtures/methods.rb