Skip to content

Commit 4d70a52

Browse files
authored
Merge pull request #3144 from obsidian-tasks-group/test-timezones-and-recurrence
vault: Add manual test of recurrence in Pacific/Auckland at DST boundary
2 parents 680612c + f12cca0 commit 4d70a52

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

contributing/Testing/About Testing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Testing dates and times:
2323

2424
- [[How do I use Moment in tests]] - how to test date and time values
2525
- [[Simulating Dates and Times]] - examples of how to use fixed dates and times in tests
26+
- [[Testing and Time Zones]] - how to test in different time zones (with difficulty)
2627

2728
Testing code that uses Obsidian API:
2829

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
publish: true
3+
---
4+
5+
# Testing in different Time Zones
6+
7+
<span class="related-pages">#testing/automated-testing #testing/manual-testing</span>
8+
9+
## Fixing the time zone to UTC in Jest
10+
11+
Currently, our Jest tests fix the time zone at run-time to `UTC` in [tests/global-setup.js](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/tests/global-setup.js).
12+
13+
This was done to ensure that the tests pass for contributors all around the world, regardless of their own time zone.
14+
15+
## Why we don't use 'moment-timezone'
16+
17+
... in `src/`:
18+
19+
1. Obsidian plugins are instructed to use `moment` as supplied by Obsidian, to reduce plugin size.
20+
1. `moment-timezone` increases the Tasks plugin `main.js` size 10-fold, which would slow down start-up time.
21+
1. So we can't use `moment-timezone` in the released plugin.
22+
23+
... in `tests/`:
24+
25+
1. The only way to set the timezone dynamically in tests is to use [moment-timezone](https://momentjs.com/timezone/docs/).
26+
1. But `moment-timezone` modifies the behaviour of `moment`
27+
1. Which would invalidate any of tests of behaviour that uses `moment`: we could not be confident that the code would behave the same in the released plugin as it does in tests.
28+
29+
## Manually testing in different time zones
30+
31+
In the absence of automated testing of Tasks in different time zones, see this manual test in the 'Tasks-Demo' vault:
32+
33+
- [Tasks-Demo/Manual Testing/Time Zones/Pacific-Auckland.md](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/resources/sample_vaults/Tasks-Demo/Manual%20Testing/Time%20Zones/Pacific-Auckland.md).
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Pacific-Auckland
2+
3+
> [!NOTE]
4+
> These instructions assume testing on Mac - hence use of `open` to an Obsidian URL...
5+
6+
## Setting up this manual test
7+
8+
1. Make sure that you have opened the [Tasks-Demo](https://github.com/obsidian-tasks-group/obsidian-tasks/tree/main/resources/sample_vaults/Tasks-Demo) test vault previously, so that Obsidian knows where that vault is on your computer.
9+
2. Run the following command
10+
11+
```bash
12+
TZ=Pacific/Auckland open 'obsidian://open?vault=Tasks-Demo&file=Manual%20Testing%2FTime%20Zones%2FPacific-Auckland'
13+
```
14+
15+
3. View this page in Reading or Live Preview mode
16+
4. Confirm that the headings in the Tasks block are:
17+
- `Timezone: Pacific/Auckland`
18+
- `2024-09-28 Saturday`
19+
20+
## Run the test
21+
22+
1. Complete the task in this file.
23+
2. Check that the due date of the new task - and the new heading - is '2024-09-28 Sunday'
24+
25+
## Tasks Plugin Search
26+
27+
```tasks
28+
not done
29+
path includes {{query.file.path}}
30+
31+
group by function 'Timezone: ' + process.env.TZ
32+
group by due
33+
34+
hide backlinks
35+
```
36+
37+
## Test task
38+
39+
- [ ] #task Next due date should be `2024-09-28 Sunday` 🔁 every day 📅 2024-09-28
40+
41+
## Background
42+
43+
- This manual test shows the existence of the bug logged in:
44+
- [Completing a daily recurring task creates task set to same day [the day before Australian clocks switch to daylight savings]](https://github.com/obsidian-tasks-group/obsidian-tasks/issues/2309)
45+
- It was written to test the behaviour of pull request \#3121:
46+
- [fix: advance recurring tasks correctly at start of Daylight Savings Time](https://github.com/obsidian-tasks-group/obsidian-tasks/pull/3121)

tests/global-setup.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
module.exports = async () => {
22
process.env.TZ = 'UTC';
3+
4+
/*
5+
* Below is an example alternative time zone, for experimentation.
6+
* See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
7+
* Note: Currently many tests fail if the timezone is changed, due to
8+
* the use of `moment.toISOString()` in the `toEqualMoment()`
9+
* custom matcher in our tests.
10+
*/
11+
// process.env.TZ = 'Pacific/Auckland';
312
};

0 commit comments

Comments
 (0)