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

Class: Date_HumanDiff

Source Location: /Date_HumanDiff-0.5.0/src/Date/HumanDiff.php

Class Overview


Generate textual time differences that are easily understandable by humans.


Author(s):

Version:

  • Release: @package_version@

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 31]
Generate textual time differences that are easily understandable by humans.

The class supports minutes, hours, days, weeks, months and years.

Examples:

  • 5 seconds ago -> "just now"
  • 65 seconds ago -> "a minute ago"
  • 120 seconds ago -> "2 minutes ago"



[ Top ]


Class Variables

$DAY =  86400

[line 35]


Type:   mixed


[ Top ]

$formats =

[line 50]

Array of possible time difference display formats.

Each value is an array with the following values:

  • max. time difference
  • textual description
  • number to divide the time difference by

  • Access: protected

Type:   array


[ Top ]

$HOUR =  3600

[line 34]


Type:   mixed


[ Top ]

$MINUTE =  60

[line 33]


Type:   mixed


[ Top ]

$MONTH =  2628000

[line 37]


Type:   mixed


[ Top ]

$translator =

[line 58]

Translation object.

Provides translations for time strings

  • Access: protected

Type:   Date_HumanDiff_Lang


[ Top ]

$WEEK =  604800

[line 36]


Type:   mixed


[ Top ]

$YEAR =  31536000

[line 38]


Type:   mixed


[ Top ]



Method Detail

__construct (Constructor)   [line 65]

Date_HumanDiff __construct( )

Create new instance, initialize $formats array
  • Access: public

[ Top ]

addFormat   [line 153]

void addFormat( integer $timeDiff, string $text, integer $divider, [boolean $sort = true])

Adds a new format to the list of time formats.
  • Access: public

Parameters:

integer   $timeDiff     Maximum time difference between reference time and given time in seconds.
string   $text     Text to show when the format is used
integer   $divider     Number to divide time difference by
boolean   $sort     Sort formats. Don't use this if you add many formats but call sortFormats() manually afterwards.

[ Top ]

clearFormats   [line 166]

void clearFormats( )

Delete all existing formats.
  • Access: public

[ Top ]

get   [line 108]

string get( int|DateTime $timestamp, [int|DateTime $reference = null])

Generate a human readable time difference.
  • Return: Human readable time difference ("a week ago")
  • Access: public

Parameters:

int|DateTime   $timestamp     Timestamp to get difference to
int|DateTime   $reference     Reference timestamp to get difference from. If omitted, it's set to the current time.

[ Top ]

getTranslation   [line 228]

string getTranslation( string $string, integer $number)

Get the translation for the given string.
  • Return: Translated string. Original string when no translation exists.
  • Access: protected

Parameters:

string   $string     String to translate
integer   $number     Number to render into the string

[ Top ]

makeTimestamp   [line 207]

integer makeTimestamp( mixed $something)

Convert given variable to a unix timestamp.

Supported formats:

  • DateTime object
  • unix timestamps
  • Strings that can be converted with strtotime

  • Return: Unix timestamp
  • Access: protected

Parameters:

mixed   $something     Some variable

[ Top ]

setLocale   [line 260]

boolean setLocale( string $lang)

Set the locale to use.

Supported formats:

  • 2-letter ISO code ("de", "fr")
  • locale name with and without encoding ("de_AT", "fr_FR.utf8")

  • Return: True if the translations could be loaded, false if not.
  • Access: public

Parameters:

string   $lang     Language name

[ Top ]

setTranslator   [line 244]

void setTranslator( Date_HumanDiff_Locale $translator)

Set the object that's used to translate time strings
  • Access: public

Parameters:

object   $translator     Language translation object

[ Top ]

sortFormatCompare   [line 189]

integer sortFormatCompare( array $a, array $b)

Comparision function for usort()
  • Return: <, = or > 0 - when $a is less, equal or greater than $b
  • Access: public

Parameters:

array   $a     First comparator
array   $b     Second comparator

[ Top ]

sortFormats   [line 176]

void sortFormats( )

Sort all formats by their time difference
  • Access: public

[ Top ]


Documentation generated on Sun, 23 Mar 2014 13:30:03 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.