Moodle PHP Documentation 5.0
Moodle 5.0.1+ (Build: 20250711) (61af040cd5f)
core_calendar\output\humandate Class Reference
Inheritance diagram for core_calendar\output\humandate:
core\output\renderable core\output\templatable

Public Member Functions

 export_for_template (renderer_base $output)
 Function to export the renderer data in a format that is suitable for a mustache template.
 
 set_display_time_only (bool $timeonly)
 Sets whether we should show time only or date and time.
 
 set_lang_time_format (?string $langtimeformat)
 Sets an optional date format to apply.
 
 set_link (?url $link)
 Sets the link for the date.
 
 set_near_limit (?int $near)
 Sets the number of seconds within which a date is considered near.
 
 set_use_relatives (bool $userelatives)
 Sets whether to use human relative terminology.
 

Static Public Member Functions

static create_from_datetime (DateTimeInterface $datetime, ?int $near=DAYSECS, bool $timeonly=false, ?url $link=null, ?string $langtimeformat=null, bool $userelatives=true,)
 Creates a new humandate instance from a datetime.
 
static create_from_timestamp (int $timestamp, ?int $near=DAYSECS, bool $timeonly=false, ?url $link=null, ?string $langtimeformat=null, bool $userelatives=true,)
 Creates a new humandate instance from a timestamp.
 

Protected Member Functions

 __construct (protected DateTimeImmutable DateTimeImmutable $datetime,)
 Class constructor.
 

Protected Attributes

clock clock $clock
 The clock interface to handle time.
 
string null string $langtimeformat = null
 An optional date format to apply.
 
url null url $link = null
 Link for the date.
 
int null int $near = DAYSECS
 The number of seconds within which a date is considered near.
 
bool bool $timeonly = false
 Whether we should show time only or date and time.
 
bool bool $userelatives = true
 Whether to use human relative terminology.
 

Constructor & Destructor Documentation

◆ __construct()

core_calendar\output\humandate::__construct ( protected DateTimeImmutable DateTimeImmutable $datetime)
protected

Class constructor.

Use the factory methods, such as create_from_timestamp or create_from_datetime, instead.

Parameters
DateTimeImmutable$datetimeThe datetime.
Parameters
$datetime$datetime The datetime. *

Member Function Documentation

◆ create_from_datetime()

static core_calendar\output\humandate::create_from_datetime ( DateTimeInterface $datetime,
?int $near = DAYSECS,
bool $timeonly = false,
?url $link = null,
?string $langtimeformat = null,
bool $userelatives = true )
static

Creates a new humandate instance from a datetime.

Parameters
DateTimeInterface$datetimeThe datetime.
int | null$nearThe number of seconds within which a date is considered near. 1 day by default.
bool$timeonlyWhether we should show time only or date and time.
url | null$linkLink for the date.
string | null$langtimeformatAn optional date format to apply.
bool$userelativesWhether to use human relative terminology.
Return values
humandateThe new instance.

◆ create_from_timestamp()

static core_calendar\output\humandate::create_from_timestamp ( int $timestamp,
?int $near = DAYSECS,
bool $timeonly = false,
?url $link = null,
?string $langtimeformat = null,
bool $userelatives = true )
static

Creates a new humandate instance from a timestamp.

Parameters
int$timestampThe timestamp.
int | null$nearThe number of seconds within which a date is considered near. 1 day by default.
bool$timeonlyWhether we should show time only or date and time.
url | null$linkLink for the date.
string | null$langtimeformatAn optional date format to apply.
bool$userelativesWhether to use human relative terminology.
Return values
humandateThe new instance.

◆ export_for_template()

core_calendar\output\humandate::export_for_template ( renderer_base $output)

Function to export the renderer data in a format that is suitable for a mustache template.

This means:

  1. No complex types - only stdClass, array, int, string, float, bool
  2. Any additional info that is required for the template is pre-calculated (e.g. capability checks).
Parameters
renderer_base$outputUsed to do a final render of any components that need to be rendered for export.
Return values
stdClass|array

Implements core\output\templatable.

◆ set_display_time_only()

core_calendar\output\humandate::set_display_time_only ( bool $timeonly)

Sets whether we should show time only or date and time.

Parameters
bool$timeonlyWhether we should show time only or date and time.
Return values
humandateThe instance.

◆ set_lang_time_format()

core_calendar\output\humandate::set_lang_time_format ( ?string $langtimeformat)

Sets an optional date format to apply.

Parameters
string | null$langtimeformatLang date and time format to use to format the date.
Return values
humandateThe instance.

◆ set_link()

core_calendar\output\humandate::set_link ( ?url $link)

Sets the link for the date.

If null, no link will be added.

Parameters
url | null$linkThe link for the date.
Return values
humandateThe instance.

◆ set_near_limit()

core_calendar\output\humandate::set_near_limit ( ?int $near)

Sets the number of seconds within which a date is considered near.

Parameters
int | null$nearThe number of seconds within which a date is considered near.
Return values
humandateThe instance.

◆ set_use_relatives()

core_calendar\output\humandate::set_use_relatives ( bool $userelatives)

Sets whether to use human relative terminology.

Parameters
bool$userelativesWhether to use human relative terminology.
Return values
humandateThe instance.

Member Data Documentation

◆ $near

int null int core_calendar\output\humandate::$near = DAYSECS
protected

The number of seconds within which a date is considered near.

1 day by default.


The documentation for this class was generated from the following file: