rubysl-date 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15a5c9e1a6382cebf9dcb0066e38531ed7dda2cc
4
- data.tar.gz: 01a181b9bf7f42df885b2b5204f07aa1ae8e1826
3
+ metadata.gz: 832efc53ef6dea723300d939c8ffb0dca2f55f64
4
+ data.tar.gz: 9e85d7f14d6f97fe9fc2383c0a31105cfebe87d0
5
5
  SHA512:
6
- metadata.gz: 4e60fe68246f81777d2c291181322736ee670ae332b9723ffd5fd4e7eaea0816b236f291f075eec55725936f0241193e7ae755fb878c99a13599853ebb010a5b
7
- data.tar.gz: 110f4dd874b0b96c40ff7922c571022d8f718e87ed936a2e1dced438347a9c9dd7601f092159c41e425a212a25af7f39ecfe93fb042029341d9dffef90d0a341
6
+ metadata.gz: a72b16d0995b4495d9211eff24d0f9321cf8d1ef59c543cde27f4aa585230dff45b196c08cf3f28bf6043e2ed66736449033c53165e07106f888fd0985f3a57e
7
+ data.tar.gz: a97d5dd4080d17cc8ad93b62b01f1a681c634cbaae2f89d196fc691718cda6e11c2dcf71e8f77870a9a6630e026b42ff177d0561f31ed0ecc9b1165f6edaabf6
@@ -3,5 +3,7 @@ env:
3
3
  - RUBYLIB=lib:.
4
4
  script: mspec spec
5
5
  rvm:
6
- - 2.1.0
6
+ - ruby-head
7
+ - 2.2.0
8
+ - 2.1.5
7
9
  - rbx-2
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
@@ -232,8 +232,8 @@ class Date
232
232
  s.scan(/./) do |k|
233
233
  case k
234
234
  when '-'; f[:p] = '-'
235
- when '_'; f[:p] = "\s"
236
- when '0'; f[:p] = '0'
235
+ when '_'; f[:p] = "\s" unless f[:p] == '-'
236
+ when '0'; f[:p] = '0' unless f[:p] == '-'
237
237
  when '^'; f[:u] = true
238
238
  when '#'; f[:x] = true
239
239
  end
@@ -559,8 +559,8 @@ class Date
559
559
  e._cent ||= if val >= 69 then 19 else 20 end
560
560
  when 'Z', /\A:{0,3}z/
561
561
  return unless str.sub!(/\A((?:gmt|utc?)?[-+]\d+(?:[,.:]\d+(?::\d+)?)?
562
- |(?-i:[[:alpha:].\\s]+)(?:standard|daylight)\\stime\\b
563
- |(?-i:[[:alpha:]]+)(?:\\sdst)?\\b
562
+ |(?-i:[[:alpha:].\s]+)(?:standard|daylight)\stime\b
563
+ |(?-i:[[:alpha:]]+)(?:\sdst)?\b
564
564
  )/ix, '')
565
565
  val = $1
566
566
  e.zone = val
@@ -1496,11 +1496,13 @@ class Date
1496
1496
  def to_s() format('%.4d-%02d-%02d', year, mon, mday) end # 4p
1497
1497
 
1498
1498
  # Dump to Marshal format.
1499
- def marshal_dump() [@ajd, @of, @sg] end
1499
+ def marshal_dump()
1500
+ [0, @ajd, 0, 0, @of, @sg]
1501
+ end
1500
1502
 
1501
1503
  # Load from Marshal format.
1502
1504
  def marshal_load(a)
1503
- @ajd, @of, @sg, = a
1505
+ _, @ajd, _, _, @of, @sg, = a
1504
1506
  @__ca__ = {}
1505
1507
  end
1506
1508
 
@@ -1,5 +1,5 @@
1
1
  module RubySL
2
2
  module Date
3
- VERSION = "2.0.8"
3
+ VERSION = "2.0.9"
4
4
  end
5
5
  end
@@ -0,0 +1,18 @@
1
+ require 'date'
2
+
3
+ describe "Date#marshal_dump" do
4
+ with_timezone("PST", +1) do
5
+ before do
6
+ @date = Date.new(2011, 7, 9)
7
+ @dumped = @date.marshal_dump
8
+ end
9
+
10
+ it "dumps self" do
11
+ @dumped.should == [0, (4911503/2r), 0, 0, 0, 2299161]
12
+ end
13
+
14
+ it "dumps @ajd within some bounds" do
15
+ @dumped[1].should be_close(@date.ajd, 1)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require 'date'
2
+
3
+ describe "Date#marshal_load" do
4
+ with_timezone("PST", +1) do
5
+ before do
6
+ @date = Date.new(2011, 7, 9)
7
+ @dumped = [0, (4911503/2r), 0, 0, 0, 2299161]
8
+ @loaded = Date.new
9
+ @loaded.marshal_load(@dumped)
10
+ end
11
+
12
+ it "returns the loaded date" do
13
+ @date.should == @loaded
14
+ end
15
+
16
+ it "loads @ajd within some bounds" do
17
+ @loaded.ajd.should be_close(@dumped[1], 1)
18
+ end
19
+ end
20
+ end
@@ -1,204 +1,40 @@
1
1
  require 'date'
2
+ require File.expand_path('../../shared/strftime_for_date', __FILE__)
2
3
 
3
4
  describe "Date#strftime" do
5
+ before :all do
6
+ @new_date = lambda { |y,m,d| Date.civil(y,m,d) }
4
7
 
5
- it "should be able to print the date" do
6
- Date.civil(2000, 4, 6).strftime.should == "2000-04-06"
7
- Date.civil(2000, 4, 6).strftime.should == Date.civil(2000, 4, 6).to_s
8
+ @date = Date.civil(2000, 4, 9)
8
9
  end
