Moodle PHP Documentation 5.0
Moodle 5.0.1+ (Build: 20250711) (61af040cd5f)
core_calendar\output\humantimeperiod Class Reference
Inheritance diagram for core_calendar\output\humantimeperiod:
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_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 $startdatetime, ?DateTimeInterface $enddatetime, ?int $near=DAYSECS, ?url $link=null, ?string $langtimeformat=null, bool $userelatives=true,)
 Creates a new humantimeperiod instance from a datetime.
 
static create_from_timestamp (int $starttimestamp, ?int $endtimestamp, ?int $near=DAYSECS, ?url $link=null, ?string $langtimeformat=null, bool $userelatives=true,)
 Creates a new humantimeperiod instance from a timestamp.
 

Protected Member Functions

 __construct (protected DateTimeImmutable DateTimeImmutable $startdatetime, protected DateTimeImmutable|null ?DateTimeImmutable $enddatetime,)
 Class constructor.
 

Protected Attributes

string null string $langtimeformat = null
 An optional date format to apply.
 
url null url $link = null
 URL to link the date to.
 
int null $near = DAYSECS
 Number of seconds that indicates a nearby date.
 
bool bool $userelatives = true
 Whether to use human common words or not.
 

Constructor & Destructor Documentation

◆ __construct()

core_calendar\output\humantimeperiod::__construct ( protected DateTimeImmutable DateTimeImmutable $startdatetime,
protected DateTimeImmutable|null ?DateTimeImmutable $enddatetime )
protected

Class constructor.

Parameters
DateTimeImmutable$startdatetimeThe starting timestamp.
DateTimeImmutable | null$enddatetimeThe ending timestamp.
Parameters
$startdatetime$startdatetime The starting date time.
$enddatetime$enddatetime The ending date time.

Member Function Documentation

◆ create_from_datetime()

static core_calendar\output\humantimeperiod::create_from_datetime ( DateTimeInterface $startdatetime,
?DateTimeInterface $enddatetime,
?int $near = DAYSECS,
?url $link = null,
?string $langtimeformat = null,
bool $userelatives = true )
static

Creates a new humantimeperiod instance from a datetime.

Parameters
DateTimeInterface$startdatetimeThe starting datetime.
DateTimeInterface | null$enddatetimeThe ending datetime.
int | null$nearThe number of seconds that indicates a nearby date. Default to DAYSECS, use null for no indication.
url | null$linkURL to link the date to.
string | null$langtimeformatLang date and time format to use to format the date.
bool$userelativesWhether to use human common words or not.
Return values
humantimeperiodThe new instance.

◆ create_from_timestamp()

static core_calendar\output\humantimeperiod::create_from_timestamp ( int $starttimestamp,
?int $endtimestamp,
?int $near = DAYSECS,
?url $link = null,
?string $langtimeformat = null,
bool $userelatives = true )
static

Creates a new humantimeperiod instance from a timestamp.

Parameters
int$starttimestampThe starting timestamp.
int | null$endtimestampThe ending timestamp.
int | null$nearThe number of seconds that indicates a nearby date. Default to DAYSECS, use null for no indication.
url | null$linkURL to link the date to.
string | null$langtimeformatLang date and time format to use to format the date.
bool$userelativesWhether to use human common words or not.
Return values
humantimeperiodThe new instance.

◆ export_for_template()

core_calendar\output\humantimeperiod::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_lang_time_format()

core_calendar\output\humantimeperiod::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
humantimeperiodThe instance.

◆ set_link()

core_calendar\output\humantimeperiod::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
humantimeperiodThe instance.

◆ set_near_limit()

core_calendar\output\humantimeperiod::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
humantimeperiodThe instance.

◆ set_use_relatives()

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

Sets whether to use human relative terminology.

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

Member Data Documentation

◆ $near

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

Number of seconds that indicates a nearby date.

Default to DAYSECS. Use null for no indication.


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