Chapter 7: dates, typed

Chapter 7 does arithmetic on dates: a start date, a notice period of one month and fifteen days, the due date they give, and the span between. The values are literals you type; the IDE writes the program's shell. To play it in the IDE: Help > Lessons > Getting Started with EK9…, or ek9 -ide -lesson book-deadline.

The EK9 IDE as the lesson opens

What you'll build

The lesson builds this program from a file holding only its module line - the finished file, as the book prints it.

#!ek9
defines module book.dates

  defines program

    Deadline()
      stdout <- Stdout()
      enGB <- Locale("en_GB")

      start <- 2026-01-15
      notice <- P1M15D
      due <- start + notice

      stdout.println(`Start: ${enGB.mediumFormat(start)}`)
      stdout.println(`Due:   ${enGB.mediumFormat(due)}`)

      span <- due - start
      stdout.println(`Notice period is ${span}`)
      stdout.println(`Due falls on day-of-week ${due.dayOfWeek()}`)

Step 1: The program's shell

Choose Code > New Construct > Program…

The EK9 IDE once this is done: Choose Code > New Construct > Program…

Deadline is the program's name. Type it and choose Preview.

The EK9 IDE just before choosing Preview: Deadline is the program's name

The preview shows Deadline about to be written. Choose Apply.

The EK9 IDE just before choosing Apply: The preview shows Deadline about to be written

The tool leaves no blank line before the program: select the Deadline() line and, above it, type the one the book opens with. Saves when typed.

The EK9 IDE once this is done: The tool leaves no blank line before the program

Step 2: The body, typed

Select the stub, from ready <- true down to its //AI line, and type the body exactly as the chapter shows it. Saves when typed.

The EK9 IDE once this is done: Select the stub, from ready <- true down to its //AI line, and type the body exactly as the chapter shows it

Step 3: Run it

Choose Run > Run Program…

The EK9 IDE once this is done: Choose Run > Run Program…

The project's only program is already chosen. Choose Run.

Start: 15 Jan 2026, Due: 2 Mar 2026, Notice period is P1M15D, Due falls on day-of-week 1. Choose Close.

The EK9 IDE just before choosing Close: Start

The result

Deadline.ek9 now reads exactly as chapter 7 of Getting Started with EK9 shows it: a Date plus a Duration gives a Date, and a Date minus a Date gives a Duration - all formatted for en_GB.

The EK9 IDE when the lesson has finished

Where this lesson comes from