Skip to content

Commit

Permalink
今年, 今月, 今日 の処理の抜けを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
uneco committed May 18, 2012
1 parent 6f5d596 commit 5b34c59
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/horai/parser/ja_jp.rb
Expand Up @@ -32,6 +32,7 @@ def register_filters
end

filter /今年|本年|ことし|ほんねん/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date, month: 1, day: 1))
end

filter /来年|明年|らいねん|みょうねん/, :absolute do |text, matches, date|
Expand Down Expand Up @@ -64,6 +65,7 @@ def register_filters
end

filter /今月|こんげつ/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date, day: 1))
end

filter /来月|らいげつ/, :absolute do |text, matches, date|
Expand Down Expand Up @@ -95,6 +97,10 @@ def register_filters
truncate_time(date - 1.day)
end

filter /今日|本日|きょう|ほんじつ/, :absolute do |text, matches, date|
truncate_time(date)
end

filter /明日|あした|みょうじつ/, :absolute do |text, matches, date|
truncate_time(date + 1.day)
end
Expand Down
36 changes: 36 additions & 0 deletions spec/horai_spec.rb
Expand Up @@ -136,14 +136,46 @@ def now (year = nil, month = nil, day = nil, hour = nil, minute = nil, second =
$jajp.relative?("10分").should be_false
$jajp.relative?("10時10分").should be_false
end
it "two years ago" do
time = $jajp.parse("一昨年")
time.to_s.should === (now(nil, 1, 1, 0, 0, 0) - 2.year).to_s
end
it "last year" do
time = $jajp.parse("昨年")
time.to_s.should === (now(nil, 1, 1, 0, 0, 0) - 1.year).to_s
end
it "this year" do
time = $jajp.parse("今年")
time.to_s.should === (now(nil, 1, 1, 0, 0, 0)).to_s
end
it "next year" do
time = $jajp.parse("来年")
time.to_s.should === (now(nil, 1, 1, 0, 0, 0) + 1.year).to_s
end
it "year after next" do
time = $jajp.parse("再来年")
time.to_s.should === (now(nil, 1, 1, 0, 0, 0) + 2.year).to_s
end
it "two monthes ago" do
time = $jajp.parse("先々月")
time.to_s.should === (now(nil, nil, 1, 0, 0, 0) - 2.month).to_s
end
it "last month" do
time = $jajp.parse("先月")
time.to_s.should === (now(nil, nil, 1, 0, 0, 0) - 1.month).to_s
end
it "this month" do
time = $jajp.parse("今月")
time.to_s.should === (now(nil, nil, 1, 0, 0, 0) - 1.month).to_s
end
it "next month" do
time = $jajp.parse("来月")
time.to_s.should === (now(nil, nil, 1, 0, 0, 0) + 1.month).to_s
end
it "today" do
time = $jajp.parse("今日")
time.to_s.should === (now(nil, nil, nil, 0, 0, 0)).to_s
end
it "tomorrow" do
time = $jajp.parse("明日")
time.to_s.should === (now(nil, nil, nil, 0, 0, 0) + 1.day).to_s
Expand All @@ -156,6 +188,10 @@ def now (year = nil, month = nil, day = nil, hour = nil, minute = nil, second =
time = $jajp.parse("昨日")
time.to_s.should === (now(nil, nil, nil, 0, 0, 0) - 1.day).to_s
end
it "day before yesterday" do
time = $jajp.parse("一昨日")
time.to_s.should === (now(nil, nil, nil, 0, 0, 0) - 2.day).to_s
end
it "numeric year after and absolute month" do
time = $jajp.parse("10年後の8月")
time.to_s.should === (now(nil, 8, 1, 0, 0, 0) + 10.year).to_s
Expand Down

0 comments on commit 5b34c59

Please sign in to comment.