File: spec_helper.cr

package info (click to toggle)
crystal 1.6.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 18,956 kB
  • sloc: javascript: 1,712; sh: 592; cpp: 541; makefile: 243; ansic: 119; python: 105; xml: 32
file content (34 lines) | stat: -rw-r--r-- 569 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require "../spec_helper"

class Time::Location
  def __cached_zone=(zone)
    @cached_zone = zone
  end

  def self.__clear_location_cache
    @@location_cache.clear
  end
end

def with_env(name, value)
  previous = ENV[name]?
  begin
    ENV[name] = value

    # Reset local time zone
    Time::Location.local = Time::Location.load_local
    yield
  ensure
    ENV[name] = previous
  end
end

ZONEINFO_ZIP = datapath("zoneinfo.zip")

def with_zoneinfo(path = ZONEINFO_ZIP)
  with_env("ZONEINFO", path) do
    Time::Location.__clear_location_cache

    yield
  end
end