Old_Timeperiod_Model Class Reference

A model used by reports to lookup when report times and timeperiods start and stop. More...

Public Member Functions

 __construct ($options)
 Warning: you should not use this directly.
 set_timeperiod_data ($period=NULL)
 Setup the data to base the timeperiod on.
 active_time ($start, $stop)
 Returns the number of active seconds "inside" the timeperiod during the start -> stop interval.
 tp_next ($when, $what= 'start')
 Finds next start or stop of timeperiod from a given timestamp.
 inside ($timestamp)
 Returns whether the given timestamp is inside timeperiod.
 resolve_timeperiods ()
 Resolve timeperiods, both the actual timeperiods and the exclusions.
 set_timeperiod_variable ($name, $value)
 Parses given input as a nagios 3 timeperiod variable.
 is_daterange_single_day (&$dr)
 Return true if both the start date and end date is the same day.
 print_timerange (&$r)
 Print the timerange $r.
 calculate_time_from_day_of_month ($year, $month, $monthday)
 Converts a date into timestamp, with some extra features such as negative days of month to use days from the end of the month.
 calculate_time_from_weekday_of_month ($year, $month, $weekday, $weekday_offset)
 Nagios supports exceptions such as "third monday in november 2010" - this converts such statements to unix timestamps.
 timeranges_overlap (&$range1, &$range2, $inclusive=false)
 Determines if two timeranges overlap Note: stop time equal to start time in other range is NOT considered an overlap.
 merge_timeranges (&$src_range, &$dst_range)
 Merges two timeranges into one.
 add_timerange_to_set ($range, &$timerange_set)
 Add a new timerange to a set of timeranges.
 merge_timerange_sets (&$timerange_set1, &$timerange_set2)
 Merge two sets of timeranges into one, with no overlapping ranges.

Static Public Member Functions

static instance ($options)
 Return an instance from a Report_options object.
static get ($period)
 Fetch info on a timeperiod.
static get_all ()
 Fetch all timperiods.

Data Fields

 $start_time = false
 Report start.
 $end_time = false
 Report stop.
 $tp_exceptions = array()
 Timeperiod exceptions.
 $tp_excludes = array()
 Timeperiod excludes.
const DATERANGE_CALENDAR_DATE = 0
 eg: 2001-01-01 - 2010-11-21 / 3 (specific complete calendar date)
const DATERANGE_MONTH_DATE = 1
 eg: july 4 - november 15 / 3 (specific month)
const DATERANGE_MONTH_DAY = 2
 eg: day 1 - 25 / 5 (generic month)
const DATERANGE_MONTH_WEEK_DAY = 3
 eg: thursday 1 april - tuesday 2 may / 2 (specific month)
const DATERANGE_WEEK_DAY = 4
 eg: thursday 3 - monday 4 (generic month)
const DATERANGE_TYPES = 5
 FIXME: incomprehensible magic.

Static Public Attributes

static $precreated = array()
 Please do not touch this outside of tests, it's a cache for performance purposes.

Protected Member Functions

 tp_parse_day ($str)
 Parses a timerange string FIXME: add more validation.
 add_timeperiod_exception ($dateperiod_type, $syear, $smon, $smday, $swday, $swday_offset, $eyear, $emon, $emday, $ewday, $ewday_offset, $skip_interval, $timeranges)
 Adds a timeperiod exception to the report.

Protected Attributes

 $period = false
 Definition of the regular (weekday) timeperiod definitions.

Detailed Description

A model used by reports to lookup when report times and timeperiods start and stop.

This sounds real easy, until you start to look at nagios' less trivial timeperiod definitions.

You should call the instance() method to get a timeperiod instance, which might be shared with other users. This class will call instance() itself, so exceptions to exceptions work.


Member Function Documentation

Old_Timeperiod_Model::active_time ( start,
stop 
)

Returns the number of active seconds "inside" the timeperiod during the start -> stop interval.

Parameters:
$start,: A timestamp in the unix epoch notation
$stop,: A timestamp in the unix epoch notation
Returns:
The number of seconds included in both $stop - $start and the timeperiod set for this report as an integer in the unix epoch notation
Old_Timeperiod_Model::add_timeperiod_exception ( dateperiod_type,
syear,
smon,
smday,
swday,
swday_offset,
eyear,
emon,
emday,
ewday,
ewday_offset,
skip_interval,
timeranges 
) [protected]

Adds a timeperiod exception to the report.

FIXME: should probably validate more

Parameters:
$dateperiod_type Indicates the type of exception. Se timeperiod_class.php for valid values.
$syear Start year
$smon Start month
$smday Start day of month
$swday Start weekday
$swday_offset Start weekday offset
$eyear End year
$emon End month
$emday End day of month
$ewday End weekday
$ewday_offset End weekday offset
$skip_interval Interval to skip, such as: "every 3 weeks" etc
$timeranges Array of timeranges. Throws Exception if any parameter has bogus values.
Old_Timeperiod_Model::add_timerange_to_set ( range,
&$  timerange_set 
)

Add a new timerange to a set of timeranges.

