Skip to content

Commit

Permalink
Add stubs for methods with file acces
Browse files Browse the repository at this point in the history
Trying to load a location from a file will fail because `File` is not
yet ported to windows.
  • Loading branch information
straight-shoota committed Jan 17, 2018
1 parent ae7e6b8 commit 5adea55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/generate_windows_zone_names.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require "xml"
require "../src/compiler/crystal/formatter"

WINDOWS_ZONE_NAMES_SOURCE = "http://unicode.org/cldr/data/common/supplemental/windowsZones.xml"
TARGET_FILE = File.join(__DIR__, "..", "src", "crystal", "system", "win32", "zone_names.cr")
TARGET_FILE = File.join(__DIR__, "..", "src", "crystal", "system", "win32", "zone_names.cr")

response = HTTP::Client.get(WINDOWS_ZONE_NAMES_SOURCE)

Expand Down
6 changes: 3 additions & 3 deletions src/crystal/system/win32/time.cr
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module Crystal::System::Time

zones = [
::Time::Location::Zone.new(stdname, (info.bias + info.standardBias) * BIAS_TO_OFFSET_FACTOR, false),
::Time::Location::Zone.new(dstname, (info.bias + info.daylightBias) * BIAS_TO_OFFSET_FACTOR, true)
::Time::Location::Zone.new(dstname, (info.bias + info.daylightBias) * BIAS_TO_OFFSET_FACTOR, true),
]

first_date = info.standardDate
Expand Down Expand Up @@ -127,7 +127,7 @@ module Crystal::System::Time

time += (day - 1).days

return time.epoch
time.epoch
end

# Normalizes the names of the standard and dst zones.
Expand Down Expand Up @@ -155,6 +155,6 @@ module Crystal::System::Time
# and returns the English name.
private def self.translate_zone_name(stdname, dstname)
# TODO: Needs implementation once there is access to the registry.
return nil
nil
end
end
8 changes: 8 additions & 0 deletions src/time/location/loader.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class Time::Location

# :nodoc:
def self.load_from_dir_or_zip(name : String, source : String)
{% if flag?(:win32) %}
raise NotImplementedError.new("Time::Location.load_from_dir_or_zip")
{% else %}
if source.ends_with?(".zip")
open_file_cached(name, source) do |file|
read_zip_file(name, file) do |io|
Expand All @@ -35,6 +38,7 @@ class Time::Location
read_zoneinfo(name, file)
end
end
{% end %}
end

private def self.open_file_cached(name : String, path : String)
Expand All @@ -57,6 +61,9 @@ class Time::Location

# :nodoc:
def self.find_zoneinfo_file(name : String, sources : Enumerable(String))
{% if flag?(:win32) %}
raise NotImplementedError.new("Time::Location.find_zoneinfo_file")
{% else %}
sources.each do |source|
if source.ends_with?(".zip")
return source if File.exists?(source)
Expand All @@ -65,6 +72,7 @@ class Time::Location
return source if File.exists?(path)
end
end
{% end %}
end

# Parse "zoneinfo" time zone file.
Expand Down

0 comments on commit 5adea55

Please sign in to comment.