9
10
 
10
- it "should be able to print the full day name" do
11
- Date.civil(2000, 4, 6).strftime("%A").should == "Thursday"
12
- end
13
-
14
- it "should be able to print the short day name" do
15
- Date.civil(2000, 4, 6).strftime("%a").should == "Thu"
16
- end
17
-
18
- it "should be able to print the full month name" do
19
- Date.civil(2000, 4, 6).strftime("%B").should == "April"
20
- end
21
-
22
- it "should be able to print the short month name" do
23
- Date.civil(2000, 4, 6).strftime("%b").should == "Apr"
24
- Date.civil(2000, 4, 6).strftime("%h").should == "Apr"
25
- Date.civil(2000, 4, 6).strftime("%b").should == Date.civil(2000, 4, 6).strftime("%h")
26
- end
27
-
28
- it "should be able to print the century" do
29
- Date.civil(2000, 4, 6).strftime("%C").should == "20"
30
- end
31
-
32
- it "should be able to print the month day with leading zeroes" do
33
- Date.civil(2000, 4, 6).strftime("%d").should == "06"
34
- end
35
-
36
- it "should be able to print the month day with leading spaces" do
37
- Date.civil(2000, 4, 6).strftime("%e").should == " 6"
38
- end
39
-
40
- it "should be able to print the commercial year with leading zeroes" do
41
- Date.civil(2000, 4, 6).strftime("%G").should == "2000"
42
- Date.civil( 200, 4, 6).strftime("%G").should == "0200"
43
- end
44
-
45
- it "should be able to print the commercial year with only two digits" do
46
- Date.civil(2000, 4, 6).strftime("%g").should == "00"
47
- Date.civil( 200, 4, 6).strftime("%g").should == "00"
48
- end
49
-
50
- it "should be able to print the hour with leading zeroes (hour is always 00)" do
51
- Date.civil(2000, 4, 6).strftime("%H").should == "00"
52
- end
53
-
54
- it "should be able to print the hour in 12 hour notation with leading zeroes" do
55
- Date.civil(2000, 4, 6).strftime("%I").should == "12"
56
- end
57
-
58
- it "should be able to print the year day with leading zeroes" do
59
- Date.civil(2000, 4, 6).strftime("%j").should == "097"
60
- end
61
-
62
- it "should be able to print the hour in 24 hour notation with leading spaces" do
63
- Date.civil(2000, 4, 6).strftime("%k").should == " 0"
64
- end
65
-
66
- it "should be able to print the hour in 12 hour notation with leading spaces" do
67
- Date.civil(2000, 4, 6).strftime("%l").should == "12"
68
- end
69
-
70
- it "should be able to print the minutes with leading zeroes" do
71
- Date.civil(2000, 4, 6).strftime("%M").should == "00"
72
- end
73
-
74
- it "should be able to print the month with leading zeroes" do
75
- Date.civil(2000, 4, 6).strftime("%m").should == "04"
76
- end
77
-
78
- it "should be able to add a newline" do
79
- Date.civil(2000, 4, 6).strftime("%n").should == "\n"
80
- end
81
-
82
- it "should be able to show AM/PM" do
83
- Date.civil(2000, 4, 6).strftime("%P").should == "am"
84
- end
85
-
86
- it "should be able to show am/pm" do
87
- Date.civil(2000, 4, 6).strftime("%p").should == "AM"
88
- end
89
-
90
- it "should be able to show the number of seconds with leading zeroes" do
91
- Date.civil(2000, 4, 6).strftime("%S").should == "00"
92
- end
93
-
94
- it "should be able to show the number of seconds with leading zeroes" do
95
- Date.civil(2000, 4, 6).strftime("%S").should == "00"
96
- end
97
-
98
- it "should be able to show the number of seconds since the unix epoch" do
99
- Date.civil(2000, 4, 6).strftime("%s").should == "954979200"
100
- end
101
-
102
- it "should be able to add a tab" do
103
- Date.civil(2000, 4, 6).strftime("%t").should == "\t"
104
- end
105
-
106
- it "should be able to show the week number with the week starting on sunday and monday" do
107
- Date.civil(2000, 4, 6).strftime("%U").should == "14"
108
- Date.civil(2000, 4, 6).strftime("%W").should == "14"
109
- Date.civil(2000, 4, 6).strftime("%U").should == Date.civil(2000, 4, 6).strftime("%W")
110
- Date.civil(2000, 4, 9).strftime("%U").should == "15"
111
- Date.civil(2000, 4, 9).strftime("%W").should == "14"
112
- Date.civil(2000, 4, 9).strftime("%U").should_not == Date.civil(2000, 4, 9).strftime("%W")
113
- end
114
-
115
- it "should be able to show the commercial week day" do
116
- Date.civil(2000, 4, 9).strftime("%u").should == "7"
117
- Date.civil(2000, 4, 10).strftime("%u").should == "1"
118
- end
119
-
120
- it "should be able to show the commercial week" do
121
- Date.civil(2000, 4, 9).strftime("%V").should == "14"
122
- Date.civil(2000, 4, 10).strftime("%V").should == "15"
123
- end
124
-
125
- it "should be able to show the week day" do
126
- Date.civil(2000, 4, 9).strftime("%w").should == "0"
127
- Date.civil(2000, 4, 10).strftime("%w").should == "1"
128
- end
129
-
130
- it "should be able to show the year in YYYY format" do
131
- Date.civil(2000, 4, 9).strftime("%Y").should == "2000"
132
- end
133
-
134
- it "should be able to show the year in YY format" do
135
- Date.civil(2000, 4, 9).strftime("%y").should == "00"
136
- end
137
-
138
- it "should be able to show the timezone of the date with a : separator" do
139
- Date.civil(2000, 4, 9).strftime("%Z").should == "+00:00"
140
- end
141
-
142
- it "should be able to show the timezone of the date with a : separator" do
143
- Date.civil(2000, 4, 9).strftime("%z").should == "+0000"
144
- end
145
-
146
- it "should be able to escape the % character" do
147
- Date.civil(2000, 4, 9).strftime("%%").should == "%"
148
- end
149
-
150
- ############################
151
- # Specs that combine stuff #
152
- ############################
153
-
154
- it "should be able to print the date in full" do
155
- Date.civil(2000, 4, 6).strftime("%c").should == "Thu Apr 6 00:00:00 2000"
156
- Date.civil(2000, 4, 6).strftime("%c").should == Date.civil(2000, 4, 6).strftime('%a %b %e %H:%M:%S %Y')
157
- end
11
+ it_behaves_like :strftime_date, :strftime
158
12
 
