Date
[ class tree: Date ] [ index: Date ] [ all elements ]

Class: Date_Span

Source Location: /Date-1.5.0a4/Date/Span.php

Class Overview


Generic time span handling class for PEAR


Author(s):

Version:

  • Release: 1.5.0a1

Copyright:

  • 1997-2006 Leandro Lucarella, Pierre-Alain Joye

Methods


Inherited Variables

Inherited Methods


Class Details

[line 120]
Generic time span handling class for PEAR


[ Top ]


Method Detail

Date_Span (Constructor)   [line 177]

Date_Span Date_Span( [mixed $time = 0], [mixed $format = null])

Constructor

Creates the time span object calling Date_Span::set()


Parameters:

mixed   $time   —  time span expression
mixed   $format   —  format string to set it from a string or the second date set it from a date diff

[ Top ]

add   [line 906]

void add( object $time)

Adds a time span

Parameters:

object   $time   —  time span to add

[ Top ]

compare   [line 1050]

int compare( object $time1, object $time2)

Compares two time spans

Suitable for use in sorting functions.

  • Return: 0 if the time spans are equal, -1 if time1 is lower than time2, 1 if time1 is greater than time2
  • Access: public

Parameters:

object   $time1   —  the first time span
object   $time2   —  the second time span

[ Top ]

copy   [line 644]

bool copy( object $time)

Sets the time span from another time object
  • Return: true on success
  • Access: public

Parameters:

object   $time   —  source time span object

[ Top ]

equal   [line 952]

bool equal( object $time)

Tells if time span is equal to $time

Parameters:

object   $time   —  time span to compare to

[ Top ]

format   [line 707]

string format( [string $format = null])

Formats time span according to specified code (similar to Date::formatLikeStrftime())

Uses a code based on strftime().

Formatting options:

  • %C - Days with time, equivalent to '%D, %H:%M:%S'
  • %d - Total days as a float number (2 days, 12 hours = 2.5 days)
  • %D - Days as a decimal number
  • %e - Total hours as a float number (1 day, 2 hours, 30 minutes = 26.5 hours)
  • %E - Total hours as a decimal number (1 day, 2 hours, 40 minutes = 26 hours)
  • %f - Total minutes as a float number (2 minutes, 30 seconds = 2.5 minutes)
  • %F - Total minutes as a decimal number (1 hour, 2 minutes, 40 seconds = 62 minutes)
  • %g - Total seconds as a decimal number (2 minutes, 30 seconds = 90 seconds)
  • %h - Hours as decimal number (0 to 23)
  • %H - Hours as decimal number (00 to 23)
  • %i - Hours as decimal number on 12-hour clock (1 to 12)
  • %I - Hours as decimal number on 12-hour clock (01 to 12)
  • %m - Minutes as a decimal number (0 to 59)
  • %M - Minutes as a decimal number (00 to 59)
  • %n - Newline character (\n)
  • %p - Either 'am' or 'pm' depending on the time
  • %P - Either 'AM' or 'PM' depending on the time
  • %r - Time in am/pm notation, equivalent to '%I:%M:%S %p'
  • %R - Time in 24-hour notation, equivalent to '%H:%M'
  • %s - Seconds as a decimal number (0 to 59)
  • %S - Seconds as a decimal number (00 to 59)
  • %t - Tab character (\t)
  • %T - Current time equivalent, equivalent to '%H:%M:%S'
  • %% - Literal '%'

  • Return: the time span in specified format
  • Access: public

Parameters:

string   $format   —  the format string for returned time span

[ Top ]

getDefaultFormat   [line 1147]

mixed getDefaultFormat( )

Returns the default format

[ Top ]

getDefaultInputFormat   [line 1109]

mixed getDefaultInputFormat( )

Returns the default input format

[ Top ]

greater   [line 1009]

bool greater( object $time)

Tells if this time span is greater than $time

Parameters:

object   $time   —  time span to compare to

[ Top ]

greaterEqual   [line 971]

bool greaterEqual( object $time)

Tells if this time span is greater or equal than $time

Parameters:

object   $time   —  time span to compare to

[ Top ]

isEmpty   [line 1071]

bool isEmpty( )

Tells if the time span is empty (zero length)
  • Return: true if empty
  • Access: public

[ Top ]

lower   [line 1028]

bool lower( object $time)

Tells if this time span is lower than $time

Parameters:

object   $time   —  time span to compare to

[ Top ]

lowerEqual   [line 990]

bool lowerEqual( object $time)

Tells if this time span is lower or equal than $time

Parameters:

object   $time   —  time span to compare to

[ Top ]

set   [line 202]

bool set( [mixed $time = 0], [mixed $format = null])

