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

Class: Date_Span

Source Location: /Date-1.4/Date/Span.php

Class Overview


Generic time span handling class for PEAR.


Author(s):

Version:

  • $Revision: 1.4 $

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 71]
Generic time span handling class for PEAR.
  • Access: public
  • Todo: Get and set default local input and output formats?
  • Since: 1.4
  • Version: $Revision: 1.4 $
  • Author: Leandro Lucarella <mailto:llucax@php.net>


[ Top ]


Class Variables

$day =

[line 76]


Type:   int


[ Top ]

$hour =

[line 81]


Type:   int


[ Top ]

$minute =

[line 86]


Type:   int


[ Top ]

$second =

[line 91]


Type:   int


[ Top ]



Method Detail

Date_Span (Constructor)   [line 105]

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

Constructor.

Creates the time span object calling the set() 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 ]

add   [line 734]

void add( object Date_Span $time)

Adds a time span.
  • Access: public

Parameters:

object Date_Span   $time     Time span to add.

[ Top ]

compare   [line 846]

int compare( object Date_Span $time1, object Date_Span $time2)

Compares two time spans.

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
  • Static: This method can be called statically

Parameters:

object Date_Span   $time1     The first time span.
object Date_Span   $time2     The second time span.

[ Top ]

copy   [line 494]

bool copy( object Date_Span $time)

Set the time span from another time object.
  • Return: True on success.
  • Access: public

Parameters:

object Date_Span   $time     Source time span object.

[ Top ]

equal   [line 771]

bool equal( object Date_Span $time)

Tells if time span is equal to $time.
  • Return: True if the time spans are equal.
  • Access: public

Parameters:

object Date_Span   $time     Time span to compare to.

[ Top ]

format   [line 553]

string format( [string $format = null])

Time span pretty printing (similar to Date::format()).

Formats the time span in the given format, similar to strftime() and Date::format().

Formatting options:


1 %C
Days with time, same as "%D, %H:%M:%S".

1 %d
Total days as a float number (2 days, 12 hours = 2.5 days).

1 %D
Days as a decimal number.

1 %e
Total hours as a float number (1 day, 2 hours, 30 minutes = 26.5 hours).

1 %E
Total hours as a decimal number (1 day, 2 hours, 40 minutes = 26 hours).

1 %f
Total minutes as a float number (2 minutes, 30 seconds = 2.5 minutes).

1 %F
Total minutes as a decimal number (1 hour, 2 minutes, 40 seconds = 62 minutes).

1 %g
Total seconds as a decimal number (2 minutes, 30 seconds = 90 seconds).

1 %h
Hours as decimal number (0 to 23).

1 %H
Hours as decimal number (00 to 23).

1 %i
Hours as decimal number on 12-hour clock (1 to 12).

1 %I
Hours as decimal number on 12-hour clock (01 to 12).

1 %m
Minutes as a decimal number (0 to 59).

1 %M
Minutes as a decimal number (00 to 59).

1 %n
Newline character (\n).

1 %p
Either 'am' or 'pm' depending on the time.

1 %P
Either 'AM' or 'PM' depending on the time.

1 %r
Time in am/pm notation, same as "%I:%M:%S %p".

1 %R
Time in 24-hour notation, same as "%H:%M".

1 %s
Seconds as a decimal number (0 to 59).

1 %S
Seconds as a decimal number (00 to 59).

1 %t
Tab character (\t).

1 %T
Current time equivalent, same as "%H:%M:%S".

1 %%
Literal '%'.

  • Return: The time span in specified format.
  • Access: public

Parameters:

string   $format     The format string for returned time span.

[ Top ]

getDefaultFormat   [line 918]

mixed getDefaultFormat( )

Get the default format.
  • Return: Default format.
  • Static: This method can be called statically

[ Top ]

getDefaultInputFormat   [line 890]

mixed getDefaultInputFormat( )

Get the default input format.
  • Return: Default input format.
  • Static: This method can be called statically

[ Top ]

greater   [line 813]

bool greater( object Date_Span $time)

Tells if this time span is greater than $time.
  • Return: True if this time span is greater than $time.
  • Access: public

Parameters:

object Date_Span   $time     Time span to compare to.

[ Top ]

greaterEqual   [line 785]

bool greaterEqual( object Date_Span $time)

Tells if this time span is greater or equal than $time.
  • Return: True if this time span is greater or equal than $time.
  • Access: public

Parameters:

object Date_Span   $time     Time span to compare to.

[ Top ]

isEmpty   [line 862]

bool isEmpty( )

Tells if the time span is empty (zero length).
  • Return: True is it's empty.

[ Top ]

lower   [line 827]

bool lower( object Date_Span $time)

Tells if this time span is lower than $time.
  • Return: True if this time span is lower than $time.
  • Access: public

Parameters:

object Date_Span   $time     Time span to compare to.

[ Top ]

lowerEqual   [line 799]

bool lowerEqual( object Date_Span $time)

