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
Inheritance diagram for SMWDITime:
Inheritance graph
[legend]
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 ()
 
 getSha1 ()
 
 getHash ()
 
 __toString ()
 
 setOption ( $key, $value)
 
 getOption ( $key, $default=null)
 

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.
 
const TYPE_NUMBER = 1
 Data item ID for SMWDINumber.
 
const TYPE_BLOB = 2
 Data item ID for SMWDIBlob.
 
const TYPE_BOOLEAN = 4
 Data item ID for SMWDIBoolean.
 
const TYPE_URI = 5
 Data item ID for SMWDIUri.
 
const TYPE_TIME = 6
 Data item ID for SMWDITimePoint.
 
const TYPE_GEO = 7
 Data item ID for SMWDIGeoCoord.
 
const TYPE_CONTAINER = 8
 Data item ID for SMWDIContainer.
 
const TYPE_WIKIPAGE = 9
 Data item ID for SMWDIWikiPage.
 
const TYPE_CONCEPT = 10
 Data item ID for SMWDIConcept.
 
const TYPE_PROPERTY = 11
 Data item ID for SMWDIProperty.
 
const TYPE_ERROR = 12
 Data item ID for SMWDIError.
 
- 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 = [ 1 => 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

◆ __construct()

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

◆ asDateTime()

SMWDITime::asDateTime ( )
Since
2.4
Returns
DateTime

◆ doUnserialize()

static SMWDITime::doUnserialize (   $serialization)
static

Create a data item from the provided serialization string.

Returns
self

◆ getCalendarModel()

SMWDITime::getCalendarModel ( )
Since
1.6
Returns
integer

◆ getCalendarModelLiteral()

SMWDITime::getCalendarModelLiteral ( )
Since
2.4
Returns
string

◆ getDay()

SMWDITime::getDay ( )
Since
1.6
Returns
integer

◆ getDayNumberForMonth()

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

◆ getDIType()

SMWDITime::getDIType ( )
Since
1.6
Returns
integer

◆ getEra()

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

◆ getForCalendarModel()

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
self

◆ getHour()

SMWDITime::getHour ( )
Since
1.6
Returns
integer

◆ getJD()

SMWDITime::getJD ( )
Since
1.6
Returns
double

◆ getMinute()

SMWDITime::getMinute ( )
Since
1.6
Returns
integer

◆ getMonth()

SMWDITime::getMonth ( )
Since
1.6
Returns
integer

◆ getMwTimestamp()

SMWDITime::getMwTimestamp (   $outputtype = TS_UNIX)

Returns a MW timestamp representation of the value.

Since
1.6.2
Parameters
$outputtype
Returns
mixed

◆ getPrecision()

SMWDITime::getPrecision ( )
Since
1.6
Returns
integer

◆ getSecond()

SMWDITime::getSecond ( )
Since
1.6
Returns
integer

◆ getSerialization()

SMWDITime::getSerialization ( )
Since
1.6
Returns
string

◆ getSortKey()

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

◆ getTimezone()

SMWDITime::getTimezone ( )
Since
2.5
Returns
integer

◆ getYear()

SMWDITime::getYear ( )
Since
1.6
Returns
integer

◆ isLeapYear()

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

◆ newFromDateTime()

static SMWDITime::newFromDateTime ( DateTime  $dateTime)
static
Since
2.4
Parameters
DateTime$dateTime
Returns
self
Exceptions
DataItemException

◆ newFromJD()

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
self

◆ newFromTimestamp()

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
self|false

Member Data Documentation

◆ PREHISTORY

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:

About | General disclaimer | Privacy policy