Package sc2002.FCS1.grp2.helpers
Class Utilities
Object
Utilities
Singleton class that handles certain common utility features such as date parsing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DateTimeFormatterCommon Date formatter, based on provided CSV file's date format of d/M/yy.private static UtilitiesThe static instance of this class. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateConstructor that should not be used outside this class. -
Method Summary
Modifier and TypeMethodDescriptionformatDate(LocalDate date) Formats aLocalDateobject into the CSV file compliant format of d/M/yy (e.g.formatDateFromDateTime(LocalDateTime dateTime) Formats a date and time object as human-readable date text.formatDateTime(LocalDateTime dateTime) Format date and time object as string, in preparation for encoding into a CSV field.private DateTimeFormatterStandardised format to be used to encode date time objects in CSV file.formatTimeFromDateTime(LocalDateTime dateTime) Formats a date and time object as human-readable time text.Format date into text of format MMM dd, yyyy (Example: Jan 1, 2025)formatUserReadableDateTime(LocalDateTime dateTime) Formats a date and time object as human-readable date and time text.static UtilitiesGet Singleton instance ofUtilities.Parse a date from text.parseDateTime(String string) Parse date and time strings from CSV fields.
-
Field Details
-
instance
The static instance of this class. -
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
Get Singleton instance ofUtilities.- Returns:
- the singleton instance of
Utilities.
-
parseDate
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
Formats aLocalDateobject 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
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
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
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
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
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
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
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.
-