159
- it "should be able to print the date with slashes" do
160
- Date.civil(2000, 4, 6).strftime("%D").should == "04/06/00"
161
- Date.civil(2000, 4, 6).strftime("%D").should == Date.civil(2000, 4, 6).strftime('%m/%d/%y')
13
+ # Differences with Time
14
+ it "should be able to print the date with no argument" do
15
+ @date.strftime.should == "2000-04-09"
16
+ @date.strftime.should == @date.to_s
162
17
  end
163
18
 
164
- it "should be able to print the date as YYYY-MM-DD" do
165
- Date.civil(2000, 4, 6).strftime("%F").should == "2000-04-06"
166
- Date.civil(2000, 4, 6).strftime("%F").should == Date.civil(2000, 4, 6).strftime('%Y-%m-%d')
167
- end
168
-
169
- it "should be able to show HH:MM" do
170
- Date.civil(2000, 4, 6).strftime("%R").should == "00:00"
171
- Date.civil(2000, 4, 6).strftime("%R").should == Date.civil(2000, 4, 6).strftime('%H:%M')
172
- end
173
-
174
- it "should be able to show HH:MM:SS AM/PM" do
175
- Date.civil(2000, 4, 6).strftime("%r").should == "12:00:00 AM"
176
- Date.civil(2000, 4, 6).strftime("%r").should == Date.civil(2000, 4, 6).strftime('%I:%M:%S %p')
177
- end
178
-
179
- it "should be able to show HH:MM:SS" do
180
- Date.civil(2000, 4, 6).strftime("%T").should == "00:00:00"
181
- Date.civil(2000, 4, 6).strftime("%T").should == Date.civil(2000, 4, 6).strftime('%H:%M:%S')
19
+ # %Z is %:z for Date/DateTime
20
+ it "should be able to show the timezone with a : separator" do
21
+ @date.strftime("%Z").should == "+00:00"
182
22
  end
183
23
 
24
+ # %v is %e-%b-%Y for Date/DateTime
184
25
  it "should be able to show the commercial week" do
185
- Date.civil(2000, 4, 9).strftime("%v").should == " 9-Apr-2000"
186
- Date.civil(2000, 4, 9).strftime("%v").should == Date.civil(2000, 4, 9).strftime('%e-%b-%Y')
187
- end
188
-
189
- it "should be able to show HH:MM:SS" do
190
- Date.civil(2000, 4, 6).strftime("%X").should == "00:00:00"
191
- Date.civil(2000, 4, 6).strftime("%X").should == Date.civil(2000, 4, 6).strftime('%H:%M:%S')
26
+ @date.strftime("%v").should == " 9-Apr-2000"
27
+ @date.strftime("%v").should == @date.strftime('%e-%b-%Y')
192
28
  end
193
29
 
194
- it "should be able to show MM/DD/YY" do
195
- Date.civil(2000, 4, 6).strftime("%x").should == "04/06/00"
196
- Date.civil(2000, 4, 6).strftime("%x").should == Date.civil(2000, 4, 6).strftime('%m/%d/%y')
30
+ # additional conversion specifiers only in Date/DateTime
31
+ it 'shows the number of milliseconds since epoch' do
32
+ DateTime.new(1970, 1, 1).strftime('%Q').should == "0"
33
+ @date.strftime("%Q").should == "955238400000"
197
34
  end
198
35
 
199
36
  it "should be able to show a full notation" do
200
- Date.civil(2000, 4, 9).strftime("%+").should == "Sun Apr 9 00:00:00 +00:00 2000"
201
- Date.civil(2000, 4, 9).strftime("%+").should == Date.civil(2000, 4, 9).strftime('%a %b %e %H:%M:%S %Z %Y')
37
+ @date.strftime("%+").should == "Sun Apr 9 00:00:00 +00:00 2000"
38
+ @date.strftime("%+").should == @date.strftime('%a %b %e %H:%M:%S %Z %Y')
202
39
  end
203
-
204
40
  end
@@ -144,6 +144,10 @@ describe "Date#strptime" do
144
144
  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)
145
145
  end
146
146
 
147
+ it "parses a date with a Time Zone" do
148
+ d = Date.strptime('31 Dec 2014 11:12:13 UTC', '%d %b %Y %T %Z')
149
+ d.should be_an_instance_of(Date)
150
+ end
147
151
  end
148
152
 
149
153
  describe "Date.strptime" do
@@ -1,25 +1,51 @@
1
1
  require 'date'
2
+ require File.expand_path('../../shared/strftime_for_date', __FILE__)
3
+ require File.expand_path('../../shared/strftime_for_time', __FILE__)
2
4
 
3
- ruby_version_is "1.9.1" do
4
- describe "DateTime#strftime" do
5
- it "shows the number of fractional seconds with leading zeroes" do
6
- DateTime.civil(2000, 4, 6).strftime("%N").should == "000000000"
7
- end
5
+ describe "DateTime#strftime" do
6
+ before :all do
7
+ @new_date = lambda { |y,m,d| DateTime.civil(y,m,d) }
8
+ @new_time = lambda { |*args| DateTime.civil(*args) }
9
+ @new_time_in_zone = lambda { |zone,offset,*args|
10
+ y, m, d, h, min, s = args
11
+ DateTime.new(y, m||1, d||1, h||0, min||0, s||0, Rational(offset, 24))
12
+ }
13
+ @new_time_with_offset = lambda { |y,m,d,h,min,s,offset|
14
+ DateTime.new(y,m,d,h,min,s, Rational(offset, 86_400))
15
+ }
8
16
 
9
- it "shows the number of fractional seconds with leading zeroes to two decimal places" do
10
- DateTime.civil(2000, 4, 6).strftime("%2N").should == "00"
11
- end
17
+ @time = DateTime.civil(2001, 2, 3, 4, 5, 6)
18
+ end
19
+
20
+ it_behaves_like :strftime_date, :strftime
21
+ it_behaves_like :strftime_time, :strftime
22
+
23
+ # Differences with Time
24
+ it "should be able to print the datetime with no argument" do
25
+ @time.strftime.should == "2001-02-03T04:05:06+00:00"
26
+ @time.strftime.should == @time.to_s
27
+ end
12
28
 
13
- it "shows the number of fractional milliseconds with leading zeroes" do
14
- DateTime.civil(2000, 4, 6).strftime("%3N").should == "000"
15
- end
29
+ # %Z is %:z for Date/DateTime
30
+ it "should be able to show the timezone with a : separator" do
31
+ @time.strftime("%Z").should == "+00:00"
32
+ end
33
+
34
+ # %v is %e-%b-%Y for Date/DateTime
35
+ it "should be able to show the commercial week" do
36
+ @time.strftime("%v").should == " 3-Feb-2001"
37
+ @time.strftime("%v").should == @time.strftime('%e-%b-%Y')
38
+ end
16
39
 
17
- it "shows the number of fractional microseconds with leading zeroes" do
18
- DateTime.civil(2000, 4, 6).strftime("%6N").should == "000000"
19
- end
40
+ # additional conversion specifiers only in Date/DateTime
41
+ it 'shows the number of milliseconds since epoch' do
42
+ DateTime.new(1970, 1, 1, 0, 0, 0).strftime("%Q").should == "0"
43
+ @time.strftime("%Q").should == "981173106000"
44
+ DateTime.civil(2001, 2, 3, 4, 5, Rational(6123, 1000)).strftime("%Q").should == "981173106123"
45
+ end
20
46
 
21
- it "shows the number of fractional nanoseconds with leading zeroes" do
22
- DateTime.civil(2000, 4, 6).strftime("%9N").should == "000000000"
23
- end
47
+ it "should be able to show a full notation" do
48
+ @time.strftime("%+").should == "Sat Feb 3 04:05:06 +00:00 2001"
49
+ @time.strftime("%+").should == @time.strftime('%a %b %e %H:%M:%S %Z %Y')
24
50
  end
25
51
  end
@@ -0,0 +1,282 @@
1
+ # Shared for Time, Date and DateTime, testing only date components (smallest unit is day)
2
+ # The reference version of this file lives in rubyspec's shared/time directory.
3
+
4
+ describe :strftime_date, :shared => true do
5
+ before :all do
6
+ @d200_4_6 = @new_date[200, 4, 6]
7
+ @d2000_4_6 = @new_date[2000, 4, 6]
8
+ @d2000_4_9 = @new_date[2000, 4, 9]
9
+ @d2000_4_10 = @new_date[2000, 4, 10]
10
+ @d2009_9_18 = @new_date[2009, 9, 18]
11
+ end
12
+
13
+ # Per conversion specifier, not combining
14
+ it "should be able to print the full day name" do
15
+ @d2000_4_6.strftime("%A").should == "Thursday"
16
+ @d2009_9_18.strftime('%A').should == 'Friday'
17
+ end
18
+
19
+ it "should be able to print the short day name" do
20
+ @d2000_4_6.strftime("%a").should == "Thu"
21
+ @d2009_9_18.strftime('%a').should == 'Fri'
22
+ end
23
+
24
+ it "should be able to print the full month name" do
25
+ @d2000_4_6.strftime("%B").should == "April"
26
+ @d2009_9_18.strftime('%B').should == 'September'
27
+ end
28
+
29
+ it "should be able to print the short month name" do
30
+ @d2000_4_6.strftime("%b").should == "Apr"
31
+ @d2000_4_6.strftime("%h").should == "Apr"
32
+ @d2000_4_6.strftime("%b").should == @d2000_4_6.strftime("%h")
33
+ @d2009_9_18.strftime('%b').should == 'Sep'
34
+ end
35
+
36
+ it "should be able to print the century" do
37
+ @d2000_4_6.strftime("%C").should == "20"
38
+ end
39
+
40
+ it "should be able to print the month day with leading zeroes" do
41
+ @d2000_4_6.strftime("%d").should == "06"
42
+ @d2009_9_18.strftime('%d').should == '18'
43
+ end
44
+
45
+ it "should be able to print the month day with leading spaces" do
46
+ @d2000_4_6.strftime("%e").should == " 6"
47
+ end
48
+
49
+ it "should be able to print the commercial year with leading zeroes" do
50
+ @d2000_4_6.strftime("%G").should == "2000"
51
+ @d200_4_6.strftime("%G").should == "0200"
52
+ end
53
+
54
+ it "should be able to print the commercial year with only two digits" do
55
+ @d2000_4_6.strftime("%g").should == "00"
56
+ @d200_4_6.strftime("%g").should == "00"
57
+ end
58
+
59
+ it "should be able to print the hour with leading zeroes (hour is always 00)" do
60
+ @d2000_4_6.strftime("%H").should == "00"
61
+ end
62
+
63
+ it "should be able to print the hour in 12 hour notation with leading zeroes" do
64
+ @d2000_4_6.strftime("%I").should == "12"
65
+ end
66
+
67
+ it "should be able to print the julian day with leading zeroes" do
68
+ @d2000_4_6.strftime("%j").should == "097"
69
+ @d2009_9_18.strftime('%j').should == '261'
70
+ end
71
+
72
+ it "should be able to print the hour in 24 hour notation with leading spaces" do
73
+ @d2000_4_6.strftime("%k").should == " 0"
74
+ end
75
+
76
+ it "should be able to print the hour in 12 hour notation with leading spaces" do
77
+ @d2000_4_6.strftime("%l").should == "12"
78
+ end
79
+
80
+ it "should be able to print the minutes with leading zeroes" do
81
+ @d2000_4_6.strftime("%M").should == "00"
82
+ end
83
+
84
+ it "should be able to print the month with leading zeroes" do
85
+ @d2000_4_6.strftime("%m").should == "04"
86
+ @d2009_9_18.strftime('%m').should == '09'
87
+ end
88
+
89
+ it "should be able to add a newline" do
90
+ @d2000_4_6.strftime("%n").should == "\n"
91
+ end
92
+
93
+ it "should be able to show AM/PM" do
94
+ @d2000_4_6.strftime("%P").should == "am"
95
+ end
96
+
97
+ it "should be able to show am/pm" do
98
+ @d2000_4_6.strftime("%p").should == "AM"
99
+ end
100
+
101
+ it "should be able to show the number of seconds with leading zeroes" do
102
+ @d2000_4_6.strftime("%S").should == "00"
103
+ end
104
+
105
+ it "should be able to show the number of seconds with leading zeroes" do
106
+ @d2000_4_6.strftime("%S").should == "00"
107
+ end
108
+
109
+ ruby_version_is "1.9" do
110
+ it "should be able to show the number of seconds since the unix epoch" do
111
+ @d2000_4_6.strftime("%s").should == "954979200"
112
+ end
113
+ end
114
+
115
+ it "should be able to add a tab" do
116
+ @d2000_4_6.strftime("%t").should == "\t"
117
+ end
118
+
119
+ it "should be able to show the week number with the week starting on Sunday (%U) and Monday (%W)" do
120
+ @d2000_4_6.strftime("%U").should == "14" # Thursday
121
+ @d2000_4_6.strftime("%W").should == "14"
122
+
123
+ @d2000_4_9.strftime("%U").should == "15" # Sunday
124
+ @d2000_4_9.strftime("%W").should == "14"
125
+
126
+ @d2000_4_10.strftime("%U").should == "15" # Monday
127
+ @d2000_4_10.strftime("%W").should == "15"
128
+
129
+ # start of the year
130
+ saturday_first = @new_date[2000,1,1]
131
+ saturday_first.strftime("%U").should == "00"
132
+ saturday_first.strftime("%W").should == "00"
133
+
134
+ sunday_second = @new_date[2000,1,2]
135
+ sunday_second.strftime("%U").should == "01"
136
+ sunday_second.strftime("%W").should == "00"
137
+
138
+ monday_third = @new_date[2000,1,3]
139
+ monday_third.strftime("%U").should == "01"
140
+ monday_third.strftime("%W").should == "01"
141
+
142
+ sunday_9th = @new_date[2000,1,9]
143
+ sunday_9th.strftime("%U").should == "02"
144
+ sunday_9th.strftime("%W").should == "01"
145
+
146
+ monday_10th = @new_date[2000,1,10]
147
+ monday_10th.strftime("%U").should == "02"
148
+ monday_10th.strftime("%W").should == "02"
149
+
150
+ # middle of the year
151
+ some_sunday = @new_date[2000,8,6]
152
+ some_sunday.strftime("%U").should == "32"
153
+ some_sunday.strftime("%W").should == "31"
154
+ some_monday = @new_date[2000,8,7]
155
+ some_monday.strftime("%U").should == "32"
156
+ some_monday.strftime("%W").should == "32"
157
+
158
+ # end of year, and start of next one
159
+ saturday_30th = @new_date[2000,12,30]
160
+ saturday_30th.strftime("%U").should == "52"
161
+ saturday_30th.strftime("%W").should == "52"
162
+
163
+ sunday_last = @new_date[2000,12,31]
164
+ sunday_last.strftime("%U").should == "53"
165
+ sunday_last.strftime("%W").should == "52"
166
+
167
+ monday_first = @new_date[2001,1,1]
168
+ monday_first.strftime("%U").should == "00"
169
+ monday_first.strftime("%W").should == "01"
170
+ end
171
+
172
+ it "should be able to show the commercial week day" do
173
+ @d2000_4_9.strftime("%u").should == "7"
174
+ @d2000_4_10.strftime("%u").should == "1"
175
+ end
176
+
177
+ it "should be able to show the commercial week" do
178
+ @d2000_4_9.strftime("%V").should == "14"
179
+ @d2000_4_10.strftime("%V").should == "15"
180
+ end
181
+
182
+ # %W: see %U
183
+
184
+ it "should be able to show the week day" do
185
+ @d2000_4_9.strftime("%w").should == "0"
186
+ @d2000_4_10.strftime("%w").should == "1"
187
+ @d2009_9_18.strftime('%w').should == '5'
188
+ end
189
+
190
+ it "should be able to show the year in YYYY format" do
191
+ @d2000_4_9.strftime("%Y").should == "2000"
192
+ @d2009_9_18.strftime('%Y').should == '2009'
193
+ end
194
+
195
+ it "should be able to show the year in YY format" do
196
+ @d2000_4_9.strftime("%y").should == "00"
197
+ @d2009_9_18.strftime('%y').should == '09'
198
+ end
199
+
200
+ it "should be able to show the timezone of the date with a : separator" do
201
+ @d2000_4_9.strftime("%z").should == "+0000"
202
+ end
203
+
204
+ it "should be able to escape the % character" do
205
+ @d2000_4_9.strftime("%%").should == "%"
206
+ end
207
+
208
+ # Combining conversion specifiers
209
+ it "should be able to print the date in full" do
210
+ @d2000_4_6.strftime("%c").should == "Thu Apr 6 00:00:00 2000"
211
+ @d2000_4_6.strftime("%c").should == @d2000_4_6.strftime('%a %b %e %H:%M:%S %Y')
212
+ end
213
+
214
+ it "should be able to print the date with slashes" do
215
+ @d2000_4_6.strftime("%D").should == "04/06/00"
216
+ @d2000_4_6.strftime("%D").should == @d2000_4_6.strftime('%m/%d/%y')
217
+ end
218
+
219
+ it "should be able to print the date as YYYY-MM-DD" do
220
+ @d2000_4_6.strftime("%F").should == "2000-04-06"
221
+ @d2000_4_6.strftime("%F").should == @d2000_4_6.strftime('%Y-%m-%d')
222
+ end
223
+
224
+ it "should be able to show HH:MM" do
225
+ @d2000_4_6.strftime("%R").should == "00:00"
226
+ @d2000_4_6.strftime("%R").should == @d2000_4_6.strftime('%H:%M')
227
+ end
228
+
229
+ it "should be able to show HH:MM:SS AM/PM" do
230
+ @d2000_4_6.strftime("%r").should == "12:00:00 AM"
231
+ @d2000_4_6.strftime("%r").should == @d2000_4_6.strftime('%I:%M:%S %p')
232
+ end
233
+
234
+ it "should be able to show HH:MM:SS" do
235
+ @d2000_4_6.strftime("%T").should == "00:00:00"
236
+ @d2000_4_6.strftime("%T").should == @d2000_4_6.strftime('%H:%M:%S')
237
+ end
238
+
239
+ it "should be able to show HH:MM:SS" do
240
+ @d2000_4_6.strftime("%X").should == "00:00:00"
241
+ @d2000_4_6.strftime("%X").should == @d2000_4_6.strftime('%H:%M:%S')
242
+ end
243
+
244
+ it "should be able to show MM/DD/YY" do
245
+ @d2000_4_6.strftime("%x").should == "04/06/00"
246
+ @d2000_4_6.strftime("%x").should == @d2000_4_6.strftime('%m/%d/%y')
247
+ end
248
+
249
+ # GNU modificators
250
+ it "supports GNU modificators" do
251
+ time = @new_date[2001, 2, 3]
252
+
253
+ time.strftime('%^h').should == 'FEB'
254
+ time.strftime('%^_5h').should == ' FEB'
255
+ time.strftime('%0^5h').should == '00FEB'
256
+ time.strftime('%04m').should == '0002'
257
+ time.strftime('%0-^5h').should == 'FEB'
258
+ time.strftime('%_-^5h').should == 'FEB'
259
+ time.strftime('%^ha').should == 'FEBa'
260
+
261
+ time.strftime("%10h").should == ' Feb'
262
+ time.strftime("%^10h").should == ' FEB'
263
+ time.strftime("%_10h").should == ' Feb'
264
+ time.strftime("%_010h").should == '0000000Feb'
265
+ time.strftime("%0_10h").should == ' Feb'
266
+ time.strftime("%0_-10h").should == 'Feb'
267
+ time.strftime("%0-_10h").should == 'Feb'
268
+ end
269
+
270
+ it "supports the '-' modifier to drop leading zeros" do
271
+ @new_date[2001,3,22].strftime("%-m/%-d/%-y").should == "3/22/1"
272
+ end
273
+
274
+ with_feature :encoding do
275
+ it "passes the format string's encoding to the result string" do
276
+ result = @new_date[2010,3,8].strftime("%d. März %Y")
277
+
278
+ result.encoding.should == Encoding::UTF_8
279
+ result.should == "08. März 2010"
280
+ end
281
+ end
282
+ end
@@ -0,0 +1,174 @@
1
+ # Shared for Time and DateTime, testing only time components (hours, minutes, seconds and smaller)
2
+ # The reference version of this file lives in rubyspec's shared/time directory.
3
+
4
+ describe :strftime_time, :shared => true do
5
+ before :all do
6
+ @time = @new_time[2001, 2, 3, 4, 5, 6]
7
+ end
8
+
9
+ it "formats time according to the directives in the given format string" do
10
+ @new_time[1970, 1, 1].strftime("There is %M minutes in epoch").should == "There is 00 minutes in epoch"
11
+ end
12
+
13
+ # Per conversion specifier, not combining
14
+ it "returns the 24-based hour with %H" do
15
+ time = @new_time[2009, 9, 18, 18, 0, 0]
16
+ time.strftime('%H').should == '18'
17
+ end
18
+
19
+ it "returns the 12-based hour with %I" do
20
+ time = @new_time[2009, 9, 18, 18, 0, 0]
21
+ time.strftime('%I').should == '06'
22
+ end
23
+
24
+ it "supports 24-hr formatting with %l" do
25
+ time = @new_time[2004, 8, 26, 22, 38, 3]
26
+ time.strftime("%k").should == "22"
27
+ morning_time = @new_time[2004, 8, 26, 6, 38, 3]
28
+ morning_time.strftime("%k").should == " 6"
29
+ end
30
+
31
+ describe "with %L" do
32
+ it "formats the milliseconds of of the second" do
33
+ @new_time[2009, 1, 1, 0, 0, Rational(100, 1000)].strftime("%L").should == "100"
34
+ @new_time[2009, 1, 1, 0, 0, Rational(10, 1000)].strftime("%L").should == "010"
35
+ @new_time[2009, 1, 1, 0, 0, Rational(1, 1000)].strftime("%L").should == "001"
36
+ @new_time[2009, 1, 1, 0, 0, Rational(1, 10000)].strftime("%L").should == "000"
37
+ end
38
+ end
39
+
40
+ it "supports 12-hr formatting with %l" do
41
+ time = @new_time[2004, 8, 26, 22, 38, 3]
42
+ time.strftime('%l').should == '10'
43
+ morning_time = @new_time[2004, 8, 26, 6, 38, 3]
44
+ morning_time.strftime('%l').should == ' 6'
45
+ end
46
+
47
+ it "returns the minute with %M" do
48
+ time = @new_time[2009, 9, 18, 12, 6, 0]
49
+ time.strftime('%M').should == '06'
50
+ end
51
+
52
+ describe "with %N" do
53
+ it "formats the nanoseconds of the second with %N" do
54
+ @new_time[2000, 4, 6, 0, 0, Rational(1234560, 1_000_000_000)].strftime("%N").should == "001234560"
55
+ end
56
+
57
+ it "formats the milliseconds of the second with %3N" do
58
+ @new_time[2000, 4, 6, 0, 0, Rational(50, 1000)].strftime("%3N").should == "050"
59
+ end
60
+
61
+ it "formats the microseconds of the second with %6N" do
62
+ @new_time[2000, 4, 6, 0, 0, Rational(42, 1000)].strftime("%6N").should == "042000"
63
+ end
64
+
65
+ it "formats the nanoseconds of the second with %9N" do
66
+ @new_time[2000, 4, 6, 0, 0, Rational(1234, 1_000_000)].strftime("%9N").should == "001234000"
67
+ end
68
+
69
+ it "formats the picoseconds of the second with %12N" do
70
+ @new_time[2000, 4, 6, 0, 0, Rational(999999999999, 1000_000_000_000)].strftime("%12N").should == "999999999999"
71
+ end
72
+ end
73
+
74
+ it "supports am/pm formatting with %P" do
75
+ time = @new_time[2004, 8, 26, 22, 38, 3]
76
+ time.strftime('%P').should == 'pm'
77
+ time = @new_time[2004, 8, 26, 11, 38, 3]
78
+ time.strftime('%P').should == 'am'
79
+ end
80
+
81
+ it "supports AM/PM formatting with %p" do
82
+ time = @new_time[2004, 8, 26, 22, 38, 3]
83
+ time.strftime('%p').should == 'PM'
84
+ time = @new_time[2004, 8, 26, 11, 38, 3]
85
+ time.strftime('%p').should == 'AM'
86
+ end
87
+
88
+ it "returns the second with %S" do
89
+ time = @new_time[2009, 9, 18, 12, 0, 6]
90
+ time.strftime('%S').should == '06'
91
+ end
92
+
93
+ it "should be able to show the number of seconds since the unix epoch" do
94
+ @new_time_in_zone["GMT", 0, 2005].strftime("%s").should == "1104537600"
95
+ end
96
+
97
+ it "returns the timezone with %Z" do
98
+ time = @new_time[2009, 9, 18, 12, 0, 0]
99
+ zone = time.zone
100
+ time.strftime("%Z").should == zone
101
+ end
102
+
103
+ describe "with %z" do
104
+ it "formats a UTC time offset as '+0000'" do
105
+ @new_time_in_zone["GMT", 0, 2005].strftime("%z").should == "+0000"
106
+ end
107
+
108
+ it "formats a local time with positive UTC offset as '+HHMM'" do
109
+ @new_time_in_zone["CET", 1, 2005].strftime("%z").should == "+0100"
110
+ end
111
+
112
+ it "formats a local time with negative UTC offset as '-HHMM'" do
113
+ @new_time_in_zone["PST", -8, 2005].strftime("%z").should == "-0800"
114
+ end
115
+
116
+ it "formats a time with fixed positive offset as '+HHMM'" do
117
+ @new_time_with_offset[2012, 1, 1, 0, 0, 0, 3660].strftime("%z").should == "+0101"
118
+ end
119
+
120
+ it "formats a time with fixed negative offset as '-HHMM'" do
121
+ @new_time_with_offset[2012, 1, 1, 0, 0, 0, -3660].strftime("%z").should == "-0101"
122
+ end
123
+
124
+ it "formats a time with fixed offset as '+/-HH:MM' with ':' specifier" do
125
+ @new_time_with_offset[2012, 1, 1, 0, 0, 0, 3660].strftime("%:z").should == "+01:01"
126
+ end
127
+
128
+ it "formats a time with fixed offset as '+/-HH:MM:SS' with '::' specifier" do
129
+ @new_time_with_offset[2012, 1, 1, 0, 0, 0, 3665].strftime("%::z").should == "+01:01:05"
130
+ end
131
+ end
132
+
133
+ # Combining conversion specifiers
134
+ it "should be able to print the time in full" do
135
+ @time.strftime("%c").should == "Sat Feb 3 04:05:06 2001"
136
+ @time.strftime("%c").should == @time.strftime('%a %b %e %H:%M:%S %Y')
137
+ end
138
+
139
+ it "should be able to show HH:MM" do
140
+ @time.strftime("%R").should == "04:05"
141
+ @time.strftime("%R").should == @time.strftime('%H:%M')
142
+ end
143
+
144
+ it "should be able to show HH:MM:SS AM/PM" do
145
+ @time.strftime("%r").should == "04:05:06 AM"
146
+ @time.strftime("%r").should == @time.strftime('%I:%M:%S %p')
147
+ end
148
+
149
+ it "supports HH:MM:SS formatting with %T" do
150
+ @time.strftime('%T').should == '04:05:06'
151
+ @time.strftime('%T').should == @time.strftime('%H:%M:%S')
152
+ end
153
+
154
+ it "supports HH:MM:SS formatting with %X" do
155
+ @time.strftime('%X').should == '04:05:06'
156
+ @time.strftime('%X').should == @time.strftime('%H:%M:%S')
157
+ end
158
+
159
+ # GNU modificators
160
+ it "supports the '-' modifier to drop leading zeros" do
161
+ time = @new_time[2001,1,1,14,01,42]
162
+ time.strftime("%-m/%-d/%-y %-I:%-M %p").should == "1/1/1 2:1 PM"
163
+
164
+ time = @new_time[2010,10,10,12,10,42]
165
+ time.strftime("%-m/%-d/%-y %-I:%-M %p").should == "10/10/10 12:10 PM"
166
+ end
167
+
168
+ it "supports the '-' modifier for padded format directives" do
169
+ time = @new_time[2010, 8, 8, 8, 10, 42]
170
+ time.strftime("%-e").should == "8"
171
+ time.strftime("%-k%p").should == "8AM"
172
+ time.strftime("%-l%p").should == "8AM"
173
+ end
174
+ end
metadata CHANGED
@@ -1,67 +1,67 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysl-date
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Shirai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-05 00:00:00.000000000 Z
11
+ date: 2015-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ type: :development
14
15
  name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
