Semantic MediaWiki and related extensions
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | Static Protected Attributes | List of all members
SMWDITime Class Reference
Collaboration diagram for SMWDITime:
Collaboration graph
[legend]

Public Member Functions

 __construct ($calendarmodel, $year, $month=false, $day=false, $hour=false, $minute=false, $second=false, $timezone=false)
 
 getDIType ()
 
 getCalendarModel ()
 
 getTimezone ()
 
 getPrecision ()
 
 getEra ()
 
 getYear ()
 
 getMonth ()
 
 getDay ()
 
 getHour ()
 
 getMinute ()
 
 getSecond ()
 
 getCalendarModelLiteral ()
 
 asDateTime ()
 
 getMwTimestamp ($outputtype=TS_UNIX)
 
 getForCalendarModel ($calendarmodel)
 
 getSortKey ()
 
 getJD ()
 
 getSerialization ()
 
 equals (SMWDataItem $di)
 
- Public Member Functions inherited from SMWDataItem
 getDIType ()
 
 getSortKey ()
 
 equals (SMWDataItem $di)
 
 getSortKeyDataItem ()
 
 getSerialization ()
 
 getHash ()
 
 __toString ()
 
 setOption ($key, $value)
 
 getOption ($key)
 

Static Public Member Functions

static newFromDateTime (DateTime $dateTime)
 
static newFromTimestamp ($timestamp)
 
static doUnserialize ($serialization)
 
static newFromJD ($jdValue, $calendarModel=null, $precision=null, $timezone=false)
 
static isLeapYear ($year, $calendarmodel)
 
static getDayNumberForMonth ($month, $year, $calendarmodel)
 
- Static Public Member Functions inherited from SMWDataItem
static newFromSerialization ($diType, $serialization)
 
static getDataItemClassNameForId ($diType)
 

Public Attributes

const PREC_Y = SMW_PREC_Y
 
const PREC_YM = SMW_PREC_YM
 
const PREC_YMD = SMW_PREC_YMD
 
const PREC_YMDT = SMW_PREC_YMDT
 
const PREHISTORY = -10000
 
- Public Attributes inherited from SMWDataItem
const TYPE_NOTYPE = 0
 Data item ID that can be used to indicate that no data item class is appropriate. More...
 
const TYPE_NUMBER = 1
 Data item ID for SMWDINumber. More...
 
const TYPE_STRING = 2
 
const TYPE_BLOB = 2
 Data item ID for SMWDIBlob. More...
 
const TYPE_BOOLEAN = 4
 Data item ID for SMWDIBoolean. More...
 
const TYPE_URI = 5
 Data item ID for SMWDIUri. More...
 
const TYPE_TIME = 6
 Data item ID for SMWDITimePoint. More...
 
const TYPE_GEO = 7
 Data item ID for SMWDIGeoCoord. More...
 
const TYPE_CONTAINER = 8
 Data item ID for SMWDIContainer. More...
 
const TYPE_WIKIPAGE = 9
 Data item ID for SMWDIWikiPage. More...
 
const TYPE_CONCEPT = 10
 Data item ID for SMWDIConcept. More...
 
const TYPE_PROPERTY = 11
 Data item ID for SMWDIProperty. More...
 
const TYPE_ERROR = 12
 Data item ID for SMWDIError. More...
 
- Public Attributes inherited from SMW\DataValues\Time\CalendarModel
const CM_GREGORIAN = 1
 
const CM_JULIAN = 2
 

Protected Attributes

 $m_precision
 
 $m_model
 
 $m_year
 
 $m_month
 
 $m_day
 
 $m_hours
 
 $m_minutes
 
 $m_seconds
 
 $timezone
 
 $era = null
 
 $julianDay = null
 

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

Constructor & Destructor Documentation

