Skip to content

Commit

Permalink
Refactor Time::Format to use unix_seconds instead of epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed Sep 4, 2018
1 parent 71811c0 commit f78359e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/time/format/formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ struct Time::Format
io << time.day_of_week.value
end

def epoch
def unix_seconds
io << time.unix_seconds
end

Expand Down
14 changes: 7 additions & 7 deletions src/time/format/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Time::Format
"PDT" => Location.fixed("PDT", -7 * 3600),
}

@epoch : Int64?
@unix_seconds : Int64?
@location : Location?

def initialize(string)
Expand All @@ -36,8 +36,8 @@ struct Time::Format
def time(location : Location? = nil)
@hour += 12 if @pm

if epoch = @epoch
return Time.unix(epoch)
if unix_seconds = @unix_seconds
return Time.unix(unix_seconds)
end

location = @location || location
Expand Down Expand Up @@ -268,17 +268,17 @@ struct Time::Format
consume_number(1)
end

def epoch
epoch_negative = false
def unix_seconds
negative = false
case current_char
when '-'
epoch_negative = true
negative = true
next_char
when '+'
next_char
end

@epoch = consume_number_i64(19) * (epoch_negative ? -1 : 1)
@unix_seconds = consume_number_i64(19) * (negative ? -1 : 1)
end

def time_zone(with_seconds = false)
Expand Down
2 changes: 1 addition & 1 deletion src/time/format/pattern.cr
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct Time::Format
when 'R'
twenty_four_hour_time
when 's'
epoch
unix_seconds
when 'S'
second
when 'T', 'X'
Expand Down

0 comments on commit f78359e

Please sign in to comment.