If new range overlaps an existing range, the two are merged to one.

Assumes timeranges contain only valid values (eg: stop time after start time) Assumes the timerange set does not contain overlapping periods itself

Parameters:
$range Array of range(s) to add
$timerange_set The timerange set to add to
Old_Timeperiod_Model::calculate_time_from_day_of_month ( year,
month,
monthday 
)

Converts a date into timestamp, with some extra features such as negative days of month to use days from the end of the month.

As for time, 00:00:00 of the day is used.

Parameters:
$year Year.
$month Month.
$monthday - Day of month, can be negative.
Returns:
The resulting timestamp.
Old_Timeperiod_Model::calculate_time_from_weekday_of_month ( year,
month,
weekday,
weekday_offset 
)

Nagios supports exceptions such as "third monday in november 2010" - this converts such statements to unix timestamps.

Parameters:
$year The year
$month The month number
$weekday The weekday's numeric presentation (0=sunday, 6=saturday)
$weekday_offset Which occurence of the weekday, can be negative
static Old_Timeperiod_Model::get ( period  )  [static]

Fetch info on a timeperiod.

Parameters:
$period string: Timeperiod name
Returns:
an array of the timeperiod's properties
static Old_Timeperiod_Model::get_all (  )  [static]

Fetch all timperiods.

Returns:
db result
Old_Timeperiod_Model::inside ( timestamp  ) 

Returns whether the given timestamp is inside timeperiod.

Parameters:
$timestamp,: A timestamp in the unix epoch notation
Returns:
TRUE if the timestamp is inside the timeperiod, FALSE otherwise
static Old_Timeperiod_Model::instance ( options  )  [static]

Return an instance from a Report_options object.

Parameters:
$options Report_options class, or possibly an array mock
Old_Timeperiod_Model::is_daterange_single_day ( &$  dr  ) 

Return true if both the start date and end date is the same day.

Parameters:
$dr A daterange
Returns:
true if condition holds
Old_Timeperiod_Model::merge_timerange_sets ( &$  timerange_set1,
&$  timerange_set2 
)

Merge two sets of timeranges into one, with no overlapping ranges.

Assumption: The argument sets may contain overlapping timeranges, which are wrong in principle, but we'll manage anyway.

Parameters:
$timerange_set1 (of structure array( array('start' => 1203120, 'stop' => 120399), aray('start' => 140104, 'stop') ....)
$timerange_set2 (of structure array( array('start' => 1203120, 'stop' => 120399), aray('start' => 140104, 'stop') ....)
Returns:
array
Old_Timeperiod_Model::merge_timeranges ( &$  src_range,
&$  dst_range 
)

Merges two timeranges into one.

Assumes timeranges actually overlap and timeranges are correct (stop time after start time)

Parameters:
$src_range array
$dst_range array
Returns:
array
Old_Timeperiod_Model::print_timerange ( &$  r  ) 

Print the timerange $r.

Parameters:
$r A timerange
Old_Timeperiod_Model::set_timeperiod_data ( period = NULL  ) 

Setup the data to base the timeperiod on.

You really shouldn't be using this, unless you're a test and want to mock a timeperiod

Parameters:
$period A timeperiod db result
Returns:
true on success, false otherwise
Old_Timeperiod_Model::set_timeperiod_variable ( name,
value 
)

Parses given input as a nagios 3 timeperiod variable.

If valid, it is added to the report. Code is derived from the nagios 3 sources (xdata/xodtemplate.c) FIXME: find better way of adding 24h to end date

Parameters:
$name The timeperiod style variable we want to parse
$value The value of the timeperiod variable
Returns:
boolean
Old_Timeperiod_Model::timeranges_overlap ( &$  range1,
&$  range2,
inclusive = false 
)

Determines if two timeranges overlap Note: stop time equal to start time in other range is NOT considered an overlap.

Parameters:
$range1 array('start'=> {timestamp}, 'stop' => {timestamp})
$range2 array('start'=> {timestamp}, 'stop' => {timestamp})
$inclusive Whether to count "straddling" periods as ovelapping, (Eg: start1 == stop2 or start2 == stop1)
Returns:
boolean
Old_Timeperiod_Model::tp_next ( when,
what = 'start' 
)

Finds next start or stop of timeperiod from a given timestamp.

If given time is in an inactive timeperiod and we're looking for a stop, current time is returned. Vice versa, if we're looking for start inside an active period, the current timestamp is returned.

Parameters:
$when Current timestamp to start from.
$what Whether to search for start or stop. Valid values are 'start' and 'stop'.
Returns:
The timestamp
Old_Timeperiod_Model::tp_parse_day ( str  )  [protected]

Parses a timerange string FIXME: add more validation.

Parameters:
$str string
Returns:
An array of timeranges E.g: $str="08:00-12:00,13:00-17:00" gives: array ( array('start' => 28800, 'stop' => 43200), array('start' => 46800, 'stop' => 61200) );

The documentation for this class was generated from the following file:
 All Data Structures Functions Variables

Generated on 22 Apr 2013 for ninja by  doxygen 1.6.1