Skip to content

Commit ae78b30

Browse files
committed
fixup! [docs] Activity overview redirection
1 parent 1d6ef46 commit ae78b30

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
43.4 KB
Loading
43.9 KB
Loading
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: Date and Time Output Classes
3+
tags:
4+
- Output
5+
---
6+
7+
<Since version="5.0" issueNumber="MDL-83873" />
8+
9+
The `humandate` and `humantimeperiod` classes in Moodle are designed to render timestamps and time periods in a human-readable format. These classes provide functionality to display dates as "Today", "Yesterday", "Tomorrow", and apply alert styling if the date is near the current date.
10+
11+
## Using human time representation output classes
12+
13+
Both classes can be used as a normal output class in Moodle. Each class represent way of show dates and time in a human readable way:
14+
15+
- `humandate`: This renderer presents single dates and times in a user-friendly format, automatically adapting to the user's preferences and with some extra customization options.
16+
- `humantimeperiod`: Designed for displaying date/time ranges, this renderer optimizes information presentation, eliminating redundant date information and representing time in a more user friendly way.
17+
18+
### `humandate` Class
19+
20+
The `humandate` class is used to render a single timestamp as a human-readable date.
21+
22+
![inplace editable example.png](./_humandate/humandate_example.png)
23+
24+
#### Constructor parameters
25+
26+
The `humandate` class constructor accepts the following parameters:
27+
28+
- **`timestamp`** (int): The Unix timestamp to be rendered.
29+
- **`near`** (int|null): The number of seconds that indicates a nearby date. Defaults to `DAYSECS`, use `null` for no indication. Near dates will be rendered with a different styling depending on the theme (usually red with a warning icon).
30+
- **`timeonly`** (bool): Whether to show only the time or the full date and time. Defaults to `false`.
31+
- **`link`** (url|null): an optional URL to link the date to.
32+
- **`langtimeformat`** (string|null): an optional lang date and time format to use to format the date. Otherwise the output will use the user's preferences or the system default.
33+
- **`userelatives`** (bool): Whether to use human common words (tomorrow, yesterday) when possible. Defaults to `true`.
34+
35+
### Example Usage
36+
37+
This will output "Today" if the timestamp is for the current day.
38+
39+
```php
40+
use core_calendar\output\humandate;
41+
42+
$renderer = $PAGE->get_renderer('core', 'output');
43+
$timestamp = time() + HOURSECS;
44+
45+
// Basic example.
46+
$humandate = new humandate($timestamp);
47+
echo $renderer->render($humandate);
48+
49+
// Example adding a link to the date.
50+
$humandate = new humandate(
51+
timestamp: $timestamp,
52+
link: new core\url('/calendar/view.php', ['view' => 'day', 'time' => $timestamp]),
53+
);
54+
echo $renderer->render($humandate);
55+
56+
// Example showing only the time.
57+
$humandate = new humandate(
58+
timestamp: $timestamp,
59+
timeonly: true,
60+
);
61+
echo $renderer->render($humandate);
62+
```
63+
64+
### `humantimeperiod` Class
65+
66+
The `humantimeperiod` class is used to render a time period in a human-readable format.
67+
68+
![inplace editable example.png](./_humandate/humandate_example.png)
69+
70+
#### Constructor parameters
71+
72+
The `humantimeperiod` class constructor accepts the following parameters:
73+
74+
- **`starttimestamp`** (int): The starting timestamp.
75+
- **`endtimestamp`** (int): The ending timestamp.
76+
- **`near`** (int|null): The number of seconds that indicates a nearby date. Defaults to `DAYSECS`, use `null` for no indication.
77+
- **`link`** (url|null): URL to link the date to.
78+
- **`langtimeformat`** (string|null): Lang date and time format to use to format the date.
79+
- **`userelatives`** (bool): Whether to use human common words or not.
80+
81+
### Example Usage
82+
83+
```php
84+
use core_calendar\output\humantimeperiod;
85+
86+
$renderer = $PAGE->get_renderer('core', 'output');
87+
$starttimestamp = time();
88+
$endtimestamp = time() + HOURSECS;
89+
90+
// Basic example.
91+
$humantimeperiod = new humantimeperiod($starttimestamp, $endtimestamp);
92+
echo $renderer->render($humantimeperiod);
93+
94+
// Example adding a link to the date.
95+
$humantimeperiod = new humantimeperiod(
96+
starttimestamp: $starttimestamp,
97+
endtimestamp: $endtimestamp,
98+
link: new core\url('/calendar/view.php', ['view' => 'day', 'time' => $starttimestamp]),
99+
);
100+
echo $renderer->render($humantimeperiod);
101+
```

0 commit comments

Comments
 (0)