smart_month 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +33 -0
  3. data/Rakefile +51 -0
  4. data/VERSION +1 -0
  5. data/lib/month.rb +26 -0
  6. data/lib/smart_month.rb +11 -0
  7. data/lib/smart_month/calculations.rb +87 -0
  8. data/lib/smart_month/collection.rb +51 -0
  9. data/lib/smart_month/extensions/date.rb +19 -0
  10. data/lib/smart_month/magic.rb +71 -0
  11. data/lib/smart_month/math.rb +41 -0
  12. data/lib/smart_month/rulesets.rb +151 -0
  13. data/lib/smart_month/util.rb +37 -0
  14. data/pkg/smart_month-1.0.0.gem +0 -0
  15. data/rdoc/classes/Date.html +209 -0
  16. data/rdoc/classes/Month.html +189 -0
  17. data/rdoc/classes/SmartMonth.html +136 -0
  18. data/rdoc/classes/SmartMonth/Calculations.html +383 -0
  19. data/rdoc/classes/SmartMonth/Collection.html +306 -0
  20. data/rdoc/classes/SmartMonth/Magic.html +214 -0
  21. data/rdoc/classes/SmartMonth/Magic/MonthFactory.html +178 -0
  22. data/rdoc/classes/SmartMonth/Math.html +311 -0
  23. data/rdoc/classes/SmartMonth/Rulesets.html +419 -0
  24. data/rdoc/classes/SmartMonth/Util.html +302 -0
  25. data/rdoc/classes/Time.html +152 -0
  26. data/rdoc/created.rid +1 -0
  27. data/rdoc/files/README.html +170 -0
  28. data/rdoc/files/lib/month_rb.html +113 -0
  29. data/rdoc/files/lib/smart_month/calculations_rb.html +101 -0
  30. data/rdoc/files/lib/smart_month/collection_rb.html +101 -0
  31. data/rdoc/files/lib/smart_month/extensions/date_rb.html +108 -0
  32. data/rdoc/files/lib/smart_month/magic_rb.html +101 -0
  33. data/rdoc/files/lib/smart_month/math_rb.html +101 -0
  34. data/rdoc/files/lib/smart_month/rulesets_rb.html +108 -0
  35. data/rdoc/files/lib/smart_month/util_rb.html +101 -0
  36. data/rdoc/files/lib/smart_month_rb.html +108 -0
  37. data/rdoc/fr_class_index.html +37 -0
  38. data/rdoc/fr_file_index.html +36 -0
  39. data/rdoc/fr_method_index.html +74 -0
  40. data/rdoc/index.html +24 -0
  41. data/rdoc/rdoc-style.css +208 -0
  42. data/smart_month.gemspec +179 -0
  43. data/test/spec/date/accessor_spec.rb +91 -0
  44. data/test/spec/date/add_month_spec.rb +24 -0
  45. data/test/spec/date/add_spec.rb +23 -0
  46. data/test/spec/date/boat_spec.rb +20 -0
  47. data/test/spec/date/civil_spec.rb +28 -0
  48. data/test/spec/date/commercial_spec.rb +29 -0
  49. data/test/spec/date/constants_spec.rb +41 -0
  50. data/test/spec/date/conversions_spec.rb +153 -0
  51. data/test/spec/date/downto_spec.rb +18 -0
  52. data/test/spec/date/eql_spec.rb +10 -0
  53. data/test/spec/date/gregorian_spec.rb +28 -0
  54. data/test/spec/date/hash_spec.rb +14 -0
  55. data/test/spec/date/infinity_spec.rb +77 -0
  56. data/test/spec/date/julian_spec.rb +52 -0
  57. data/test/spec/date/minus_month_spec.rb +23 -0
  58. data/test/spec/date/minus_spec.rb +30 -0
  59. data/test/spec/date/new_spec.rb +9 -0
  60. data/test/spec/date/neww_spec.rb +9 -0
  61. data/test/spec/date/ordinal_spec.rb +29 -0
  62. data/test/spec/date/parse_spec.rb +149 -0
  63. data/test/spec/date/relationship_spec.rb +20 -0
  64. data/test/spec/date/shared/civil.rb +66 -0
  65. data/test/spec/date/shared/commercial.rb +39 -0
  66. data/test/spec/date/shared/parse.rb +54 -0
  67. data/test/spec/date/shared/parse_eu.rb +30 -0
  68. data/test/spec/date/shared/parse_us.rb +29 -0
  69. data/test/spec/date/step_spec.rb +56 -0
  70. data/test/spec/date/strftime_spec.rb +205 -0
  71. data/test/spec/date/strptime_spec.rb +143 -0
  72. data/test/spec/date/upto_spec.rb +18 -0
  73. data/test/spec/parsedate/parsedate.rb +95 -0
  74. data/test/spec/time/httpdate_spec.rb +21 -0
  75. data/test/spec/time/iso8601_spec.rb +7 -0
  76. data/test/spec/time/rfc2822_spec.rb +7 -0
  77. data/test/spec/time/rfc822_spec.rb +7 -0
  78. data/test/spec/time/shared/rfc2822.rb +65 -0
  79. data/test/spec/time/shared/xmlschema.rb +53 -0
  80. data/test/spec/time/xmlschema_spec.rb +7 -0
  81. data/test/spec_helper.rb +56 -0
  82. data/test/test_helper.rb +4 -0
  83. data/test/unit/calculations_test.rb +82 -0
  84. data/test/unit/collection_test.rb +42 -0
  85. data/test/unit/magic_test.rb +37 -0
  86. data/test/unit/math_test.rb +30 -0
  87. data/test/unit/rulesets_test.rb +94 -0
  88. data/test/unit/samples/test_ruleset.yml +6 -0
  89. data/test/unit/util_test.rb +29 -0
  90. metadata +196 -0
