Skip to content

Commit

Permalink
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spec/std/time/time_spec.cr
Original file line number Diff line number Diff line change
@@ -459,6 +459,12 @@ describe Time do
time.to_utc.to_s.should eq("2014-10-31 16:11:12 UTC")
end

it "parses microseconds" do
time = Time.parse("2016-09-09T17:03:28.456789+01:00", "%FT%T.%L%z").to_utc
time.to_s.should eq("2016-09-09 16:03:28 UTC")
time.millisecond.should eq(456)
end

it "parses the correct amount of digits (#853)" do
time = Time.parse("20150624", "%Y%m%d")
time.year.should eq(2015)
10 changes: 9 additions & 1 deletion src/time/format/parser.cr
Original file line number Diff line number Diff line change
@@ -164,7 +164,15 @@ struct Time::Format
end

def milliseconds
@millisecond = consume_number(3)
# Consume more than 3 digits (12 seems a good maximum),
# and later just use the first 3 digits because Time
# only has microsecond precision.

This comment has been minimized.

Copy link
@bcardiff

bcardiff Sep 22, 2016

Member

🔍 Either the ivar name or the comment is wrong.
@millisecond vs Time only has _micro_second precision.

pos = @reader.pos
@millisecond = consume_number(12)
digits = @reader.pos - pos
if digits > 3
@millisecond /= 10 ** (digits - 3)
end
end

def am_pm

0 comments on commit 026f632

Please sign in to comment.