+ version_requirements: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - "~>"
18
19
  - !ruby/object:Gem::Version
19
20
  version: '1.3'
20
- type: :development
21
21
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
22
+ requirement: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
+ type: :development
28
29
  name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
+ version_requirements: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - "~>"
32
33
  - !ruby/object:Gem::Version
33
34
  version: '10.0'
34
- type: :development
35
35
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
36
+ requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
+ type: :development
42
43
  name: mspec
43
- requirement: !ruby/object:Gem::Requirement
44
+ version_requirements: !ruby/object:Gem::Requirement
44
45
  requirements:
45
46
  - - "~>"
46
47
  - !ruby/object:Gem::Version
47
48
  version: '1.5'
48
- type: :development
49
49
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.5'
55
55
  - !ruby/object:Gem::Dependency
56
+ type: :development
56
57
  name: rubysl-prettyprint
57
- requirement: !ruby/object:Gem::Requirement
58
+ version_requirements: !ruby/object:Gem::Requirement
58
59
  requirements:
59
60
  - - "~>"
60
61
  - !ruby/object:Gem::Version
61
62
  version: '2.0'
62
- type: :development
63
63
  prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
@@ -77,6 +77,7 @@ files:
77
77
  - ".travis.yml"
78
78
  - Gemfile
