diff options
| author | KOBAYASHI Shuji <[email protected]> | 2019-05-14 22:05:45 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2019-05-14 22:50:36 +0900 |
| commit | edf4b33c61d04148ef11406d37256feda5fe78fb (patch) | |
| tree | 467356b689e5744116bc54de7ef9e7e6a306fe00 /mrbgems/mruby-time/test | |
| parent | d8eff635fd70360eb83849fa2a19413b1ffeaaeb (diff) | |
| download | mruby-edf4b33c61d04148ef11406d37256feda5fe78fb.tar.gz mruby-edf4b33c61d04148ef11406d37256feda5fe78fb.zip | |
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.
Diffstat (limited to 'mrbgems/mruby-time/test')
| -rw-r--r-- | mrbgems/mruby-time/test/time.rb | 4 |
1 files changed, 2 insertions, 2 deletions
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 |