@@ -0,0 +1,143 @@
1
+ require 'date'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ describe "Date#strftime" do
5
+
6
+ it "should be able to parse without arguments" do
7
+ Date.strptime.should == Date.civil(-4712, 1, 1)
8
+ end
9
+
10
+ it "should be able to parse the default date format" do
11
+ Date.strptime("2000-04-06").should == Date.civil(2000, 4, 6)
12
+ Date.civil(2000, 4, 6).strftime.should == Date.civil(2000, 4, 6).to_s
13
+ end
14
+
15
+ it "should be able to parse the full day name" do
16
+ d = Date.today
17
+ # strptime assumed week that start on sunday, not monday
18
+ week = d.cweek
19
+ week += 1 if d.cwday == 7
20
+ Date.strptime("Thursday", "%A").should == Date.commercial(d.cwyear, week, 4)
21
+ end
22
+
23
+ it "should be able to parse the short day name" do
24
+ d = Date.today
25
+ # strptime assumed week that start on sunday, not monday
26
+ week = d.cweek
27
+ week += 1 if d.cwday == 7
28
+ Date.strptime("Thu", "%a").should == Date.commercial(d.cwyear, week, 4)
29
+ end
30
+
31
+ it "should be able to parse the full month name" do
32
+ d = Date.today
33
+ Date.strptime("April", "%B").should == Date.civil(d.year, 4, 1)
34
+ end
35
+
36
+ it "should be able to parse the short month name" do
37
+ d = Date.today
38
+ Date.strptime("Apr", "%b").should == Date.civil(d.year, 4, 1)
39
+ Date.strptime("Apr", "%h").should == Date.civil(d.year, 4, 1)
40
+ end
41
+
42
+ it "should be able to parse the century" do
43
+ Date.strptime("06 20", "%y %C").should == Date.civil(2006, 1, 1)
44
+ end
45
+
46
+ it "should be able to parse the month day with leading zeroes" do
47
+ d = Date.today
48
+ Date.strptime("06", "%d").should == Date.civil(d.year, d.month, 6)
49
+ end
50
+
51
+ it "should be able to parse the month day with leading spaces" do
52
+ d = Date.today
53
+ Date.strptime(" 6", "%e").should == Date.civil(d.year, d.month, 6)
54
+ end
55
+
56
+ it "should be able to parse the commercial year with leading zeroes" do
57
+ Date.strptime("2000", "%G").should == Date.civil(2000, 1, 3)
58
+ Date.strptime("2002", "%G").should == Date.civil(2001, 12, 31)
59
+ end
60
+
61
+ it "should be able to parse the commercial year with only two digits" do
62
+ Date.strptime("68", "%g").should == Date.civil(2068, 1, 2)
63
+ Date.strptime("69", "%g").should == Date.civil(1968, 12, 30)
64
+ end
65
+
66
+ it "should be able to parse the year day with leading zeroes" do
67
+ d = Date.today
68
+ if Date.gregorian_leap?(Date.today.year)
69
+ Date.strptime("097", "%j").should == Date.civil(d.year, 4, 6)
70
+ else
71
+ Date.strptime("097", "%j").should == Date.civil(d.year, 4, 7)
72
+ end
73
+ end
74
+
75
+ it "should be able to parse the month with leading zeroes" do
76
+ d = Date.today
77
+ Date.strptime("04", "%m").should == Date.civil(d.year, 4, 1)
78
+ end
79
+
80
+ it "should be able to show the week number with the week starting on sunday and monday" do
81
+ d = Date.today
82
+ Date.strptime("14", "%U").should == Date.commercial(d.cwyear, 14, 7)
83
+ Date.strptime("14", "%W").should == Date.commercial(d.cwyear, 15, 7)
84
+ end
85
+
86
+ it "should be able to show the commercial week day" do
87
+ Date.strptime("2008 1", "%G %u").should == Date.civil(2007, 12, 31)
88
+ end
89
+
90
+ it "should be able to show the commercial week" do
91
+ d = Date.commercial(Date.today.year,1,1)
92
+ Date.strptime("1", "%V").should == d
93
+ Date.strptime("15", "%V").should == Date.commercial(d.cwyear, 15, 1)
94
+ end
95
+
96
+ it "should be able to show the week day" do
97
+ d = Date.today
98
+ Date.strptime("2007 4", "%Y %w").should == Date.civil(2007, 1, 4)
99
+ end
100
+
101
+ it "should be able to show the year in YYYY format" do
102
+ Date.strptime("2007", "%Y").should == Date.civil(2007, 1, 1)
103
+ end
104
+
105
+ it "should be able to show the year in YY format" do
106
+ Date.strptime("00", "%y").should == Date.civil(2000, 1, 1)
107
+ end
108
+
109
+ ############################
110
+ # Specs that combine stuff #
111
+ ############################
112
+
113
+ it "should be able to parse the date in full" do
114
+ Date.strptime("Thu Apr 6 00:00:00 2000", "%c").should == Date.civil(2000, 4, 6)
115
+ Date.strptime("Thu Apr 6 00:00:00 2000", "%a %b %e %H:%M:%S %Y").should == Date.civil(2000, 4, 6)
116
+ end
117
+
118
+ it "should be able to parse the date with slashes" do
119
+ Date.strptime("04/06/00", "%D").should == Date.civil(2000, 4, 6)
120
+ Date.strptime("04/06/00", "%m/%d/%y").should == Date.civil(2000, 4, 6)
121
+ end
122
+
123
+ it "should be able to parse the date as YYYY-MM-DD" do
124
+ Date.strptime("2000-04-06", "%F").should == Date.civil(2000, 4, 6)
125
+ Date.strptime("2000-04-06", "%Y-%m-%d").should == Date.civil(2000, 4, 6)
126
+ end
127
+
128
+ it "should be able to show the commercial week" do
129
+ Date.strptime(" 9-Apr-2000", "%v").should == Date.civil(2000, 4, 9)
130
+ Date.strptime(" 9-Apr-2000", "%e-%b-%Y").should == Date.civil(2000, 4, 9)
131
+ end
132
+
133
+ it "should be able to show MM/DD/YY" do
134
+ Date.strptime("04/06/00", "%x").should == Date.civil(2000, 4, 6)
135
+ Date.strptime("04/06/00", "%m/%d/%y").should == Date.civil(2000, 4, 6)
136
+ end
137
+
138
+ it "should be able to show a full notation" do
139
+ Date.strptime("Sun Apr 9 00:00:00 +00:00 2000", "%+").should == Date.civil(2000, 4, 9)
140
+ Date.strptime("Sun Apr 9 00:00:00 +00:00 2000", "%a %b %e %H:%M:%S %Z %Y").should == Date.civil(2000, 4, 9)
141
+ end
142
+
143
+ end
@@ -0,0 +1,18 @@
1
+ require 'date'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
+
4
+ describe "Date#upto" do
5
+
6
+ it "should be able to step forward in time" do
7
+ ds = Date.civil(2008, 10, 11)
8
+ de = Date.civil(2008, 9, 29)
9
+ count = 0
10
+ de.upto(ds) do |d|
11
+ d.should <= ds
12
+ d.should >= de
13
+ count += 1
14
+ end
15
+ count.should == 13
16
+ end
17
+
18
+ end
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + "/../../spec_helper"
2
+ require "parsedate"
3
+
4
+ describe "ParseDate.parsedate" do
5
+ it "returns Array of 8 nils given an empty String" do
6
+ ParseDate.parsedate("").should == [nil] * 8
7
+ end
8
+
9
+ it "raises TypeError given nil" do
10
+ lambda { ParseDate.parsedate(nil) }.should raise_error(TypeError)
11
+ end
12
+
13
+ it "raises NoMethodError given Time" do
14
+ lambda { ParseDate.parsedate(Time.now) }.should raise_error(NoMethodError)
15
+ end
16
+
17
+ it "returns Array with weekday number, given a full day name" do
18
+ ParseDate.parsedate("Sunday").should == [nil] * 7 + [0]
19
+ end
20
+
21
+ it "returns Array with weekday number, given a 3 letter day name" do
22
+ ParseDate.parsedate("mon").should == [nil] * 7 + [1]
23
+ end
24
+
25
+ it "returns Array with weekday number, given a String containing a word starting with day" do
26
+ ParseDate.parsedate("ignore friday monday ignore").should == [nil] * 7 + [5]
27
+ ParseDate.parsedate("ignorefriday").should == [nil] * 8
28
+ ParseDate.parsedate("fridayignore").should == [nil] * 7 + [5]
29
+ # friday, not monday!
30
+ ParseDate.parsedate("friends on monday").should == [nil] * 7 + [5]
31
+ end
32
+
33
+ it "returns Array of 8 nils, given a single digit String" do
34
+ ParseDate.parsedate("8").should == [nil] * 8
35
+ end
36
+
37
+ it "returns Array with day set, given a String of 2 digits" do
38
+ ParseDate.parsedate("08").should == [nil, nil] + [8] + [nil] * 5
39
+ ParseDate.parsedate("99").should == [nil, nil] + [99] + [nil] * 5
40
+ end
41
+
42
+ it "returns Array of 8 nils, given a String of 3 digits" do
43
+ ParseDate.parsedate("100").should == [nil] * 8
44
+ end
45
+
46
+ it "returns Array with month and day set, given a String of 4 digits" do
47
+ ParseDate.parsedate("1050").should == [nil] + [10,50] + [nil] * 5
48
+ end
49
+
50
+ it "returns Array with year set, given a String of 5 digits" do
51
+ ParseDate.parsedate("10500").should == [10] + [nil] * 7
52
+ end
53
+
54
+ it "returns Array with date fields set, given a String of 6 digits" do
55
+ ParseDate.parsedate("105070").should == [10, 50, 70] + [nil] * 5
56
+ end
57
+
58
+ it "returns Array with 4-digit year set, given a String of 7 digits" do
59
+ ParseDate.parsedate("1050701").should == [1050] + [nil] * 7
60
+ end
61
+
62
+ it "returns Array with date fields set, given a String of 8 digits" do
63
+ ParseDate.parsedate("10507011").should == [1050, 70, 11] + [nil] * 5
64
+ end
65
+
66
+ it "returns Array of 8 nils, given a odd-sized String of 9 or more digits" do
67
+ ParseDate.parsedate("123456789").should == [nil] * 8
68
+ ParseDate.parsedate("12345678901").should == [nil] * 8
69
+ end
70
+
71
+ it "returns Array with date & hour fields set, given a String of 10 digits" do
72
+ ParseDate.parsedate("1234567890").should == [1234, 56, 78, 90] + [nil] * 4
73
+ end
74
+
75
+ it "returns Array with date, hour & minute fields set, given a String of 12 digits" do
76
+ ParseDate.parsedate("123456789012").should == [1234, 56, 78, 90, 12] + [nil] * 3
77
+ end
78
+
79
+ it "returns Array with date & time fields set, given a String of 14 digits" do
80
+ ParseDate.parsedate("12345678901234").should == [1234, 56, 78, 90, 12, 34, nil, nil]
81
+ end
82
+
83
+ it "returns Array with year and month set, given a String like nn-nn" do
84
+ ParseDate.parsedate("08-09").should == [8,9] + [nil] * 6
85
+ ParseDate.parsedate("08-09",true).should == [2008,9] + [nil] * 6
86
+ end
87
+
88
+ it "returns Array with day and hour set, given a String like n-nn" do
89
+ ParseDate.parsedate("8-09").should == [nil,nil] + [9,8] + [nil] * 4
90
+ end
91
+
92
+ it "returns Array with day and timezone set, given a String like nn-n" do
93
+ ParseDate.parsedate("08-9").should == [nil,nil,8,nil,nil,nil,"-9",nil]
94
+ end
95
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require 'time'
3
+
4
+ describe "Time.httpdate" do
5
+ it "parses RFC-2616 strings" do
6
+ t = Time.utc(1994, 11, 6, 8, 49, 37)
7
+ t.should == Time.httpdate("Sun, 06 Nov 1994 08:49:37 GMT")
8
+
9
+ # relies on Time.parse (not yet implemented)
10
+ # t.should == Time.httpdate("Sunday, 06-Nov-94 08:49:37 GMT")
11
+
12
+ t.should == Time.httpdate("Sun Nov 6 08:49:37 1994")
13
+ Time.utc(1995, 11, 15, 6, 25, 24).should == Time.httpdate("Wed, 15 Nov 1995 06:25:24 GMT")
14
+ Time.utc(1995, 11, 15, 4, 58, 8).should == Time.httpdate("Wed, 15 Nov 1995 04:58:08 GMT")
15
+ Time.utc(1994, 11, 15, 8, 12, 31).should == Time.httpdate("Tue, 15 Nov 1994 08:12:31 GMT")
16
+ Time.utc(1994, 12, 1, 16, 0, 0).should == Time.httpdate("Thu, 01 Dec 1994 16:00:00 GMT")
17
+ Time.utc(1994, 10, 29, 19, 43, 31).should == Time.httpdate("Sat, 29 Oct 1994 19:43:31 GMT")
18
+ Time.utc(1994, 11, 15, 12, 45, 26).should == Time.httpdate("Tue, 15 Nov 1994 12:45:26 GMT")
19
+ Time.utc(1999, 12, 31, 23, 59, 59).should == Time.httpdate("Fri, 31 Dec 1999 23:59:59 GMT")
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require File.dirname(__FILE__) + '/shared/xmlschema'
3
+ require 'time'
4
+
5
+ describe "Time.xmlschema" do
6
+ it_behaves_like :time_xmlschema, :iso8601
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require File.dirname(__FILE__) + '/shared/rfc2822'
3
+ require 'time'
4
+
5
+ describe "Time.rfc2822" do
6
+ it_behaves_like :time_rfc2822, :rfc2822
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require File.dirname(__FILE__) + '/shared/rfc2822'
3
+ require 'time'
4
+
5
+ describe "Time.rfc822" do
6
+ it_behaves_like :time_rfc2822, :rfc822
7
+ end
@@ -0,0 +1,65 @@
1
+ describe :time_rfc2822, :shared => true do
2
+ it "parses RFC-822 strings" do
3
+ t1 = (Time.utc(1976, 8, 26, 14, 30) + 4 * 3600)
4
+ t2 = Time.rfc2822("26 Aug 76 14:30 EDT")
5
+ t1.should == t2
6
+
7
+ t3 = Time.utc(1976, 8, 27, 9, 32) + 7 * 3600
8
+ t4 = Time.rfc2822("27 Aug 76 09:32 PDT")
9
+ t3.should == t4
10
+ end
11
+
12
+ it "parses RFC-2822 strings" do
13
+ t1 = Time.utc(1997, 11, 21, 9, 55, 6) + 6 * 3600
14
+ t2 = Time.rfc2822("Fri, 21 Nov 1997 09:55:06 -0600")
15
+ t1.should == t2
16
+
17
+ t3 = Time.utc(2003, 7, 1, 10, 52, 37) - 2 * 3600
18
+ t4 = Time.rfc2822("Tue, 1 Jul 2003 10:52:37 +0200")
19
+ t3.should == t4
20
+
21
+ t5 = Time.utc(1997, 11, 21, 10, 1, 10) + 6 * 3600
22
+ t6 = Time.rfc2822("Fri, 21 Nov 1997 10:01:10 -0600")
23
+ t5.should == t6
24
+
25
+ t7 = Time.utc(1997, 11, 21, 11, 0, 0) + 6 * 3600
26
+ t8 = Time.rfc2822("Fri, 21 Nov 1997 11:00:00 -0600")
27
+ t7.should == t8
28
+
29
+ t9 = Time.utc(1997, 11, 24, 14, 22, 1) + 8 * 3600
30
+ t10 = Time.rfc2822("Mon, 24 Nov 1997 14:22:01 -0800")
31
+ t9.should == t10
32
+
33
+ begin
34
+ Time.at(-1)
35
+ rescue ArgumentError
36
+ # ignore
37
+ else
38
+ t11 = Time.utc(1969, 2, 13, 23, 32, 54) + 3 * 3600 + 30 * 60
39
+ t12 = Time.rfc2822("Thu, 13 Feb 1969 23:32:54 -0330")
40
+ t11.should == t12
41
+
42
+ t13 = Time.utc(1969, 2, 13, 23, 32, 0) + 3 * 3600 + 30 * 60
43
+ t14 = Time.rfc2822(" Thu,
44
+ 13
45
+ Feb
46
+ 1969
47
+ 23:32
48
+ -0330 (Newfoundland Time)")
49
+ t13.should == t14
50
+ end
51
+
52
+ t15 = Time.utc(1997, 11, 21, 9, 55, 6)
53
+ t16 = Time.rfc2822("21 Nov 97 09:55:06 GMT")
54
+ t15.should == t16
55
+
56
+ t17 = Time.utc(1997, 11, 21, 9, 55, 6) + 6 * 3600
57
+ t18 = Time.rfc2822("Fri, 21 Nov 1997 09 : 55 : 06 -0600")
58
+ t17.should == t18
59
+
60
+ lambda {
61
+ # inner comment is not supported.
62
+ Time.rfc2822("Fri, 21 Nov 1997 09(comment): 55 : 06 -0600")
63
+ }.should raise_error(ArgumentError)
64
+ end
65
+ end
@@ -0,0 +1,53 @@
1
+ describe :time_xmlschema, :shared => true do
2
+ it "parses ISO-8601 strings" do
3
+ t = Time.utc(1985, 4, 12, 23, 20, 50, 520000)
4
+ s = "1985-04-12T23:20:50.52Z"
5
+ t.should == Time.xmlschema(s)
6
+ #s.should == t.xmlschema(2)
7
+
8
+ t = Time.utc(1996, 12, 20, 0, 39, 57)
9
+ s = "1996-12-19T16:39:57-08:00"
10
+ t.should == Time.xmlschema(s)
11
+ # There is no way to generate time string with arbitrary timezone.
12
+ s = "1996-12-20T00:39:57Z"
13
+ t.should == Time.xmlschema(s)
14
+ #assert_equal(s, t.xmlschema)
15
+
16
+ t = Time.utc(1990, 12, 31, 23, 59, 60)
17
+ s = "1990-12-31T23:59:60Z"
18
+ t.should == Time.xmlschema(s)
19
+ # leap second is representable only if timezone file has it.
20
+ s = "1990-12-31T15:59:60-08:00"
21
+ t.should == Time.xmlschema(s)
22
+
23
+ begin
24
+ Time.at(-1)
25
+ rescue ArgumentError
26
+ # ignore
27
+ else
28
+ t = Time.utc(1937, 1, 1, 11, 40, 27, 870000)
29
+ s = "1937-01-01T12:00:27.87+00:20"
30
+ t.should == Time.xmlschema(s)
31
+ end
32
+
33
+ # more
34
+
35
+ # (Time.utc(1999, 5, 31, 13, 20, 0) + 5 * 3600).should == Time.xmlschema("1999-05-31T13:20:00-05:00")
36
+ # (Time.local(2000, 1, 20, 12, 0, 0)).should == Time.xmlschema("2000-01-20T12:00:00")
37
+ # (Time.utc(2000, 1, 20, 12, 0, 0)).should == Time.xmlschema("2000-01-20T12:00:00Z")
38
+ # (Time.utc(2000, 1, 20, 12, 0, 0) - 12 * 3600).should == Time.xmlschema("2000-01-20T12:00:00+12:00")
39
+ # (Time.utc(2000, 1, 20, 12, 0, 0) + 13 * 3600).should == Time.xmlschema("2000-01-20T12:00:00-13:00")
40
+ # (Time.utc(2000, 3, 4, 23, 0, 0) - 3 * 3600).should == Time.xmlschema("2000-03-04T23:00:00+03:00")
41
+ # (Time.utc(2000, 3, 4, 20, 0, 0)).should == Time.xmlschema("2000-03-04T20:00:00Z")
42
+ # (Time.local(2000, 1, 15, 0, 0, 0)).should == Time.xmlschema("2000-01-15T00:00:00")
43
+ # (Time.local(2000, 2, 15, 0, 0, 0)).should == Time.xmlschema("2000-02-15T00:00:00")
44
+ # (Time.local(2000, 1, 15, 12, 0, 0)).should == Time.xmlschema("2000-01-15T12:00:00")
45
+ # (Time.utc(2000, 1, 16, 12, 0, 0)).should == Time.xmlschema("2000-01-16T12:00:00Z")
46
+ # (Time.local(2000, 1, 1, 12, 0, 0)).should == Time.xmlschema("2000-01-01T12:00:00")
47
+ # (Time.utc(1999, 12, 31, 23, 0, 0)).should == Time.xmlschema("1999-12-31T23:00:00Z")
48
+ # (Time.local(2000, 1, 16, 12, 0, 0)).should == Time.xmlschema("2000-01-16T12:00:00")
49
+ # (Time.local(2000, 1, 16, 0, 0, 0)).should == Time.xmlschema("2000-01-16T00:00:00")
50
+ # (Time.utc(2000, 1, 12, 12, 13, 14)).should == Time.xmlschema("2000-01-12T12:13:14Z")
51
+ # (Time.utc(2001, 4, 17, 19, 23, 17, 300000)).should == Time.xmlschema("2001-04-17T19:23:17.3Z")
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require File.dirname(__FILE__) + '/shared/xmlschema'
3
+ require 'time'
4
+
5
+ describe "Time.xmlschema" do
6
+ it_behaves_like :time_xmlschema, :xmlschema
7
+ end
@@ -0,0 +1,56 @@
1
+ # quickly load smart month into the test spec
2
+ $LOAD_PATH << File.dirname(__FILE__) + '/../'
3
+ require 'lib/smart_month'
4
+
5
+ unless ENV['MSPEC_RUNNER']
6
+ begin
7
+ require "pp"
8
+ require 'mspec/version'
9
+ require 'mspec/helpers'
10
+ require 'mspec/guards'
11
+ require 'mspec/runner/shared'
12
+ require 'mspec/matchers/be_ancestor_of'
13
+ require 'mspec/matchers/output'
14
+ require 'mspec/matchers/output_to_fd'
15
+ require 'mspec/matchers/complain'
16
+ require 'mspec/matchers/equal_element'
17
+ require 'mspec/matchers/equal_utf16'
18
+ require 'mspec/matchers/match_yaml'
19
+
20
+
21
+
22
+ # Code to setup HOME directory correctly on Windows
23
+ # This duplicates Ruby 1.9 semantics for defining HOME
24
+ platform_is :windows do
25
+ if ENV['HOME']
26
+ ENV['HOME'] = ENV['HOME'].tr '\\', '/'
27
+ elsif ENV['HOMEDIR'] && ENV['HOMEDRIVE']
28
+ ENV['HOME'] = File.join(ENV['HOMEDRIVE'], ENV['HOMEDIR'])
29
+ elsif ENV['HOMEDIR']
30
+ ENV['HOME'] = ENV['HOMEDIR']
31
+ elsif ENV['HOMEDRIVE']
32
+ ENV['HOME'] = ENV['HOMEDRIVE']
33
+ elsif ENV['USERPROFILE']
34
+ ENV['HOME'] = ENV['USERPROFILE']
35
+ else
36
+ puts "No suitable HOME environment found. This means that all of"
37
+ puts "HOME, HOMEDIR, HOMEDRIVE, and USERPROFILE are not set"
38
+ exit 1
39
+ end
40
+ end
41
+
42
+ TOLERANCE = 0.00003 unless Object.const_defined?(:TOLERANCE)
43
+ rescue LoadError
44
+ puts "Please install the MSpec gem to run the specs."
45
+ exit 1
46
+ end
47
+ end
48
+
49
+ minimum_version = "1.5.9"
50
+ unless MSpec::VERSION >= minimum_version
51
+ puts "Please install MSpec version >= #{minimum_version} to run the specs"
52
+ exit 1
53
+ end
54
+
55
+ $VERBOSE = nil unless ENV['OUTPUT_WARNINGS']
56
+