SMWDITime Class Reference
[SMWDataItems]

This class implements time data items. More...

Inherits SMWDataItem.

List of all members.

Public Member Functions

 __construct ($calendarmodel, $year, $month=false, $day=false, $hour=false, $minute=false, $second=false)
 Create a time data item.
 getDIType ()
 Convenience method that returns a constant that defines the concrete class that implements this data item.
 getCalendarModel ()
 getPrecision ()
 getYear ()
 getMonth ()
 getDay ()
 getHour ()
 getMinute ()
 getSecond ()
 getMwTimestamp ($outputtype=TS_UNIX)
 Returns a MW timestamp representatation of the value.
 getForCalendarModel ($calendarmodel)
 Get the data in the specified calendar model.
 getSortKey ()
 Return a number that helps comparing time data items.
 getJD ()
 getSerialization ()
 Get a UTF-8 encoded string serialization of this data item.

Static Public Member Functions

static doUnserialize ($serialization)
 Create a data item from the provided serialization string and type ID.
static newFromJD ($jdvalue, $calendarmodel, $precision)
 Create a new time data item from the specified Julian Day number, calendar model, presicion, and type ID.
static date2JD ($year, $month, $day, $calendarmodel)
 Compute the Julian Day number from a given date in the specified calendar model.
static time2JDoffset ($hours, $minutes, $seconds)
 Compute the offset for the Julian Day number from a given time.
static JD2Date ($jdvalue, $calendarmodel)
 Convert a Julian Day number to a date in the given calendar model.
static JD2Time ($jdvalue)
 Extract the time from a Julian Day number and return it as a string.
static isLeapYear ($year, $calendarmodel)
 Find out whether the given year number is a leap year.
static getDayNumberForMonth ($month, $year, $calendarmodel)
 Find out how many days the given month had in the given year based on the specified calendar model.

Public Attributes

const CM_GREGORIAN = 1
const CM_JULIAN = 2
const PREC_Y = 0
const PREC_YM = 1
const PREC_YMD = 2
const PREC_YMDT = 3

Protected Attributes

 $m_precision
 $m_model
 $m_year
 $m_month
 $m_day
 $m_hours
 $m_minutes
 $m_seconds

Static Protected Attributes

static $m_daysofmonths = array ( 1 => 31, 2 => 29, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31 )


Detailed Description

This class implements time data items.

Such data items represent a unique point in time, given in either Julian or Gregorian notation (possibly proleptic), and a precision setting that states which of the components year, month, day, time were specified expicitly. Even when not specified, the data item always assumes default values for the missing parts, so the item really captures one point in time, no intervals. Times are always assumed to be in UTC.

"Y0K issue": Neither the Gregorian nor the Julian calendar assume a year 0, i.e. the year 1 BC(E) was followed by 1 AD/CE. See http://en.wikipedia.org/wiki/Year_zero This implementation adheres to this convention and disallows year 0. The stored year numbers use positive numbers for CE and negative numbers for BCE. This is not just relevant for the question of how many years have (exactly) passed since a given date, but also for the location of leap years.

Since:
1.6
Author:
Markus Krötzsch

Definition at line 30 of file SMW_DI_Time.php.


Constructor & Destructor Documentation

SMWDITime::__construct ( calendarmodel,
year,
month = false,
day = false,
hour = false,
minute = false,
second = false 
)

Create a time data item.

All time components other than the year can be false to indicate that they are not specified. This will affect the internal precision setting. The missing values are initialised to minimal values (0 or 1) for internal calculations.

Parameters:
$calendarmodel integer one of SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
$year integer number of the year (possibly negative)
$month mixed integer number or false
$day mixed integer number or false
$hour mixed integer number or false
$minute mixed integer number or false
$second mixed integer number or false
Todo:
Implement more validation here.

Definition at line 104 of file SMW_DI_Time.php.


Member Function Documentation

SMWDITime::getDIType (  ) 

Convenience method that returns a constant that defines the concrete class that implements this data item.

Used to switch when processing data items.

Returns:
integer that specifies the basic type of data item

Reimplemented from SMWDataItem.

Definition at line 139 of file SMW_DI_Time.php.

References SMWDataItem::TYPE_TIME.

SMWDITime::getCalendarModel (  ) 

Definition at line 143 of file SMW_DI_Time.php.

SMWDITime::getPrecision (  ) 

Definition at line 147 of file SMW_DI_Time.php.

SMWDITime::getYear (  ) 

Definition at line 151 of file SMW_DI_Time.php.

SMWDITime::getMonth (  ) 

Definition at line 155 of file SMW_DI_Time.php.

SMWDITime::getDay (  ) 

Definition at line 159 of file SMW_DI_Time.php.

Referenced by SMWTimeValue::getCaptionFromDataitem().

SMWDITime::getHour (  ) 

Definition at line 163 of file SMW_DI_Time.php.

SMWDITime::getMinute (  ) 

Definition at line 167 of file SMW_DI_Time.php.

SMWDITime::getSecond (  ) 

Definition at line 171 of file SMW_DI_Time.php.

SMWDITime::getMwTimestamp ( outputtype = TS_UNIX  ) 

Returns a MW timestamp representatation of the value.

Since:
1.6.2
Parameters:
$outputtype 

Definition at line 182 of file SMW_DI_Time.php.

SMWDITime::getForCalendarModel ( calendarmodel  ) 

Get the data in the specified calendar model.

This might require conversion.

Note:
Conversion can be unreliable for very large absolute year numbers when the internal calculations hit floating point accuracy. Callers might want to avoid this (calendar models make little sense in such cases anyway).
Parameters:
$calendarmodel integer one of SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
Returns:
SMWDITime

Definition at line 206 of file SMW_DI_Time.php.

References getJD().

SMWDITime::getSortKey (  ) 

Return a number that helps comparing time data items.

For dates in the Julian Day era (roughly from 4713 BCE onwards), we use the Julian Day number. For earlier dates, the (negative) year number with a fraction for the date is used (times are ignored). This avoids calculation errors that would occur for very ancient dates if the JD number was used there.

Returns:
double sortkey

Reimplemented from SMWDataItem.

Definition at line 223 of file SMW_DI_Time.php.

References getJD().

SMWDITime::getJD (  ) 

Definition at line 232 of file SMW_DI_Time.php.

Referenced by getForCalendarModel(), and getSortKey().

SMWDITime::getSerialization (  ) 

Get a UTF-8 encoded string serialization of this data item.

The serialisation should be concise and need not be pretty, but it must allow unserialization. Each subclass of SMWDataItem implements a static method doUnserialize() for this purpose.

Returns:
string

Reimplemented from SMWDataItem.

Definition at line 237 of file SMW_DI_Time.php.

static SMWDITime::doUnserialize ( serialization  )  [static]

Create a data item from the provided serialization string and type ID.

Returns:
SMWDITime

Definition at line 256 of file SMW_DI_Time.php.

static SMWDITime::newFromJD ( jdvalue,
calendarmodel,
precision 
) [static]

Create a new time data item from the specified Julian Day number, calendar model, presicion, and type ID.

Parameters:
$jdvalue double Julian Day number
$calendarmodel integer either SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
$precision integer one of SMWDITime::PREC_Y, SMWDITime::PREC_YM, SMWDITime::PREC_YMD, SMWDITime::PREC_YMDT
Returns:
SMWDITime object

Definition at line 287 of file SMW_DI_Time.php.

Referenced by SMWSetRecurringEvent::jdToTimeValue(), SMWTimeValue::parseUserValue(), and SMWTimeValue::setDateFromParsedValues().

static SMWDITime::date2JD ( year,
month,
day,
calendarmodel 
) [static]

Compute the Julian Day number from a given date in the specified calendar model.

This calculation assumes that neither calendar has a year 0.

Parameters:
$year integer representing the year
$month integer representing the month
$day integer representing the day
$calendarmodel integer either SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
Returns:
float Julian Day number

Definition at line 313 of file SMW_DI_Time.php.

static SMWDITime::time2JDoffset ( hours,
minutes,
seconds 
) [static]

Compute the offset for the Julian Day number from a given time.

This computation is the same for all calendar models.

Parameters:
$hours integer representing the hour
$minutes integer representing the minutes
$seconds integer representing the seconds
Returns:
float offset for a Julian Day number to get this time

Definition at line 335 of file SMW_DI_Time.php.

static SMWDITime::JD2Date ( jdvalue,
calendarmodel 
) [static]

Convert a Julian Day number to a date in the given calendar model.

This calculation assumes that neither calendar has a year 0.

Note:
The algorithm may fail for some cases, in particular since the conversion to Gregorian needs positive JD. If this happens, wrong values will be returned. Avoid date conversions before 10000 BCE.
Parameters:
$jdvalue float number of Julian Days
$calendarmodel integer either SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
Returns:
array( yearnumber, monthnumber, daynumber )

Definition at line 349 of file SMW_DI_Time.php.

References $db.

static SMWDITime::JD2Time ( jdvalue  )  [static]

Extract the time from a Julian Day number and return it as a string.

This conversion is the same for all calendar models.

Parameters:
$jdvalue float number of Julian Days
Returns:
array( hours, minutes, seconds )

Definition at line 388 of file SMW_DI_Time.php.

static SMWDITime::isLeapYear ( year,
calendarmodel 
) [static]

Find out whether the given year number is a leap year.

This calculation assumes that neither calendar has a year 0.

Parameters:
$year integer year number
$calendarmodel integer either SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
Returns:
boolean

Definition at line 406 of file SMW_DI_Time.php.

static SMWDITime::getDayNumberForMonth ( month,
year,
calendarmodel 
) [static]

Find out how many days the given month had in the given year based on the specified calendar model.

This calculation assumes that neither calendar has a year 0.

Parameters:
$month integer month number
$year integer year number
$calendarmodel integer either SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
Returns:
boolean

Definition at line 425 of file SMW_DI_Time.php.

Referenced by SMWTimeValue::getISO8601Date().


Member Data Documentation

const SMWDITime::PREC_Y = 0

const SMWDITime::PREC_YM = 1

SMWDITime::$m_daysofmonths = array ( 1 => 31, 2 => 29, 3 => 31, 4 => 30, 5 => 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 31 ) [static, protected]

Definition at line 44 of file SMW_DI_Time.php.

SMWDITime::$m_precision [protected]

Definition at line 51 of file SMW_DI_Time.php.

SMWDITime::$m_model [protected]

Definition at line 56 of file SMW_DI_Time.php.

SMWDITime::$m_year [protected]

Definition at line 61 of file SMW_DI_Time.php.

SMWDITime::$m_month [protected]

Definition at line 66 of file SMW_DI_Time.php.

SMWDITime::$m_day [protected]

Definition at line 71 of file SMW_DI_Time.php.

SMWDITime::$m_hours [protected]

Definition at line 76 of file SMW_DI_Time.php.

SMWDITime::$m_minutes [protected]

Definition at line 81 of file SMW_DI_Time.php.

SMWDITime::$m_seconds [protected]

Definition at line 86 of file SMW_DI_Time.php.


The documentation for this class was generated from the following file:

Generated on Sun Mar 18 07:15:43 2012 for Semantic MediaWiki by  doxygen 1.5.6