Date Time Utils - UQdeco2800/2021-ext-studio-2 GitHub Wiki

Description

The DateTimeUtils class exposes methods which rely on LocalDateTime inputs in order to display the date and time in a readable manner, instead of a non user friendly ISO Standard.

Location: deco2800/game/utils/DateTimeUtils

Implementation

The java.lang and java.time packages were used to preprocess the LocalDateTime objects in order to get a readable date and time. JAVA provides a lot of convinient classes which help preprocess the LocalDateTime of the system.

  • LocalDateTime: Immutable date-time object that represents a date-time, often viewed as year-month-day-hour-minute-second (As per the Oracle Documentation).
  • DateTimeFormatter: Formatter for printing and parsing date-time objects.

Usage

Function name Return type Description
getFormattedTime(LocalDateTime dateTime) String Prettifies the time and returns it.
Example: 05:55:23 AM
getVerboseDate(LocalDateTime dateTime) String Prettifies the date and returns it in a verbose format.
Example: Tuesday, 31 December, 2021
getFormattedDate(LocalDateTime dateTime) String Prettifies the date and returns it in a concise format.
Example: 31/12/2021
getFormattedDateTime(LocalDateTime dateTime) String Returns prettified date and time.
Example: 2021-09-15 11:38 PM
getCurrentDateTime() LocalDateTime Returns the current date and time in local time zone, based on the one that is set on the operating system. An object similar to the one returned by this function will ideally be used as an input to the above functions when the game is running and when the necessary operations are performed. Also, in the in game records, this object is parsed as a string and then stored. Its string represents the date and time of the operating system at the time of invocation.

Sample Usage:

// Sample return value: Tuesday, 31 December, 2021
String formattedDate = DateTimeUtils.getVerboseDate(DateTimeUtils.getCurrentDateTime());
⚠️ **GitHub.com Fallback** ⚠️