79
79
  - LICENSE
80
+ - MRI_LICENSE
80
81
  - README.md
81
82
  - Rakefile
82
83
  - lib/date.rb
@@ -154,6 +155,8 @@ files:
154
155
  - spec/date/ld_spec.rb
155
156
  - spec/date/ld_to_jd_spec.rb
156
157
  - spec/date/leap_spec.rb
158
+ - spec/date/marshal_dump_spec.rb
159
+ - spec/date/marshal_load_spec.rb
157
160
  - spec/date/mday_spec.rb
158
161
  - spec/date/minus_month_spec.rb
159
162
  - spec/date/minus_spec.rb
@@ -243,6 +246,8 @@ files:
243
246
  - spec/datetime/to_time_spec.rb
244
247
  - spec/datetime/xmlschema_spec.rb
245
248
  - spec/datetime/zone_spec.rb
249
+ - spec/shared/strftime_for_date.rb
250
+ - spec/shared/strftime_for_time.rb
246
251
  - spec/time/to_date_spec.rb
247
252
  homepage: https://github.com/rubysl/rubysl-date
248
253
  licenses:
@@ -264,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
269
  version: '0'
265
270
  requirements: []
266
271
  rubyforge_project:
267
- rubygems_version: 2.2.2
272
+ rubygems_version: 2.4.5
268
273
  signing_key:
269
274
  specification_version: 4
270
275
  summary: Ruby standard library date.
@@ -335,6 +340,8 @@ test_files:
335
340
  - spec/date/ld_spec.rb
336
341
  - spec/date/ld_to_jd_spec.rb
337
342
  - spec/date/leap_spec.rb
343
+ - spec/date/marshal_dump_spec.rb
344
+ - spec/date/marshal_load_spec.rb
338
345
  - spec/date/mday_spec.rb
339
346
  - spec/date/minus_month_spec.rb
340
347
  - spec/date/minus_spec.rb
@@ -424,4 +431,6 @@ test_files:
424
431
  - spec/datetime/to_time_spec.rb
425
432
  - spec/datetime/xmlschema_spec.rb
426
433
  - spec/datetime/zone_spec.rb
434
+ - spec/shared/strftime_for_date.rb
435
+ - spec/shared/strftime_for_time.rb
427
436
  - spec/time/to_date_spec.rb