13   What time is it?

In this lesson you will:

  • Create a package for your application
  • Import and use the java.time package
  • Code using classes, objects, and traits together with access modifiers
  • Define an executable object

Timezones are hard, particularly in distributed teams and collaborations. In this capstone, you’ll implement an executable application that uses SBT to prints the current time in a given timezone.

13.1   What time is it?

The goal of this capstone is to create a small program using SBT: it should start, ask the user to enter a timezone, use the input to compute the current time in it and display the result in the terminal in a human-readable format, such as RFC 1123 (e.g., “Fri, 27 Apr 2018 11:44:35 +0200”). Let’s keep things simple, and let the script crash if the user enters an invalid timezone – you’ll learn how to handle exceptions in the next unit.

13.1.1   SBT Project Setup

First, you need to create an SBT project. There are different ways of achieving this: you can create an SBT project using your IDE, or you can apply the hello-world giter8 template (see lesson 3) by typing the command sbt new scala/hello-world.g8. When using the hello-world giter8 template – when doing so, do not forget to delete the Main.scala file in the src/main/scala folder. Alternatively, you can also create an empty SBT project manually as follows:

13.2   The ugly bits of our solution

13.3   Summary