From edf4b33c61d04148ef11406d37256feda5fe78fb Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Tue, 14 May 2019 22:05:45 +0900 Subject: Refine `Time#(to_s|inspect)` For the following reasons: - Ruby compatibility. - Add UTC offset (time zone informations was not included by #4433). - More readable. Example: Before this patch: p Time.gm(2003,4,5,6,7,8,9) #=> Sat Apr 5 06:07:08 2003 p Time.local(2013,10,28,16,27,48) #=> Mon Oct 28 16:27:48 2013 After this patch: p Time.gm(2003,4,5,6,7,8,9) #=> 2003-04-05 06:07:08 UTC p Time.local(2013,10,28,16,27,48) #=> 2013-10-28 16:27:48 +0900 Implementation: I use `strftime(3)` because UTC offset can be added and program size become smaller than the other implementations (using `sprintf(3)`, self conversion etc) in my environment. --- mrbgems/mruby-time/test/time.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mrbgems/mruby-time/test') diff --git a/mrbgems/mruby-time/test/time.rb b/mrbgems/mruby-time/test/time.rb index c7ad35ab2..ce7b39928 100644 --- a/mrbgems/mruby-time/test/time.rb +++ b/mrbgems/mruby-time/test/time.rb @@ -235,11 +235,11 @@ end # Not ISO specified assert('Time#to_s') do - assert_equal("Sun Mar 13 07:06:40 2011", Time.at(1300000000.0).utc.to_s) + assert_equal("2003-04-05 06:07:08 UTC", Time.gm(2003,4,5,6,7,8,9).to_s) end assert('Time#inspect') do - assert_equal("Sun Mar 13 07:06:40 2011", Time.at(1300000000.0).utc.inspect) + assert_match("2013-10-28 16:27:48 [^U]*", Time.local(2013,10,28,16,27,48).inspect) end assert('day of week methods') do -- cgit v1.2.3