SMWDITime::__construct (   $calendarmodel,
  $year,
  $month = false,
  $day = false,
  $hour = false,
  $minute = false,
  $second = false,
  $timezone = 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
$calendarmodelinteger one of SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
$yearinteger number of the year (possibly negative)
$monthmixed integer number or false
$daymixed integer number or false
$hourmixed integer number or false
$minutemixed integer number or false
$secondmixed integer number or false
integer | false$timezone
Todo:
Implement more validation here.

Member Function Documentation

SMWDITime::asDateTime ( )
Since
2.4
Returns
DateTime
static SMWDITime::doUnserialize (   $serialization)
static

Create a data item from the provided serialization string.

Returns
SMWDITime
SMWDITime::equals ( SMWDataItem  $di)
SMWDITime::getCalendarModel ( )
Since
1.6
Returns
integer
SMWDITime::getCalendarModelLiteral ( )
Since
2.4
Returns
string
SMWDITime::getDay ( )
Since
1.6
Returns
integer
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
$monthinteger month number
$yearinteger year number
$calendarmodelinteger either SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
Returns
boolean
SMWDITime::getDIType ( )
Since
1.6
Returns
integer
SMWDITime::getEra ( )

Indicates whether a user explicitly used an era marker even for a positive year.

  • [-1] indicates BC(E)
  • [0]/null indicates no era marker
  • [1] indicates AD/CE was used
Since
2.4
Returns
integer
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
$calendarmodelinteger one of SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
Returns
SMWDITime
SMWDITime::getHour ( )
Since
1.6
Returns
integer
SMWDITime::getJD ( )
Since
1.6
Returns
double
SMWDITime::getMinute ( )
Since
1.6
Returns
integer
SMWDITime::getMonth ( )
Since
1.6
Returns
integer
SMWDITime::getMwTimestamp (   $outputtype = TS_UNIX)

Returns a MW timestamp representation of the value.

Since
1.6.2
Parameters
$outputtype
Returns
mixed
SMWDITime::getPrecision ( )
Since
1.6
Returns
integer
SMWDITime::getSecond ( )
Since
1.6
Returns
integer
SMWDITime::getSerialization ( )
Since
1.6
Returns
string
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
SMWDITime::getTimezone ( )
Since
2.5
Returns
integer
SMWDITime::getYear ( )
Since
1.6
Returns
integer
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
$yearinteger year number
$calendarmodelinteger either SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
Returns
boolean
static SMWDITime::newFromDateTime ( DateTime  $dateTime)
static
Since
2.4
Parameters
DateTime$dateTime
Returns
SMWDITime|false
static SMWDITime::newFromJD (   $jdValue,
  $calendarModel = null,
  $precision = null,
  $timezone = false 
)
static

Create a new time dataItem from a specified Julian Day number, calendar model, presicion.

Parameters
double$jdValue
integer | null$calendarmodel
integer | null$precision
Returns
DITime object
static SMWDITime::newFromTimestamp (   $timestamp)
static

Creates and returns a new instance of SMWDITime from a MW timestamp.

Since
1.8
Parameters
string$timestampmust be in format
Returns
SMWDITime|false

Member Data Documentation

SMWDITime::$era = null
protected
SMWDITime::$julianDay = null
protected
SMWDITime::$m_day
protected
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 )
staticprotected
SMWDITime::$m_hours
protected
SMWDITime::$m_minutes
protected
SMWDITime::$m_model
protected
SMWDITime::$m_month
protected
SMWDITime::$m_precision
protected
SMWDITime::$m_seconds
protected
SMWDITime::$m_year
protected
SMWDITime::$timezone
protected
const SMWDITime::PREC_Y = SMW_PREC_Y
const SMWDITime::PREC_YM = SMW_PREC_YM
const SMWDITime::PREC_YMD = SMW_PREC_YMD
const SMWDITime::PREC_YMDT = SMW_PREC_YMDT
const SMWDITime::PREHISTORY = -10000

The year before which we do not accept anything but year numbers and largely discourage calendar models.


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