Set the time span to a new value in a 'smart' way

Sets the time span depending on the argument types, calling to the appropriate setFromXxx() method.


Parameters:

mixed   $time   —  time span expression
mixed   $format   —  format string to set it from a string or the second date set it from a date diff

[ Top ]

setDefaultFormat   [line 1128]

mixed setDefaultFormat( mixed $format)

Sets the default format

Parameters:

mixed   $format   —  new default format

[ Top ]

setDefaultInputFormat   [line 1090]

mixed setDefaultInputFormat( mixed $format)

Sets the default input format

Parameters:

mixed   $format   —  new default input format

[ Top ]

setFromArray   [line 242]

bool setFromArray( array $time)

Set the time span from an array

Any value can be a float (but it has no sense in seconds), for example:

  1. $object->setFromArray(array(23.5200));

is interpreted as 23 hours, 0.5 * 60 + 20 = 50 minutes and 0 seconds.


Parameters:

array   $time   —  items are counted from right to left. First item is for seconds, second for minutes, third for hours and fourth for days. If there are less items than 4, zero (0) is assumed for the absent values.

[ Top ]

setFromDateDiff   [line 596]

bool setFromDateDiff( object $date1, object $date2)

Sets the span from the elapsed time between two dates

The time span is unsigned, so the date's order is not important.


Parameters:

object   $date1   —  first Date
object   $date2   —  second Date

[ Top ]

setFromDays   [line 575]

bool setFromDays( float $days)

Sets the time span from a total number of days

Parameters:

float   $days   —  total number of days

[ Top ]

setFromHours   [line 556]

bool setFromHours( float $hours)

Sets the time span from a total number of hours

Parameters:

float   $hours   —  total number of hours

[ Top ]

setFromMinutes   [line 537]

bool setFromMinutes( float $minutes)

Sets the time span from a total number of minutes

Parameters:

float   $minutes   —  total number of minutes

[ Top ]

setFromSeconds   [line 506]

bool setFromSeconds( int $seconds)

Set the time span from a total number of seconds

Parameters:

int   $seconds   —  total number of seconds

[ Top ]

setFromString   [line 331]

bool setFromString( string $time, [string $format = null])

Sets the time span from a string, based on an input format

This is some like a mix of the PHP functions strftime() and sscanf(). The error checking and validation of this function is very primitive, so you should be careful when using it with unknown strings. With this method you are assigning day, hour, minute and second values, and the last values are used. This means that if you use something like:

  1. $object->setFromString('10, 20''%H, %h');

your time span would be 20 hours long. Always remember that this method sets all the values, so if you had a span object 30 minutes long and you call:

  1. $object->setFromString('20 hours''%H hours');

the span object would be 20 hours long (and not 20 hours and 30 minutes).

Input format options:

  • %C - Days with time, equivalent to 'D, %H:%M:%S'
  • %d - Total days as a float number (2 days, 12 hours = 2.5 days)
  • %D - Days as a decimal number
  • %e - Total hours as a float number (1 day, 2 hours, 30 minutes = 26.5 hours)
  • %f - Total minutes as a float number (2 minutes, 30 seconds = 2.5 minutes)
  • %g - Total seconds as a decimal number (2 minutes, 30 seconds = 90 seconds)
  • %h - Hours as decimal number
  • %H - Hours as decimal number limited to 2 digits
  • %m - Minutes as a decimal number
  • %M - Minutes as a decimal number limited to 2 digits
  • %n - Newline character (\n)
  • %p - Either 'am' or 'pm' depending on the time. If 'pm' is detected it adds 12 hours to the resulting time span (without any checks). This is case insensitive.
  • %r - Time in am/pm notation, equivalent to 'H:%M:%S %p'
  • %R - Time in 24-hour notation, equivalent to 'H:%M'
  • %s - Seconds as a decimal number
  • %S - Seconds as a decimal number limited to 2 digits
  • %t - Tab character (\t)
  • %T - Current time equivalent, equivalent to 'H:%M:%S'
  • %% - Literal '%'


Parameters:

string   $time   —  string from where to get the time span information
string   $format   —  format string

[ Top ]

subtract   [line 928]

void subtract( object $time)

Subtracts a time span

If the time span to subtract is larger than the original, the result is zero (there's no sense in negative time spans).


Parameters:

object   $time   —  time span to subtract

[ Top ]

toDays   [line 887]

float toDays( )

Converts time span to days

[ Top ]

toHours   [line 869]

float toHours( )

Converts time span to hours

[ Top ]

toMinutes   [line 851]

float toMinutes( )

Converts time span to minutes

[ Top ]

toSeconds   [line 833]

int toSeconds( )

Converts time span to seconds

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:55:01 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.