Skip to content

Commit

Permalink
fixup! [Docs] Migrate Time API
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocolate-lightning committed Jul 6, 2022
1 parent b565101 commit 0588876
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions docs/apis/subsystems/time/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ tags:
- Time
---

## Overview

Internally Moodle always stores all times in unixtime format (number of seconds since epoch) which is independent of timezones.

The Time API is used to display proper date-time depending on user or site timezones.
Expand Down Expand Up @@ -47,7 +45,9 @@ $time->setTime(15, 0, 0);
$timestamp = $time->getTimestamp();
```

Remember! NEVER NEVER NEVER add or subtract timestamps for any reason - you will get it wrong (DST is a killer)!
:::danger
Never add or subtract timestamps for any reason - you will get it wrong (DST is a killer)!
:::

Other functions related to time api can be found in lib/moodlelib.php.

Expand Down Expand Up @@ -84,7 +84,7 @@ Moodle supports following timezone formats:

### Location

Timezone depends on [en](https://docs.moodle.org/en/Location) of the user and can be forced upon by administrator.
Timezone depends on [Location](https://docs.moodle.org/en/Location) of the user and can be forced upon by administrator.

### DST

Expand All @@ -94,9 +94,11 @@ DST is abbreviation of **Daylight Saving Time** (also known as "Day light saving

### Create DateTime with date/time from a unixtime (number of seconds)

```php
$date = new DateTime();
$date->setTimestamp(intval($unixtime);
echo userdate($date->getTimestamp());
```

### Time API's for current user

Expand Down Expand Up @@ -125,7 +127,7 @@ echo userdate($date->getTimestamp(), get_string('strftimedatefullshort', 'core_l

Find the day of the week for the first day in this month.

<pre>
```php
$now = new DateTime("now", core_date::get_server_timezone_object());

$year = $now->format('Y');
Expand All @@ -134,7 +136,7 @@ $month = $now->format('m');
$now->setDate($year, $month, 1);
$dayofweek = $now->format('N');
echo $dayofweek;
</pre>
```

## See also

Expand Down

0 comments on commit 0588876

Please sign in to comment.