Tells if this time span is lower or equal than $time.
  • Return: True if this time span is lower or equal than $time.
  • Access: public

Parameters:

object Date_Span   $time     Time span to compare to.

[ Top ]

set   [line 129]

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 904]

mixed setDefaultFormat( mixed $format)

Set the default format.
  • Return: Previous default format.
  • Static: This method can be called statically

Parameters:

mixed   $format     New default format.

[ Top ]

setDefaultInputFormat   [line 876]

mixed setDefaultInputFormat( mixed $format)

Set the default input format.
  • Return: Previous default input format.
  • Static: This method can be called statically

Parameters:

mixed   $format     New default input format.

[ Top ]

setFromArray   [line 163]

bool setFromArray( array $time)

Set the time span from an array.

Set the time span from an array. Any value can be a float (but it has no sense in seconds), for example array(23.5, 20, 0) is interpreted as 23 hours, .5*60 + 20 = 50 minutes and 0 seconds.

  • Return: True on success.
  • Access: public

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 462]

bool setFromDateDiff( object Date $date1, object Date $date2)

Set the span from the elapsed time between two dates.

Set the span from the elapsed time between two dates. The time span is allways positive, so the date's order is not important.

  • Return: True on success.
  • Access: public

Parameters:

object Date   $date1     First Date.
object Date   $date2     Second Date.

[ Top ]

setFromDays   [line 444]

bool setFromDays( float $days)

Set the time span from a total number of days.
  • Return: True on success.
  • Access: public

Parameters:

float   $days     Total number of days.

[ Top ]

setFromHours   [line 430]

bool setFromHours( float $hours)

Set the time span from a total number of hours.
  • Return: True on success.
  • Access: public

Parameters:

float   $hours     Total number of hours.

[ Top ]

setFromMinutes   [line 416]

bool setFromMinutes( float $minutes)

Set the time span from a total number of minutes.
  • Return: True on success.
  • Access: public

Parameters:

float   $minutes     Total number of minutes.

[ Top ]

setFromSeconds   [line 391]

bool setFromSeconds( int $seconds)

Set the time span from a total number of seconds.
  • Return: True on success.
  • Access: public

Parameters:

int   $seconds     Total number of seconds.

[ Top ]

setFromString   [line 238]

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

Set the time span from a string based on an input format.

Set the time span from a string based on an input format. This is some like a mix of format() method and sscanf() PHP function. The error checking and validation of this function is very primitive, so you should be carefull when using it with unknown $time 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 setFromString('10, 20', '%H, %h') your time span would be 20 hours long. Allways remember that this method set all the values, so if you had a $time span 30 minutes long and you make $time->setFromString('20 hours', '%H hours'), $time span would be 20 hours long (and not 20 hours and 30 minutes). Input format options:


1 %C
Days with time, same as "%D, %H:%M:%S".

1 %d
Total days as a float number (2 days, 12 hours = 2.5 days).

1 %D
Days as a decimal number.

1 %e
Total hours as a float number (1 day, 2 hours, 30 minutes = 26.5 hours).

1 %f
Total minutes as a float number (2 minutes, 30 seconds = 2.5 minutes).

1 %g
Total seconds as a decimal number (2 minutes, 30 seconds = 90 seconds).

1 %h
Hours as decimal number.

1 %H
Hours as decimal number limited to 2 digits.

1 %m
Minutes as a decimal number.

1 %M
Minutes as a decimal number limited to 2 digits.

1 %n
Newline character (\n).

1 %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.

1 %r
Time in am/pm notation, same as "%H:%M:%S %p".

1 %R
Time in 24-hour notation, same as "%H:%M".

1 %s
Seconds as a decimal number.

1 %S
Seconds as a decimal number limited to 2 digits.

1 %t
Tab character (\t).

1 %T
Current time equivalent, same as "%H:%M:%S".

1 %%
Literal '%'.

  • Return: True on success.
  • Access: public

Parameters:

string   $time     String from where to get the time span information.
string   $format     Format string.

[ Top ]

subtract   [line 752]

void subtract( object Date_Span $time)

Subtracts a time span.

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).

  • Access: public

Parameters:

object Date_Span   $time     Time span to subtract.

[ Top ]

toDays   [line 721]

float toDays( )

Convert time span to days.
  • Return: Time span as a decimal number of days.
  • Access: public

[ Top ]

toHours   [line 708]

float toHours( )

Convert time span to hours.
  • Return: Time span as a decimal number of hours.
  • Access: public

[ Top ]

toMinutes   [line 695]

float toMinutes( )

Convert time span to minutes.
  • Return: Time span as a decimal number of minutes.
  • Access: public

[ Top ]

toSeconds   [line 682]

int toSeconds( )

Convert time span to seconds.
  • Return: Time span as an integer number of seconds.
  • Access: public

[ Top ]


Documentation generated on Sat, 1 May 2004 01:25:52 +0200 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.