Class Unit
Constants and static methods for time units.
Methods summary
public static
string
|
#
symbol( string $unit )
Parameters
Returns
string A one-character representation of the unit.
Throws
|
public static
string
|
#
forSymbol( string $symbol )
Parameters
- $symbol
- one-character representation of a unit.
Returns
string The unit associated with the symbol.
Throws
|
public static
string
|
#
displayName( string $unit, DateTime $dt )
Formats a DateTime depending on the unit.
Formats a DateTime depending on the unit.
Parameters
Returns
string
Throws
|
public static
DateTime
|
#
add( DateTime $dt, integer $amount, string $unit )
Moves a DateTime {@code $amount} units in time.
Moves a DateTime {@code $amount} units in time.
Use a positive amount to move forward and a negative amount to move backwards.
Parameters
- $dt
- $amount
- number of units to move.
- $unit
- unit. Must be one of the constants in Unit.
Returns
|
public static
DateTime
|
#
floor( DateTime $dt, string $unit, string $firstDayOfWeek = 'Mon' )
Returns a new DateTime moved back in time to the closest whole unit.
Returns a new DateTime moved back in time to the closest whole unit.
Parameters
- $dt
- DateTime to floor.
- $unit
- unit. Must be one of the constants in Unit.
- $firstDayOfWeek
- english three letter abbreviation for the first day of the week, e.g. 'Mon' or 'Sun'. Only needed when unit is WEEK.
Returns
Throws
|
public static
DateTime
|
#
ceil( DateTime $dt, string $unit, string $firstDayOfWeek = 'Mon' )
Returns a new DateTime moved forward in time to the closest whole unit.
Returns a new DateTime moved forward in time to the closest whole unit.
Will not change the DateTime if the time is already ceiled.
Parameters
- $dt
- DateTime to ceil.
- $unit
- unit. Must be one of the constants in Unit.
- $firstDayOfWeek
- english three letter abbreviation for the first day of the week, e.g. 'Mon' or 'Sun'. Only needed when unit is WEEK.
Returns
|
public static
DateTime
|
#
round( DateTime $dt, string $unit, string $firstDayOfWeek = 'Mon' )
Returns a new DateTime moved to the closest whole unit.
Returns a new DateTime moved to the closest whole unit.
Will not change the DateTime if the time is already at the start of a unit.
Parameters
- $dt
- DateTime to ceil.
- $unit
- unit. Must be one of the constants in Unit.
- $firstDayOfWeek
- english three letter abbreviation for the first day of the week, e.g. 'Mon' or 'Sun'. Only needed when unit is WEEK.
Returns
|