CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.10 Red Velvet API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.10
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Class RelativeTimeFormatter

Helper class for formatting relative dates & times.

Namespace: Cake\I18n

Method Summary

  • _diffData() protected

    Calculate the data needed to format a relative difference string.

  • _options() protected

    Build the options for relative date formatting.

  • dateAgoInWords() public

    Format a into a relative date string.

  • diffForHumans() public

    Get the difference in a human readable format.

  • timeAgoInWords() public

    Format a into a relative timestring.

Method Detail

_diffData() ¶ protected

_diffData(int|string $futureTime, int|string $pastTime, bool $backwards, array $options): array

Calculate the data needed to format a relative difference string.

Parameters
int|string $futureTime

The timestamp from the future.

int|string $pastTime

The timestamp from the past.

bool $backwards

Whether or not the difference was backwards.

array $options

An array of options.

Returns
array

_options() ¶ protected

_options(array $options, string $class): array

Build the options for relative date formatting.

Parameters
array $options

The options provided by the user.

string $class

The class name to use for defaults.

Returns
array

dateAgoInWords() ¶ public

dateAgoInWords(DateTimeInterface $date, array $options = []): string

Format a into a relative date string.

Parameters
DateTimeInterface $date

The date to format.

array $options optional

Array of options.

Returns
string
See Also
\Cake\I18n\Date::timeAgoInWords()

diffForHumans() ¶ public

diffForHumans(Cake\Chronos\ChronosInterface $date, Cake\Chronos\ChronosInterface|null $other = null, bool $absolute = false): string

Get the difference in a human readable format.

Parameters
Cake\Chronos\ChronosInterface $date

The datetime to start with.

Cake\Chronos\ChronosInterface|null $other optional

The datetime to compare against.

bool $absolute optional

removes time difference modifiers ago, after, etc

Returns
string
See Also
\Cake\Chronos\ChronosInterface::diffForHumans

timeAgoInWords() ¶ public

timeAgoInWords(DateTimeInterface $time, array $options = []): string

Format a into a relative timestring.

Parameters
DateTimeInterface $time

The time instance to format.

array $options optional

Array of options.

Returns
string
See Also
\Cake\I18n\Time::timeAgoInWords()
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs