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
|
# File 'lib/horai/parser/ja_jp.rb', line 12
def register_filters
dd = DATE_DELIMITER
td = TIME_DELIMITER
filter /(\d+)年/, :absolute do |text, matches, date|
year = year_normalize(matches[1].to_i)
truncate_time(datetime_delta(date, year: year, month: 1, day: 1))
end
filter /一昨[々昨]年|さきおととし|いっさくさくねん/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date - 3.year, month: 1, day: 1))
end
filter /一昨年|おととし|いっさくねん/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date - 2.year, month: 1, day: 1))
end
filter /去年|昨年|きょねん|さくねん/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date - 1.year, month: 1, day: 1))
end
filter /今年|本年|ことし|ほんねん/, :absolute do |text, matches, date|
end
filter /来年|明年|らいねん|みょうねん/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date + 1.year, month: 1, day: 1))
end
filter /再来年|明後年|さらいねん|みょうごねん/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date + 2.year, month: 1, day: 1))
end
filter /明[々明]後年|みょうみょうごねん/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date + 3.year, month: 1, day: 1))
end
filter /(\d+)月/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date, month: matches[1].to_i, day: 1))
end
filter /[先前][々先前]{3}月|せんせんせんげつ/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date - 3.month, day: 1))
end
filter /[先前][々先前]月|せんせんげつ/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date - 2.month, day: 1))
end
filter /先月|前月|せんげつ/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date - 1.month, day: 1))
end
filter /今月|こんげつ/, :absolute do |text, matches, date|
end
filter /来月|らいげつ/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date + 1.month, day: 1))
end
filter /再来月|来[々来]月|さらいげつ|らいらいげつ/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date + 2.month, day: 1))
end
filter /再[々再]来月|ささらいげつ/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date + 3.month, day: 1))
end
filter /(\d+)日/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date, day: matches[1]))
end
filter /一昨[々昨]日|さきおと[とつ]い|いっさくさくじつ/, :absolute do |text, matches, date|
truncate_time(date - 3.day)
end
filter /一昨日|おと[とつ]い|いっさくじつ/, :absolute do |text, matches, date|
truncate_time(date - 2.day)
end
filter /昨日|きのう|さくじつ/, :absolute do |text, matches, date|
truncate_time(date - 1.day)
end
filter /明日|あした|みょうじつ/, :absolute do |text, matches, date|
truncate_time(date + 1.day)
end
filter /明後日|あさって|みょうごにち/, :absolute do |text, matches, date|
truncate_time(date + 2.day)
end
filter /明[々明]後日|しあさって|みょうみょうごにち/, :absolute do |text, matches, date|
truncate_time(date + 3.day)
end
filter /(?<![\d\/-])(?<!\d)(\d{1,2})#{dd}(\d{1,2})(?!#{dd})/, :absolute do |text, matches, date|
truncate_time(datetime_delta(date, month: matches[1], day: matches[2]))
end
filter /(?<![\d\/-])(\d{1,2}|\d{4})#{dd}(\d{1,2})#{dd}(\d{1,2})(?!#{dd})/, :absolute do |text, matches, date|
year = year_normalize(matches[1].to_i)
truncate_time(datetime_delta(date, year: year, month: matches[2], day: matches[3]))
end
filter /(?<![\d:])(\d{1,2})#{td}(\d{2})(?!#{td})/, :absolute do |text, matches, date|
datetime_delta(date, hour: matches[1], minute: matches[2], second: 0)
end
filter /(?<![\d:])(\d{1,2})#{td}(\d{2})#{td}(\d{2})(?!#{td})/, :absolute do |text, matches, date|
datetime_delta(date, hour: matches[1], minute: matches[2], second: matches[3])
end
filter /正午/, :absolute do |text, matches, date|
datetime_delta(date, hour: 12, minute: 0, second: 0)
end
filter /(\d+)時(半)?/, :absolute do |text, matches, date|
hour = matches[1]
minute = matches[2] ? 30 : 0
date = datetime_delta(date, hour: hour, minute: minute, second: 0)
date += 12.hour if date.hour <= 12 && text =~ AFTERNOON_PATTERN
date
end
filter /(\d+)分(半)?/, :absolute do |text, matches, date|
minute = matches[1]
second = matches[2] ? 30 : 0
datetime_delta(date, minute: minute, second: second)
end
filter /(\d+)秒/, :absolute do |text, matches, date|
datetime_delta(date, second: matches[1])
end
filter /(\d+)年/, :relative do |text, matches, date|
date + matches[1].to_i.year
end
filter /(\d+)月/, :relative do |text, matches, date|
date + matches[1].to_i.month
end
filter /(\d+)日/, :relative do |text, matches, date|
date + matches[1].to_f.day
end
filter /(\d+)時間(半)?/, :relative do |text, matches, date|
date + matches[1].to_f.hour + (matches[2] ? 0.5 : 0.0).hour
end
filter /(\d+)分(半)?/, :relative do |text, matches, date|
date + matches[1].to_f.minute + (matches[2] ? 0.5 : 0.0).minute
end
filter /(\d+)秒/, :relative do |text, matches, date|
date + matches[1].to_f.second
end
end
|