[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/data/Date/ -> Span.class.php (sommaire)

Non Numeric Separated Values (NNSV) Input Format. Input format guessed from something like this: days<sep>hours<sep>minutes<sep>seconds Where <sep> is any quantity of non numeric chars. If no values are given, time span is set to zero, if one value is given, it's used for hours, if two values are given it's used for hours and minutes and if three values are given, it's used for hours, minutes and seconds.<br> Examples:<br> ''                   -> 0, 0, 0, 0 (days, hours, minutes, seconds)<br> '12'                 -> 0, 12, 0, 0 '12.30'              -> 0, 12, 30, 0<br> '12:30:18'           -> 0, 12, 30, 18<br> '3-12-30-18'         -> 3, 12, 30, 18<br> '3 days, 12-30-18'   -> 3, 12, 30, 18<br> '12:30 with 18 secs' -> 0, 12, 30, 18<br>

Poids: 939 lignes (31 kb)
Inclus ou requis:0 fois
Référencé: 1 fois
Nécessite: 0 fichiers

Définit 1 class

Date_Span:: (28 méthodes):
  Date_Span()
  set()
  setFromArray()
  setFromString()
  setFromSeconds()
  setFromMinutes()
  setFromHours()
  setFromDays()
  copy()
  format()
  toSeconds()
  toMinutes()
  toHours()
  toDays()
  add()
  subtract()
  equal()
  greaterEqual()
  lowerEqual()
  greater()
  lower()
  compare()
  isEmpty()
  setDefaultInputFormat()
  getDefaultInputFormat()
  setDefaultFormat()
  getDefaultFormat()
  __clone()


Classe: Date_Span  - X-Ref

\ingroup Data

Generic time span handling class for PEAR.

Date_Span($time = 0, $format = null)   X-Ref
Constructor.

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

param: mixed $time   Time span expression.
param: mixed $format Format string to set it from a string or the

set($time = 0, $format = null)   X-Ref
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.

param: mixed $time   Time span expression.
param: mixed $format Format string to set it from a string or the
return: bool  true on success.

setFromArray($time)   X-Ref
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.

param: array $time Items are counted from right to left. First
return: bool  True on success.

setFromString($time, $format = null)   X-Ref
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
<b>all</b> 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:<br>
<code>%C</code> Days with time, same as "%D, %H:%M:%S".<br>
<code>%d</code> Total days as a float number
(2 days, 12 hours = 2.5 days).<br>
<code>%D</code> Days as a decimal number.<br>
<code>%e</code> Total hours as a float number
(1 day, 2 hours, 30 minutes = 26.5 hours).<br>
<code>%f</code> Total minutes as a float number
(2 minutes, 30 seconds = 2.5 minutes).<br>
<code>%g</code> Total seconds as a decimal number
(2 minutes, 30 seconds = 90 seconds).<br>
<code>%h</code> Hours as decimal number.<br>
<code>%H</code> Hours as decimal number limited to 2 digits.<br>
<code>%m</code> Minutes as a decimal number.<br>
<code>%M</code> Minutes as a decimal number limited to 2 digits.<br>
<code>%n</code> Newline character (\n).<br>
<code>%p</code> 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.<br>
<code>%r</code> Time in am/pm notation, same as "%H:%M:%S %p".<br>
<code>%R</code> Time in 24-hour notation, same as "%H:%M".<br>
<code>%s</code> Seconds as a decimal number.<br>
<code>%S</code> Seconds as a decimal number limited to 2 digits.<br>
<code>%t</code> Tab character (\t).<br>
<code>%T</code> Current time equivalent, same as "%H:%M:%S".<br>
<code>%%</code> Literal '%'.<br>

param: string $time   String from where to get the time span
param: string $format Format string.
return: bool   True on success.

setFromSeconds($seconds)   X-Ref
Set the time span from a total number of seconds.

param: int  $seconds Total number of seconds.
return: bool True on success.

setFromMinutes($minutes)   X-Ref
Set the time span from a total number of minutes.

param: float $minutes Total number of minutes.
return: bool  True on success.

setFromHours($hours)   X-Ref
Set the time span from a total number of hours.

param: float $hours Total number of hours.
return: bool  True on success.

setFromDays($days)   X-Ref
Set the time span from a total number of days.

param: float $days Total number of days.
return: bool  True on success.

copy($time)   X-Ref
Set the time span from another time object.

param: object Date_Span $time Source time span object.
return: bool   True on success.

format($format = null)   X-Ref
Time span pretty printing (similar to Date::format()).

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

param: string $format The format string for returned time span.
return: string The time span in specified format.

toSeconds()   X-Ref
Convert time span to seconds.

return: int Time span as an integer number of seconds.

toMinutes()   X-Ref
Convert time span to minutes.

return: float Time span as a decimal number of minutes.

toHours()   X-Ref
Convert time span to hours.

return: float Time span as a decimal number of hours.

toDays()   X-Ref
Convert time span to days.

return: float Time span as a decimal number of days.

add($time)   X-Ref
Adds a time span.

param: object Date_Span $time Time span to add.

subtract($time)   X-Ref
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).

param: object Date_Span $time Time span to subtract.

equal($time)   X-Ref
Tells if time span is equal to $time.

param: object Date_Span $time Time span to compare to.
return: bool   True if the time spans are equal.

greaterEqual($time)   X-Ref
Tells if this time span is greater or equal than $time.

param: object Date_Span $time Time span to compare to.
return: bool   True if this time span is greater or equal than $time.

lowerEqual($time)   X-Ref
Tells if this time span is lower or equal than $time.

param: object Date_Span $time Time span to compare to.
return: bool   True if this time span is lower or equal than $time.

greater($time)   X-Ref
Tells if this time span is greater than $time.

param: object Date_Span $time Time span to compare to.
return: bool   True if this time span is greater than $time.

lower($time)   X-Ref
Tells if this time span is lower than $time.

param: object Date_Span $time Time span to compare to.
return: bool   True if this time span is lower than $time.

compare($time1, $time2)   X-Ref
Compares two time spans.

Compares two time spans. Suitable for use in sorting functions.

param: object Date_Span $time1 The first time span.
param: object Date_Span $time2 The second time span.
return: int    0 if the time spans are equal, -1 if time1 is lower

isEmpty()   X-Ref
Tells if the time span is empty (zero length).

return: bool True is it's empty.

setDefaultInputFormat($format)   X-Ref
Set the default input format.

param: mixed $format New default input format.
return: mixed Previous default input format.

getDefaultInputFormat()   X-Ref
Get the default input format.

return: mixed Default input format.

setDefaultFormat($format)   X-Ref
Set the default format.

param: mixed $format New default format.
return: mixed Previous default format.

getDefaultFormat()   X-Ref
Get the default format.

return: mixed Default format.

__clone()   X-Ref
Returns a copy of the object (workarround for PHP5 forward compatibility).

return: object Date_Span Copy of the object.



Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics