Class Utilities

Object
Utilities

public class Utilities extends Object
Singleton class that handles certain common utility features such as date parsing.
  • Field Details

    • instance

      private static Utilities instance
      The static instance of this class.
    • dateFormatter

      private DateTimeFormatter dateFormatter
      Common Date formatter, based on provided CSV file's date format of d/M/yy.
  • Constructor Details

    • Utilities

      private Utilities()
      Constructor that should not be used outside this class.
  • Method Details

    • getInstance

      public static Utilities getInstance()
      Get Singleton instance of Utilities.
      Returns:
      the singleton instance of Utilities.
    • parseDate

      public LocalDate parseDate(String dateString)
      Parse a date from text.
      Parameters:
      dateString - The text that should be of format d/M/yy (e.g. 12/4/25)
      Returns:
      LocalDate object representing the provided date.
      Throws:
      DateTimeParseException - if the text is not of expected date format, or isn't a date.
    • formatDate

      public String formatDate(LocalDate date)
      Formats a LocalDate object into the CSV file compliant format of d/M/yy (e.g. 12/4/25)
      Parameters:
      date - The date object that you wish to convert to text.
      Returns:
      A string that is formatted based on d/M/yy.
    • formatUserReadableDate

      public String formatUserReadableDate(LocalDate date)
      Format date into text of format MMM dd, yyyy (Example: Jan 1, 2025)
      Parameters:
      date - The date to be formatted.
      Returns:
      date formatted to text as described.
    • formatterForCSVDateTime

      private DateTimeFormatter formatterForCSVDateTime()
      Standardised format to be used to encode date time objects in CSV file. For example: 2025-04-23T17:25:30'
      Returns:
      formatter object to be used in parse or format methods of LocalDateTime.
    • parseDateTime

      public LocalDateTime parseDateTime(String string)
      Parse date and time strings from CSV fields. Intended for CSV date time fields parsing.
      Parameters:
      string - date and time, formatted as ISO 8601, but as local time, without timezone offset.
      Returns:
      an object representing local date and time.
    • formatDateTime

      public String formatDateTime(LocalDateTime dateTime)
      Format date and time object as string, in preparation for encoding into a CSV field.
      Parameters:
      dateTime - local date and time object
      Returns:
      a formatted date and time string, formatted as ISO 8601, as local time, without timezone offset.
    • formatDateFromDateTime

      public String formatDateFromDateTime(LocalDateTime dateTime)
      Formats a date and time object as human-readable date text. For example: 22 Apr 2025.
      Parameters:
      dateTime - the local date time object.
      Returns:
      formatted date only.
    • formatTimeFromDateTime

      public String formatTimeFromDateTime(LocalDateTime dateTime)
      Formats a date and time object as human-readable time text. For example: 8:43:39 pm.
      Parameters:
      dateTime - the local date time object.
      Returns:
      formatted time only.
    • formatUserReadableDateTime

      public String formatUserReadableDateTime(LocalDateTime dateTime)
      Formats a date and time object as human-readable date and time text. For example: 22 Apr 2025, 4:59:18 pm.
      Parameters:
      dateTime - the local date time object.
      Returns:
      formatted date and time, seperated by comma.