Permalink
Browse files

RubyJS.Time basics

  • Loading branch information...
1 parent f7f9925 commit 95dc5e9d1ea623a25b222ec8049e6ac7c41c2723 @hasclass hasclass committed Dec 18, 2012
Showing with 1,977 additions and 1,770 deletions.
  1. +630 −3 lib/corelib/time.coffee
  2. +27 −0 progress.txt
  3. +1 −0 spec/javascripts/support/jasmine.yml
  4. +11 −19 spec/lib/corelib/time/_dump_spec.rb
  5. +10 −19 spec/lib/corelib/time/_load_spec.rb
  6. +5 −0 spec/lib/corelib/time/asctime_spec.coffee
  7. +0 −7 spec/lib/corelib/time/asctime_spec.rb
  8. +126 −0 spec/lib/corelib/time/at_spec.coffee
  9. +0 −172 spec/lib/corelib/time/at_spec.rb
  10. +63 −0 spec/lib/corelib/time/comparison_spec.coffee
  11. +0 −81 spec/lib/corelib/time/comparison_spec.rb
  12. +6 −0 spec/lib/corelib/time/ctime_spec.coffee
  13. +0 −7 spec/lib/corelib/time/ctime_spec.rb
  14. +13 −0 spec/lib/corelib/time/day_spec.coffee
  15. +0 −7 spec/lib/corelib/time/day_spec.rb
  16. +1 −2 spec/lib/corelib/time/dst_spec.rb
  17. +20 −0 spec/lib/corelib/time/dup_spec.coffee
  18. +0 −29 spec/lib/corelib/time/dup_spec.rb
  19. +16 −24 spec/lib/corelib/time/eql_spec.rb
  20. +14 −0 spec/lib/corelib/time/fixtures/classes.coffee
  21. +0 −5 spec/lib/corelib/time/fixtures/classes.rb
  22. +0 −3 spec/lib/corelib/time/fixtures/methods.rb
  23. +9 −0 spec/lib/corelib/time/friday_spec.coffee
  24. +0 −13 spec/lib/corelib/time/friday_spec.rb
  25. +5 −0 spec/lib/corelib/time/getgm_spec.coffee
  26. +0 −7 spec/lib/corelib/time/getgm_spec.rb
  27. +33 −51 spec/lib/corelib/time/getlocal_spec.rb
  28. +5 −0 spec/lib/corelib/time/getutc_spec.coffee
  29. +0 −7 spec/lib/corelib/time/getutc_spec.rb
  30. +15 −0 spec/lib/corelib/time/gm_spec.coffee
  31. +0 −11 spec/lib/corelib/time/gm_spec.rb
  32. +23 −6 spec/lib/corelib/time/gmt_offset_spec.rb
  33. +4 −0 spec/lib/corelib/time/gmt_spec.coffee
  34. +0 −9 spec/lib/corelib/time/gmt_spec.rb
  35. +8 −0 spec/lib/corelib/time/gmtime_spec.coffee
  36. +0 −7 spec/lib/corelib/time/gmtime_spec.rb
  37. +24 −0 spec/lib/corelib/time/gmtoff_spec.coffee
  38. +0 −7 spec/lib/corelib/time/gmtoff_spec.rb
  39. +5 −8 spec/lib/corelib/time/hash_spec.rb
  40. +27 −0 spec/lib/corelib/time/hour_spec.coffee
  41. +0 −20 spec/lib/corelib/time/hour_spec.rb
  42. +2 −0 spec/lib/corelib/time/initialize_copy_spec.coffee
  43. +0 −2 spec/lib/corelib/time/initialize_copy_spec.rb
  44. +20 −0 spec/lib/corelib/time/inspect_spec.coffee
  45. +0 −11 spec/lib/corelib/time/inspect_spec.rb
  46. +1 −2 spec/lib/corelib/time/isdst_spec.rb
  47. +1 −2 spec/lib/corelib/time/local_spec.rb
  48. +34 −53 spec/lib/corelib/time/localtime_spec.rb
  49. +14 −0 spec/lib/corelib/time/mday_spec.coffee
  50. +0 −7 spec/lib/corelib/time/mday_spec.rb
  51. +11 −0 spec/lib/corelib/time/min_spec.coffee
  52. +0 −20 spec/lib/corelib/time/min_spec.rb
  53. +41 −63 spec/lib/corelib/time/minus_spec.rb
  54. +1 −2 spec/lib/corelib/time/mktime_spec.rb
  55. +13 −0 spec/lib/corelib/time/mon_spec.coffee
  56. +0 −7 spec/lib/corelib/time/mon_spec.rb
  57. +7 −0 spec/lib/corelib/time/monday_spec.coffee
  58. +0 −14 spec/lib/corelib/time/monday_spec.rb
  59. +12 −0 spec/lib/corelib/time/month_spec.coffee
  60. +0 −7 spec/lib/corelib/time/month_spec.rb
  61. +76 −0 spec/lib/corelib/time/new_spec.coffee
  62. +0 −88 spec/lib/corelib/time/new_spec.rb
  63. +4 −0 spec/lib/corelib/time/now_spec.coffee
  64. +0 −7 spec/lib/corelib/time/now_spec.rb
  65. +14 −22 spec/lib/corelib/time/nsec_spec.rb
  66. +56 −86 spec/lib/corelib/time/plus_spec.rb
  67. +11 −18 spec/lib/corelib/time/round_spec.rb
  68. +9 −0 spec/lib/corelib/time/saturday_spec.coffee
  69. +0 −13 spec/lib/corelib/time/saturday_spec.rb
  70. +7 −0 spec/lib/corelib/time/sec_spec.coffee
  71. +0 −8 spec/lib/corelib/time/sec_spec.rb
  72. +2 −4 spec/lib/corelib/time/shared/asctime.rb
  73. +7 −13 spec/lib/corelib/time/shared/day.rb
  74. +2 −5 spec/lib/corelib/time/shared/getgm.rb
  75. +6 −13 spec/lib/corelib/time/shared/gm.rb
  76. +15 −26 spec/lib/corelib/time/shared/gmt_offset.rb
  77. +2 −5 spec/lib/corelib/time/shared/gmtime.rb
  78. +12 −22 spec/lib/corelib/time/shared/inspect.rb
  79. +3 −6 spec/lib/corelib/time/shared/isdst.rb
  80. +3 −11 spec/lib/corelib/time/shared/local.rb
  81. +7 −13 spec/lib/corelib/time/shared/month.rb
  82. +3 −8 spec/lib/corelib/time/shared/now.rb
  83. +98 −161 spec/lib/corelib/time/shared/time_params.rb
  84. +2 −4 spec/lib/corelib/time/shared/to_i.rb
  85. +237 −0 spec/lib/corelib/time/strftime_spec.coffee
  86. +0 −292 spec/lib/corelib/time/strftime_spec.rb
  87. +14 −22 spec/lib/corelib/time/subsec_spec.rb
  88. +5 −8 spec/lib/corelib/time/succ_spec.rb
  89. +9 −0 spec/lib/corelib/time/sunday_spec.coffee
  90. +0 −13 spec/lib/corelib/time/sunday_spec.rb
  91. +7 −0 spec/lib/corelib/time/thursday_spec.coffee
  92. +0 −13 spec/lib/corelib/time/thursday_spec.rb
  93. +2 −4 spec/lib/corelib/time/times_spec.rb
  94. +3 −6 spec/lib/corelib/time/to_a_spec.rb
  95. +3 −5 spec/lib/corelib/time/to_f_spec.rb
  96. +5 −0 spec/lib/corelib/time/to_i_spec.coffee
  97. +0 −7 spec/lib/corelib/time/to_i_spec.rb
  98. +6 −10 spec/lib/corelib/time/to_r_spec.rb
  99. +1 −2 spec/lib/corelib/time/to_s_spec.rb
  100. +9 −0 spec/lib/corelib/time/tuesday_spec.coffee
  101. +0 −13 spec/lib/corelib/time/tuesday_spec.rb
  102. +2 −4 spec/lib/corelib/time/tv_nsec_spec.rb
  103. +1 −2 spec/lib/corelib/time/tv_sec_spec.rb
  104. +1 −2 spec/lib/corelib/time/tv_usec_spec.rb
  105. +28 −39 spec/lib/corelib/time/usec_spec.rb
  106. +1 −2 spec/lib/corelib/time/utc_offset_spec.rb
  107. +5 −15 spec/lib/corelib/time/utc_spec.rb
  108. +4 −0 spec/lib/corelib/time/wday_spec.coffee
  109. +0 −10 spec/lib/corelib/time/wday_spec.rb
  110. +8 −0 spec/lib/corelib/time/wednesday_spec.coffee
  111. +0 −13 spec/lib/corelib/time/wednesday_spec.rb
  112. +12 −0 spec/lib/corelib/time/yday_spec.coffee
  113. +0 −10 spec/lib/corelib/time/yday_spec.rb
  114. +11 −0 spec/lib/corelib/time/year_spec.coffee
  115. +0 −20 spec/lib/corelib/time/year_spec.rb
  116. +6 −11 spec/lib/corelib/time/zone_spec.rb
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,27 @@
+Spec completeness
+--------------------
+spec/lib/corelib/array ..........................................................................
+spec/lib/corelib/comparable .
+spec/lib/corelib/enumerable ...............................................
+spec/lib/corelib/enumerator .xxxxxxxxxxxxxxx
+spec/lib/corelib/fixnum ...........................
+spec/lib/corelib/float ..................................
+spec/lib/corelib/hash xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+spec/lib/corelib/integer ....................
+spec/lib/corelib/kernel ....
+spec/lib/corelib/matchdata .....................
+spec/lib/corelib/numeric .......................
+spec/lib/corelib/object xxxxxxxxxxxxx
+spec/lib/corelib/range ......................
+spec/lib/corelib/README.md
+spec/lib/corelib/regexp ........................
+spec/lib/corelib/string ........................................................................x
+spec/lib/corelib/time ................................xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
+spec/lib/corelib/versions xx
+
+Compiled Filesize
+--------------------
+-rw-r--r-- 1 seb staff 235K Dec 18 19:11 ruby.coffee
+-rw-r--r-- 1 seb staff 187K Dec 18 19:11 ruby.js
+-rw-r--r-- 1 seb staff 96K Dec 18 19:11 ruby.min.js
+-rw-r--r-- 1 seb staff 20K Dec 18 19:11 ruby.min.js.gz
@@ -5,6 +5,7 @@ src_files:
- corelib/string/fixtures/classes.js
- corelib/numeric/fixtures/classes.js
- corelib/enumerable/fixtures/classes.js
+ - corelib/time/fixtures/classes.js
spec_dir: spec/javascripts
@@ -1,31 +1,28 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/methods', __FILE__)
-describe "Time#_dump" do
+describe "Time#_dump", ->
before :each do
- @local = Time.at(946812800)
- @t = Time.at(946812800)
+ @local = R.Time.at(946812800)
+ @t = R.Time.at(946812800)
@t = @t.gmtime
@s = @t._dump
- end
ruby_bug("http://redmine.ruby-lang.org/issues/show/627", "1.8.7") do
- it "preserves the GMT flag" do
- @t.gmt?.should == true
+ it "preserves the GMT flag", ->
+ @t.gmt() ).toEqual true
dump = @t._dump.unpack("VV").first
((dump >> 30) & 0x1).should == 1
- @local.gmt?.should == false
+ @local.gmt() ).toEqual false
dump = @local._dump.unpack("VV").first
((dump >> 30) & 0x1).should == 0
- end
- it "dumps a Time object to a bytestring" do
+ it "dumps a Time object to a bytestring", ->
@s.should be_kind_of(String)
@s.should == [3222863947, 2235564032].pack("VV")
- end
- it "dumps an array with a date as first element" do
+ it "dumps an array with a date as first element", ->
high = 1 << 31 |
(@t.gmt? ? 1 : 0) << 30 |
(@t.year - 1900) << 14 |
@@ -34,20 +31,15 @@
@t.hour
high.should == @s.unpack("VV").first
- end
- end
- it "dumps an array with a time as second element" do
+ it "dumps an array with a time as second element", ->
low = @t.min << 26 |
@t.sec << 20 |
@t.usec
low.should == @s.unpack("VV").last
- end
- it "dumps like MRI's marshaled time format" do
- t = Time.utc(2000, 1, 15, 20, 1, 1, 203).localtime
+ it "dumps like MRI's marshaled time format", ->
+ t = R.Time.utc(2000, 1, 15, 20, 1, 1, 203).localtime
t._dump.should == "\364\001\031\200\313\000\020\004"
- end
-end
@@ -1,10 +1,10 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/methods', __FILE__)
-describe "Time#_load" do
+describe "Time#_load", ->
ruby_bug("http://redmine.ruby-lang.org/issues/show/627", "1.8.7") do
- it "loads a time object in the new format" do
- t = Time.local(2000, 1, 15, 20, 1, 1)
+ it "loads a time object in the new format", ->
+ t = R.Time.local(2000, 1, 15, 20, 1, 1)
t = t.gmtime
high = 1 << 31 |
@@ -19,39 +19,30 @@
t.usec
Time._load([high, low].pack("VV")).should == t
- end
- end
- it "loads a time object in the old UNIX timestamp based format" do
- t = Time.local(2000, 1, 15, 20, 1, 1, 203)
+ it "loads a time object in the old UNIX timestamp based format", ->
+ t = R.Time.local(2000, 1, 15, 20, 1, 1, 203)
timestamp = t.to_i
high = timestamp & ((1 << 31) - 1)
low = t.usec
Time._load([high, low].pack("VV")).should == t
- end
- ruby_version_is ''...'1.9' do
- it "loads MRI's marshaled time format" do
+ describe ''...'1.9', ->
+ it "loads MRI's marshaled time format", ->
t = Marshal.load("\004\bu:\tTime\r\320\246\e\200\320\001\r\347")
t.utc
t.to_s.should == "Fri Oct 22 16:57:48 UTC 2010"
- end
- end
- ruby_version_is '1.9' do
- it "loads MRI's marshaled time format" do
+ describe '1.9', ->
+ it "loads MRI's marshaled time format", ->
t = Marshal.load("\004\bu:\tTime\r\320\246\e\200\320\001\r\347")
t.utc
t.to_s.should == "2010-10-22 16:57:48 UTC"
- end
- end
-end
-describe "Time._load" do
+describe "Time._load", ->
it "needs to be reviewed for spec completeness"
-end
@@ -0,0 +1,5 @@
+describe "Time#asctime", ->
+ # it_behaves_like(:time_asctime, :asctime)
+ it "returns a canonical string representation of time", ->
+ t = R.Time.now()
+ expect( t.asctime() ).toEqual t.strftime("%a %b %e %H:%M:%S %Y")
@@ -1,7 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/methods', __FILE__)
-require File.expand_path('../shared/asctime', __FILE__)
-
-describe "Time#asctime" do
- it_behaves_like(:time_asctime, :asctime)
-end
@@ -0,0 +1,126 @@
+
+
+xdescribe "R.Time.at", ->
+ describe "passed Numeric", ->
+ it "returns a Time object representing the given number of Integer seconds since 1970-01-01 00:00:00 UTC", ->
+ expect( R.Time.at(1184027924).getgm().asctime() ).toEqual R("Tue Jul 10 00:38:44 2007")
+
+ it "returns a Time object representing the given number of Float seconds since 1970-01-01 00:00:00 UTC", ->
+ t = R.Time.at(10.5)
+ expect( t.usec() ).toEqual R(500000.0)
+ expect( t.to_i() ).toNotEqual R.Time.at(10).to_i()
+
+ it "returns a non-UTC Time", ->
+ expect( R.Time.at(1184027924).utc() ).toEqual false
+
+ xit "returns a subclass instance on a Time subclass", ->
+ # c = Class.new(Time)
+ # t = c.at(0)
+ # t.should be_kind_of(c)
+
+ describe "passed Time", ->
+ it "creates a new time object with the value given by time", ->
+ t = R.Time.now()
+ expect( R.Time.at(t).inspect() ).toEqual R(t.inspect())
+
+ it "creates a dup time object with the value given by time", ->
+ t1 = R.Time.new()
+ t2 = R.Time.at(t1)
+ expect( t1 is t2).toEqual false
+
+ it "returns a UTC time if the argument is UTC", ->
+ t = R.Time.now().getgm()
+ expect( R.Time.at(t).utc() ).toEqual true
+
+ it "returns a non-UTC time if the argument is non-UTC", ->
+ t = R.Time.now()
+ expect( R.Time.at(t).utc() ).toEqual false
+
+ xit "returns a subclass instance", ->
+ # c = Class.new(Time)
+ # t = c.at(R.Time.now)
+ # t.should be_kind_of(c)
+
+ describe "passed non-Time, non-Numeric", ->
+ it "raises a TypeError with a String argument", ->
+ expect( -> R.Time.at("0") ).toThrow('TypeError')
+
+ it "raises a TypeError with a nil argument", ->
+ expect( -> R.Time.at(null) ).toThrow('TypeError')
+
+ describe "with an argument that responds to #to_int", ->
+ # describe ""..."1.9", ->
+ # it "raises a TypeError", ->
+ # o = mock('integer')
+ # o.should_not_receive(:to_int)
+ # expect( -> R.Time.at(o) ).toThrow('TypeError')
+
+ describe "1.9", ->
+ it "coerces using #to_int", ->
+ o =
+ to_int: -> R(0)
+ expect( R.Time.at(o) ).toEqual R(R.Time.at(0))
+
+ describe "with an argument that responds to #to_r", ->
+ # describe ""..."1.9", ->
+ # it "raises a TypeError", ->
+ # o = mock('rational')
+ # o.should_not_receive(:to_r)
+ # expect( -> R.Time.at(o) ).toThrow('TypeError')
+
+ describe "1.9", ->
+ xit "coerces using #to_r", ->
+ # o =
+ # to_r: -> R.Rational(5, 2)
+ # expect( R.Time.at(o) ).toEqual R(R.Time.at(Rational(5, 2)))
+
+ describe "passed [Integer, Numeric]", ->
+ it "returns a Time object representing the given number of seconds and Integer microseconds since 1970-01-01 00:00:00 UTC", ->
+ t = R.Time.at(10, 500000)
+ expect( t.tv_sec() ).toEqual R(10)
+ expect( t.tv_usec() ).toEqual R(500000)
+
+ describe "1.9", ->
+ it "returns a Time object representing the given number of seconds and Float microseconds since 1970-01-01 00:00:00 UTC", ->
+ t = R.Time.at(10, 500.500)
+ expect( t.tv_sec() ).toEqual R(10)
+ expect( t.tv_nsec ).toEqual R(500500)
+
+ describe "with a second argument that responds to #to_int", ->
+ it "coerces using #to_int", ->
+ o =
+ to_int: -> R(10)
+ expect( R.Time.at(0, o) ).toEqual R(R.Time.at(0, 10))
+
+ describe "with a second argument that responds to #to_r", ->
+ # describe ""..."1.9", ->
+ # it "raises a TypeError", ->
+ # o = mock('rational')
+ # o.should_not_receive(:to_r)
+ # expect( -> R.Time.at(0, o) ).toThrow('TypeError')
+
+ describe "1.9", ->
+ # it "coerces using #to_r", ->
+ # o =
+ # to_r: -> (R.Rational(5, 2))
+ # expect( R.Time.at(0, o) ).toEqual R(R.Time.at(0, Rational(5, 2)))
+
+ describe "passed [Integer, nil]", ->
+ it "raises a TypeError", ->
+ expect( -> R.Time.at(0, null) ).toThrow('TypeError')
+
+ describe "passed [Integer, String]", ->
+ it "raises a TypeError", ->
+ expect( -> R.Time.at(0, "0") ).toThrow('TypeError')
+
+ describe "passed [Time, Integer]", ->
+ # describe ""..."1.9", ->
+ # it "raises a TypeError", ->
+ # expect( -> R.Time.at(R.Time.now, 500000) ).toThrow('TypeError')
+
+ describe "1.9", ->
+ it "returns a Time object equal to the specified time plus the number of microseconds", ->
+ t1 = R.Time.at(10)
+ t2 = R.Time.at(t1, 500000)
+ expect( t2.tv_sec() ).toEqual R(10)
+ expect( t2.tv_usec() ).toEqual R(500000)
Oops, something went wrong.

0 comments on commit 95dc5e9

Please sign in to comment.