Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 4.3 — Dates and Time Zones
Data Visualization · Example 1 of 3

The same trips on five clocks

A chart that groups by the wrong clock moves thousands of rides to the wrong bar and prints no error. Europe/London shows 386 moved trips because London is one hour ahead of UTC in summer.

A timestamp is one exact instant, but the calendar day it falls on depends on whose clock you read. Parse dates with a stated format, format them on a stated clock, and never let a chart silently shift a ride to the wrong day.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write localDay(iso, zone) returning YYYY-MM-DD. Use it to count how many of trips-10k.csv's trips start on 15 June on the Pacific/Auckland clock.

02

Write hoursInLocalDay(dateText, zone) that returns 23, 24 or 25 for a YYYY-MM-DD date by counting the hours.

Explain it without notes

01

Why can a trip at 00:30 UTC belong to the previous day for some viewers?

02

How do you get the local day of an instant for Ardenvale without a library?

03

Why is dividing a daily total by 24 wrong on 30 March 2025?

The same trips on five clocks

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

First trip: T07790 starts at 2025-06-01T00:00:09Z
UTC                 first trip on 2025-06-01 | trips on 1 June: 330 | trips on another day than UTC: 0
Atlantic/Azores     first trip on 2025-06-01 | trips on 1 June: 330 | trips on another day than UTC: 0
Europe/London       first trip on 2025-06-01 | trips on 1 June: 317 | trips on another day than UTC: 386
America/Los_Angeles first trip on 2025-05-31 | trips on 1 June: 313 | trips on another day than UTC: 2856
Pacific/Auckland    first trip on 2025-06-01 | trips on 1 June: 179 | trips on another day than UTC: 5057