Class Date_Span

Description

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 <llucax@php.net>

Located in /maintenance/libraries/pear/Date/Span.php (line 71)


	
			
Variable Summary
 int $day
 int $hour
 int $minute
 int $second
Method Summary
 Date_Span Date_Span (mixed $time, [mixed $format = null])
 void add (object Date_Span $time)
 int compare (object Date_Span $time1, object Date_Span $time2)
 bool copy (object Date_Span $time)
 bool equal (object Date_Span $time)
 string format ([string $format = null])
 mixed getDefaultFormat ()
 bool greater (object Date_Span $time)
 bool isEmpty ()
 bool lower (object Date_Span $time)
 bool set (mixed $time, [mixed $format = null])
 mixed setDefaultFormat (mixed $format)
 mixed setDefaultInputFormat (mixed $format)
 bool setFromArray (array $time)
 bool setFromDateDiff (object Date $date1, object Date $date2)
 bool setFromDays (float $days)
 bool setFromHours (float $hours)
 bool setFromMinutes (float $minutes)
 bool setFromSeconds (int $seconds)
 bool setFromString (string $time, [string $format = null])
 void subtract (object Date_Span $time)
 float toDays ()
 float toHours ()
 float toMinutes ()
 int toSeconds ()
Variables
int $day (line 76)
int $hour (line 81)
int $minute (line 86)
int $second (line 91)
Methods
Constructor Date_Span (line 105)

Constructor.

Creates the time span object calling the set() method.

Date_Span Date_Span (mixed $time, [mixed $format = null])
  • 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.
add (line 734)

Adds a time span.

  • access: public
void add (object Date_Span $time)
compare (line 846)

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:
int compare (object Date_Span $time1, object Date_Span $time2)
copy (line 494)

Set the time span from another time object.

  • return: True on success.
  • access: public
bool copy (object Date_Span $time)
equal (line 771)

Tells if time span is equal to $time.

  • return: True if the time spans are equal.
  • access: public
bool equal (object Date_Span $time)
format (line 553)

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
string format ([string $format = null])
  • string $format: The format string for returned time span.
getDefaultFormat (line 918)

Get the default format.

  • return: Default format.
  • static:
mixed getDefaultFormat ()
getDefaultInputFormat (line 890)

Get the default input format.

  • return: Default input format.
  • static:
mixed getDefaultInputFormat ()
greater (line 813)

Tells if this time span is greater than $time.

  • return: True if this time span is greater than $time.
  • access: public
bool greater (object Date_Span $time)
greaterEqual (line 785)

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
bool greaterEqual (object Date_Span $time)
isEmpty (line 862)

Tells if the time span is empty (zero length).

  • return: True is it's empty.
bool isEmpty ()
lower (line 827)

Tells if this time span is lower than $time.

  • return: True if this time span is lower than $time.
  • access: public
bool lower (object Date_Span $time)
lowerEqual (line 799)

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
bool lowerEqual (object Date_Span $time)
set (line 129)

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.

bool set (mixed $time, [mixed $format = null])
  • 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.
setDefaultFormat (line 904)

Set the default format.

  • return: Previous default format.
  • static:
mixed setDefaultFormat (mixed $format)
  • mixed $format: New default format.
setDefaultInputFormat (line 876)

Set the default input format.

  • return: Previous default input format.
  • static:
mixed setDefaultInputFormat (mixed $format)
  • mixed $format: New default input format.
setFromArray (line 163)

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
bool setFromArray (array $time)
  • 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.
setFromDateDiff (line 462)

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
bool setFromDateDiff (object Date $date1, object Date $date2)
setFromDays (line 444)

Set the time span from a total number of days.

  • return: True on success.
  • access: public
bool setFromDays (float $days)
  • float $days: Total number of days.
setFromHours (line 430)

Set the time span from a total number of hours.

  • return: True on success.
  • access: public
bool setFromHours (float $hours)
  • float $hours: Total number of hours.
setFromMinutes (line 416)

Set the time span from a total number of minutes.

  • return: True on success.
  • access: public
bool setFromMinutes (float $minutes)
  • float $minutes: Total number of minutes.
setFromSeconds (line 391)

Set the time span from a total number of seconds.

  • return: True on success.
  • access: public
bool setFromSeconds (int $seconds)
  • int $seconds: Total number of seconds.
setFromString (line 238)

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
bool setFromString (string $time, [string $format = null])
  • string $time: String from where to get the time span information.
  • string $format: Format string.
subtract (line 752)

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
void subtract (object Date_Span $time)
toDays (line 721)

Convert time span to days.

  • return: Time span as a decimal number of days.
  • access: public
float toDays ()
toHours (line 708)

Convert time span to hours.

  • return: Time span as a decimal number of hours.
  • access: public
float toHours ()
toMinutes (line 695)

Convert time span to minutes.

  • return: Time span as a decimal number of minutes.
  • access: public
float toMinutes ()
toSeconds (line 682)

Convert time span to seconds.

  • return: Time span as an integer number of seconds.
  • access: public
int toSeconds ()
__clone (line 928)

Returns a copy of the object (workarround for PHP5 forward compatibility).

  • return: Copy of the object.
object Date_Span __clone ()

Documentation generated on Fri, 24 Dec 2004 13:03:26 +0000 by phpDocumentor 1.3.0RC3