1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
require 'date'
require File.expand_path('../../../spec_helper', __FILE__)
describe "Date#strftime" do
it "should be able to print the date" do
Date.civil(2000, 4, 6).strftime.should == "2000-04-06"
Date.civil(2000, 4, 6).strftime.should == Date.civil(2000, 4, 6).to_s
end
it "should be able to print the full day name" do
Date.civil(2000, 4, 6).strftime("%A").should == "Thursday"
end
it "should be able to print the short day name" do
Date.civil(2000, 4, 6).strftime("%a").should == "Thu"
end
it "should be able to print the full month name" do
Date.civil(2000, 4, 6).strftime("%B").should == "April"
end
it "should be able to print the short month name" do
Date.civil(2000, 4, 6).strftime("%b").should == "Apr"
Date.civil(2000, 4, 6).strftime("%h").should == "Apr"
Date.civil(2000, 4, 6).strftime("%b").should == Date.civil(2000, 4, 6).strftime("%h")
end
it "should be able to print the century" do
Date.civil(2000, 4, 6).strftime("%C").should == "20"
end
it "should be able to print the month day with leading zeroes" do
Date.civil(2000, 4, 6).strftime("%d").should == "06"
end
it "should be able to print the month day with leading spaces" do
Date.civil(2000, 4, 6).strftime("%e").should == " 6"
end
it "should be able to print the commercial year with leading zeroes" do
Date.civil(2000, 4, 6).strftime("%G").should == "2000"
Date.civil( 200, 4, 6).strftime("%G").should == "0200"
end
it "should be able to print the commercial year with only two digits" do
Date.civil(2000, 4, 6).strftime("%g").should == "00"
Date.civil( 200, 4, 6).strftime("%g").should == "00"
end
it "should be able to print the hour with leading zeroes (hour is always 00)" do
Date.civil(2000, 4, 6).strftime("%H").should == "00"
end
it "should be able to print the hour in 12 hour notation with leading zeroes" do
Date.civil(2000, 4, 6).strftime("%I").should == "12"
end
it "should be able to print the year day with leading zeroes" do
Date.civil(2000, 4, 6).strftime("%j").should == "097"
end
it "should be able to print the hour in 24 hour notation with leading spaces" do
Date.civil(2000, 4, 6).strftime("%k").should == " 0"
end
it "should be able to print the hour in 12 hour notation with leading spaces" do
Date.civil(2000, 4, 6).strftime("%l").should == "12"
end
it "should be able to print the minutes with leading zeroes" do
Date.civil(2000, 4, 6).strftime("%M").should == "00"
end
it "should be able to print the month with leading zeroes" do
Date.civil(2000, 4, 6).strftime("%m").should == "04"
end
it "should be able to add a newline" do
Date.civil(2000, 4, 6).strftime("%n").should == "\n"
end
it "should be able to show AM/PM" do
Date.civil(2000, 4, 6).strftime("%P").should == "am"
end
it "should be able to show am/pm" do
Date.civil(2000, 4, 6).strftime("%p").should == "AM"
end
it "should be able to show the number of seconds with leading zeroes" do
Date.civil(2000, 4, 6).strftime("%S").should == "00"
end
it "should be able to show the number of seconds with leading zeroes" do
Date.civil(2000, 4, 6).strftime("%S").should == "00"
end
it "should be able to show the number of seconds since the unix epoch" do
Date.civil(2000, 4, 6).strftime("%s").should == "954979200"
end
it "should be able to add a tab" do
Date.civil(2000, 4, 6).strftime("%t").should == "\t"
end
it "should be able to show the week number with the week starting on sunday and monday" do
Date.civil(2000, 4, 6).strftime("%U").should == "14"
Date.civil(2000, 4, 6).strftime("%W").should == "14"
Date.civil(2000, 4, 6).strftime("%U").should == Date.civil(2000, 4, 6).strftime("%W")
Date.civil(2000, 4, 9).strftime("%U").should == "15"
Date.civil(2000, 4, 9).strftime("%W").should == "14"
Date.civil(2000, 4, 9).strftime("%U").should_not == Date.civil(2000, 4, 9).strftime("%W")
end
it "should be able to show the commercial week day" do
Date.civil(2000, 4, 9).strftime("%u").should == "7"
Date.civil(2000, 4, 10).strftime("%u").should == "1"
end
it "should be able to show the commercial week" do
Date.civil(2000, 4, 9).strftime("%V").should == "14"
Date.civil(2000, 4, 10).strftime("%V").should == "15"
end
it "should be able to show the week day" do
Date.civil(2000, 4, 9).strftime("%w").should == "0"
Date.civil(2000, 4, 10).strftime("%w").should == "1"
end
it "should be able to show the year in YYYY format" do
Date.civil(2000, 4, 9).strftime("%Y").should == "2000"
end
it "should be able to show the year in YY format" do
Date.civil(2000, 4, 9).strftime("%y").should == "00"
end
it "should be able to show the timezone of the date with a : separator" do
Date.civil(2000, 4, 9).strftime("%Z").should == "+00:00"
end
it "should be able to show the timezone of the date with a : separator" do
Date.civil(2000, 4, 9).strftime("%z").should == "+0000"
end
it "should be able to escape the % character" do
Date.civil(2000, 4, 9).strftime("%%").should == "%"
end
############################
# Specs that combine stuff #
############################
it "should be able to print the date in full" do
Date.civil(2000, 4, 6).strftime("%c").should == "Thu Apr 6 00:00:00 2000"
Date.civil(2000, 4, 6).strftime("%c").should == Date.civil(2000, 4, 6).strftime('%a %b %e %H:%M:%S %Y')
end
it "should be able to print the date with slashes" do
Date.civil(2000, 4, 6).strftime("%D").should == "04/06/00"
Date.civil(2000, 4, 6).strftime("%D").should == Date.civil(2000, 4, 6).strftime('%m/%d/%y')
end
it "should be able to print the date as YYYY-MM-DD" do
Date.civil(2000, 4, 6).strftime("%F").should == "2000-04-06"
Date.civil(2000, 4, 6).strftime("%F").should == Date.civil(2000, 4, 6).strftime('%Y-%m-%d')
end
it "should be able to show HH:MM" do
Date.civil(2000, 4, 6).strftime("%R").should == "00:00"
Date.civil(2000, 4, 6).strftime("%R").should == Date.civil(2000, 4, 6).strftime('%H:%M')
end
it "should be able to show HH:MM:SS AM/PM" do
Date.civil(2000, 4, 6).strftime("%r").should == "12:00:00 AM"
Date.civil(2000, 4, 6).strftime("%r").should == Date.civil(2000, 4, 6).strftime('%I:%M:%S %p')
end
it "should be able to show HH:MM:SS" do
Date.civil(2000, 4, 6).strftime("%T").should == "00:00:00"
Date.civil(2000, 4, 6).strftime("%T").should == Date.civil(2000, 4, 6).strftime('%H:%M:%S')
end
it "should be able to show the commercial week" do
Date.civil(2000, 4, 9).strftime("%v").should == " 9-Apr-2000"
Date.civil(2000, 4, 9).strftime("%v").should == Date.civil(2000, 4, 9).strftime('%e-%b-%Y')
end
it "should be able to show HH:MM:SS" do
Date.civil(2000, 4, 6).strftime("%X").should == "00:00:00"
Date.civil(2000, 4, 6).strftime("%X").should == Date.civil(2000, 4, 6).strftime('%H:%M:%S')
end
it "should be able to show MM/DD/YY" do
Date.civil(2000, 4, 6).strftime("%x").should == "04/06/00"
Date.civil(2000, 4, 6).strftime("%x").should == Date.civil(2000, 4, 6).strftime('%m/%d/%y')
end
it "should be able to show a full notation" do
Date.civil(2000, 4, 9).strftime("%+").should == "Sun Apr 9 00:00:00 +00:00 2000"
Date.civil(2000, 4, 9).strftime("%+").should == Date.civil(2000, 4, 9).strftime('%a %b %e %H:%M:%S %Z %Y')
end
end
|