-class Chronic::RepeaterDayName < Chronic::Repeater #:nodoc:
- DAY_SECONDS = 86400 # (24 * 60 * 60)
-
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_DayName extends Horde_Date_Parser_Locale_Base_Repeater
+{
+ // (24 * 60 * 60)
+ const DAY_SECONDS = 86400;
+
def next(pointer)
super
-
+
direction = pointer == :future ? 1 : -1
-
+
if !@current_day_start
@current_day_start = Time.construct(@now.year, @now.month, @now.day)
@current_day_start += direction * DAY_SECONDS
day_num = symbol_to_number(@type)
-
+
while @current_day_start.wday != day_num
@current_day_start += direction * DAY_SECONDS
end
else
@current_day_start += direction * 7 * DAY_SECONDS
end
-
+
Chronic::Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
end
-
+
def this(pointer = :future)
super
-
+
pointer = :future if pointer == :none
self.next(pointer)
end
-
+
def width
DAY_SECONDS
end
-
+
def to_s
super << '-dayname-' << @type.to_s
end
-
+
private
-
+
def symbol_to_number(sym)
lookup = {:sunday => 0, :monday => 1, :tuesday => 2, :wednesday => 3, :thursday => 4, :friday => 5, :saturday => 6}
lookup[sym] || raise("Invalid symbol specified")
-class Chronic::RepeaterDayPortion < Chronic::Repeater #:nodoc:
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_DayPortion extends Horde_Date_Parser_Locale_Base_Repeater
+{
@@morning = (6 * 60 * 60)..(12 * 60 * 60) # 6am-12am
@@afternoon = (13 * 60 * 60)..(17 * 60 * 60) # 1pm-5pm
@@evening = (17 * 60 * 60)..(20 * 60 * 60) # 5pm-8pm
@@night = (20 * 60 * 60)..(24 * 60 * 60) # 8pm-12pm
-
+
def initialize(type)
super
-
+
if type.kind_of? Integer
@range = (@type * 60 * 60)..((@type + 12) * 60 * 60)
else
end
@range || raise("Range should have been set by now")
end
-
+
def next(pointer)
super
-
+
full_day = 60 * 60 * 24
-
+
if !@current_span
now_seconds = @now - Time.construct(@now.year, @now.month, @now.day)
if now_seconds < @range.begin
range_start = Time.construct(@now.year, @now.month, @now.day) - full_day + @range.begin
end
end
-
+
@current_span = Chronic::Span.new(range_start, range_start + (@range.end - @range.begin))
else
case pointer
end
end
end
-
+
def this(context = :future)
super
-
+
range_start = Time.construct(@now.year, @now.month, @now.day) + @range.begin
@current_span = Chronic::Span.new(range_start, range_start + (@range.end - @range.begin))
end
-
+
def offset(span, amount, pointer)
@now = span.begin
portion_span = self.next(pointer)
direction = pointer == :future ? 1 : -1
portion_span + (direction * (amount - 1) * Chronic::RepeaterDay::DAY_SECONDS)
end
-
+
def width
@range || raise("Range has not been set")
return @current_span.width if @current_span
@range.end - @range.begin
end
end
-
+
def to_s
super << '-dayportion-' << @type.to_s
end
-class Chronic::RepeaterFortnight < Chronic::Repeater #:nodoc:
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_Fortnight extends Horde_Date_Parser_Locale_Base_Repeater
+{
FORTNIGHT_SECONDS = 1_209_600 # (14 * 24 * 60 * 60)
-
+
def next(pointer)
super
-
+
if !@current_fortnight_start
case pointer
when :future
direction = pointer == :future ? 1 : -1
@current_fortnight_start += direction * FORTNIGHT_SECONDS
end
-
+
Chronic::Span.new(@current_fortnight_start, @current_fortnight_start + FORTNIGHT_SECONDS)
end
-
+
def this(pointer = :future)
super
-
+
pointer = :future if pointer == :none
-
+
case pointer
when :future
this_fortnight_start = Time.construct(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
Chronic::Span.new(this_fortnight_start, this_fortnight_end)
end
end
-
+
def offset(span, amount, pointer)
direction = pointer == :future ? 1 : -1
span + direction * amount * FORTNIGHT_SECONDS
def width
FORTNIGHT_SECONDS
end
-
+
def to_s
super << '-fortnight'
end
-class Chronic::RepeaterHour < Chronic::Repeater #:nodoc:
- HOUR_SECONDS = 3600 # 60 * 60
-
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_Hour extends Horde_Date_Parser_Locale_Base_Repeater
+{
+ /**
+ * 60 * 60
+ */
+ const HOUR_SECONDS = 3600;
+
def next(pointer)
super
-
+
if !@current_hour_start
case pointer
when :future
direction = pointer == :future ? 1 : -1
@current_hour_start += direction * HOUR_SECONDS
end
-
+
Chronic::Span.new(@current_hour_start, @current_hour_start + HOUR_SECONDS)
end
-
+
def this(pointer = :future)
super
-
+
case pointer
when :future
hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour)
hour_end = hour_begin + HOUR_SECONDS
end
-
+
Chronic::Span.new(hour_start, hour_end)
end
-
+
def offset(span, amount, pointer)
direction = pointer == :future ? 1 : -1
span + direction * amount * HOUR_SECONDS
end
-
+
def width
HOUR_SECONDS
end
-
+
def to_s
super << '-hour'
end
-class Chronic::RepeaterMinute < Chronic::Repeater #:nodoc:
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_Minute extends Horde_Date_Parser_Locale_Base_Repeater
+{
MINUTE_SECONDS = 60
-
+
def next(pointer = :future)
super
-
+
if !@current_minute_start
case pointer
when :future
direction = pointer == :future ? 1 : -1
@current_minute_start += direction * MINUTE_SECONDS
end
-
+
Chronic::Span.new(@current_minute_start, @current_minute_start + MINUTE_SECONDS)
end
-
+
def this(pointer = :future)
super
-
+
case pointer
when :future
minute_begin = @now
minute_begin = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
minute_end = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min) + MINUTE_SECONDS
end
-
+
Chronic::Span.new(minute_begin, minute_end)
end
-
+
def offset(span, amount, pointer)
direction = pointer == :future ? 1 : -1
span + direction * amount * MINUTE_SECONDS
end
-
+
def width
MINUTE_SECONDS
end
-
+
def to_s
super << '-minute'
end
-class Chronic::RepeaterMonth < Chronic::Repeater #:nodoc:
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_Month extends Horde_Date_Parser_Locale_Base_Repeater
+{
MONTH_SECONDS = 2_592_000 # 30 * 24 * 60 * 60
YEAR_MONTHS = 12
-
+
def next(pointer)
super
-
+
if !@current_month_start
@current_month_start = offset_by(Time.construct(@now.year, @now.month), 1, pointer)
else
@current_month_start = offset_by(Time.construct(@current_month_start.year, @current_month_start.month), 1, pointer)
end
-
+
Chronic::Span.new(@current_month_start, Time.construct(@current_month_start.year, @current_month_start.month + 1))
end
-
+
def this(pointer = :future)
super
-
+
case pointer
when :future
month_start = Time.construct(@now.year, @now.month, @now.day + 1)
month_start = Time.construct(@now.year, @now.month)
month_end = self.offset_by(Time.construct(@now.year, @now.month), 1, :future)
end
-
+
Chronic::Span.new(month_start, month_end)
end
-
- def offset(span, amount, pointer)
+
+ def offset(span, amount, pointer)
Chronic::Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
end
-
- def offset_by(time, amount, pointer)
+
+ def offset_by(time, amount, pointer)
direction = pointer == :future ? 1 : -1
-
+
amount_years = direction * amount / YEAR_MONTHS
amount_months = direction * amount % YEAR_MONTHS
-
+
new_year = time.year + amount_years
new_month = time.month + amount_months
if new_month > YEAR_MONTHS
end
Time.construct(new_year, new_month, time.day, time.hour, time.min, time.sec)
end
-
+
def width
MONTH_SECONDS
end
-
+
def to_s
super << '-month'
end
-class Chronic::RepeaterMonthName < Chronic::Repeater #:nodoc:
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_MonthName extends Horde_Date_Parser_Locale_Base_Repeater
+{
MONTH_SECONDS = 2_592_000 # 30 * 24 * 60 * 60
-
+
def next(pointer)
super
-
+
if !@current_month_begin
target_month = symbol_to_number(@type)
case pointer
@current_month_begin = Time.construct(@current_month_begin.year - 1, @current_month_begin.month)
end
end
-
+
cur_month_year = @current_month_begin.year
cur_month_month = @current_month_begin.month
-
+
if cur_month_month == 12
next_month_year = cur_month_year + 1
next_month_month = 1
next_month_year = cur_month_year
next_month_month = cur_month_month + 1
end
-
+
Chronic::Span.new(@current_month_begin, Time.construct(next_month_year, next_month_month))
end
-
+
def this(pointer = :future)
super
-
+
case pointer
when :past
self.next(pointer)
self.next(:none)
end
end
-
+
def width
MONTH_SECONDS
end
-
+
def index
symbol_to_number(@type)
end
-
+
def to_s
super << '-monthname-' << @type.to_s
end
-
+
private
-
+
def symbol_to_number(sym)
lookup = {:january => 1,
:february => 2,
-class Chronic::RepeaterSecond < Chronic::Repeater #:nodoc:
- SECOND_SECONDS = 1 # haha, awesome
-
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_Second extends Horde_Date_Parser_Locale_Base_Repeater
+{
+ const SECOND_SECONDS = 1;
+
def next(pointer = :future)
super
-
+
direction = pointer == :future ? 1 : -1
-
+
if !@second_start
@second_start = @now + (direction * SECOND_SECONDS)
else
@second_start += SECOND_SECONDS * direction
end
-
+
Chronic::Span.new(@second_start, @second_start + SECOND_SECONDS)
end
-
+
def this(pointer = :future)
super
-
+
Chronic::Span.new(@now, @now + 1)
end
-
+
def offset(span, amount, pointer)
direction = pointer == :future ? 1 : -1
span + direction * amount * SECOND_SECONDS
end
-
+
def width
SECOND_SECONDS
end
-
+
def to_s
super << '-second'
end
-end
\ No newline at end of file
+end
-class Chronic::RepeaterTime < Chronic::Repeater #:nodoc:
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_Time extends Horde_Date_Parser_Locale_Base_Repeater
+{
+
class Tick #:nodoc:
attr_accessor :time
-
+
def initialize(time, ambiguous = false)
@time = time
@ambiguous = ambiguous
end
-
+
def ambiguous?
@ambiguous
end
-
+
def *(other)
Tick.new(@time * other, @ambiguous)
end
-
+
def to_f
@time.to_f
end
-
+
def to_s
@time.to_s + (@ambiguous ? '?' : '')
end
end
-
+
def initialize(time, options = {})
t = time.gsub(/\:/, '')
- @type =
+ @type =
if (1..2) === t.size
hours = t.to_i
hours == 12 ? Tick.new(0 * 60 * 60, true) : Tick.new(hours * 60 * 60, true)
raise("Time cannot exceed six digits")
end
end
-
+
# Return the next past or future Span for the time that this Repeater represents
# pointer - Symbol representing which temporal direction to fetch the next day
# must be either :past or :future
def next(pointer)
super
-
+
half_day = 60 * 60 * 12
full_day = 60 * 60 * 24
-
+
first = false
-
+
unless @current_time
first = true
midnight = Time.local(@now.year, @now.month, @now.day)
end
end
end
-
+
@current_time || raise("Current time cannot be nil at this point")
end
-
+
unless first
increment = @type.ambiguous? ? half_day : full_day
@current_time += pointer == :future ? increment : -increment
end
-
+
Chronic::Span.new(@current_time, @current_time + width)
end
-
+
def this(context = :future)
super
-
+
context = :future if context == :none
-
+
self.next(context)
end
-
+
def width
1
end
-
+
def to_s
super << '-time-' << @type.to_s
end
-class Chronic::RepeaterWeek < Chronic::Repeater #:nodoc:
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_Week extends Horde_Date_Parser_Locale_Base_Repeater
+{
WEEK_SECONDS = 604800 # (7 * 24 * 60 * 60)
-
+
def next(pointer)
super
-
+
if !@current_week_start
case pointer
when :future
direction = pointer == :future ? 1 : -1
@current_week_start += direction * WEEK_SECONDS
end
-
+
Chronic::Span.new(@current_week_start, @current_week_start + WEEK_SECONDS)
end
-
+
def this(pointer = :future)
super
-
+
case pointer
when :future
this_week_start = Time.local(@now.year, @now.month, @now.day, @now.hour) + Chronic::RepeaterHour::HOUR_SECONDS
Chronic::Span.new(this_week_start, this_week_start + WEEK_SECONDS)
end
end
-
+
def offset(span, amount, pointer)
direction = pointer == :future ? 1 : -1
span + direction * amount * WEEK_SECONDS
end
-
+
def width
WEEK_SECONDS
end
-
+
def to_s
super << '-week'
end
-class Chronic::RepeaterWeekend < Chronic::Repeater #:nodoc:
+<?php
+class Horde_Date_Parser_Locale_Base_Repeater_Weekend extends Horde_Date_Parser_Locale_Base_Repeater
+{
WEEKEND_SECONDS = 172_800 # (2 * 24 * 60 * 60)
-
+
def next(pointer)
super
-
+
if !@current_week_start
case pointer
when :future
direction = pointer == :future ? 1 : -1
@current_week_start += direction * Chronic::RepeaterWeek::WEEK_SECONDS
end
-
+
Chronic::Span.new(@current_week_start, @current_week_start + WEEKEND_SECONDS)
end
-
+
def this(pointer = :future)
super
-
+
case pointer
when :future, :none
saturday_repeater = Chronic::RepeaterDayName.new(:saturday)
Chronic::Span.new(last_saturday_span.begin, last_saturday_span.begin + WEEKEND_SECONDS)
end
end
-
+
def offset(span, amount, pointer)
direction = pointer == :future ? 1 : -1
weekend = Chronic::RepeaterWeekend.new(:weekend)
start = weekend.next(pointer).begin + (amount - 1) * direction * Chronic::RepeaterWeek::WEEK_SECONDS
Chronic::Span.new(start, start + (span.end - span.begin))
end
-
+
def width
WEEKEND_SECONDS
end
-
+
def to_s
super << '-weekend'
end