Class Util

java.lang.Object
net.amcintosh.freshbooks.Util

public class Util extends Object
Utility functions. Mostly around dates and timezones.
  • Field Details

    • UTC_ZONE

      public static final ZoneId UTC_ZONE
      UTC timezone.
    • ACCOUNTING_LOCAL_ZONE

      public static final ZoneId ACCOUNTING_LOCAL_ZONE
      Local timezone used by the FreshBooks accounting service.
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • getStandardDateFormatter

      public static DateTimeFormatter getStandardDateFormatter()
      Get a DateTimeFormatter configured for date fields ("yyyy-MM-dd").
      Returns:
      The formatter for dates. Eg. 2021-01-08
    • getAccountingDateTimeFormatter

      public static DateTimeFormatter getAccountingDateTimeFormatter()
      Get a DateTimeFormatter configured for accounting endpoint format ("yyyy-MM-dd HH:mm:ss").
      Returns:
      The formatter for accounting endpoints. Eg. 2021-01-08 20:39:52
    • getZonedDateTimeFromAccountingLocalTime

      public static ZonedDateTime getZonedDateTimeFromAccountingLocalTime(String dateString)
      Get a datetime zoned to UTC from an accounting endpoint date string. The accounting service stores almost all dates in the US/Eastern timezone.
      Parameters:
      dateString - An accounting date-string. eg. 2021-01-08 20:39:52
      Returns:
      UTC-zoned datetime
    • getAccountingLocalTimeFromZonedDateTime

      public static String getAccountingLocalTimeFromZonedDateTime(ZonedDateTime datetime)
      Get a date string in the accounting endpoint format and timezone from a ZonedDateTime object. The accounting service stores almost all dates in the US/Eastern timezone.
      Parameters:
      datetime - datetime object from any timezone
      Returns:
      String An accounting date-string in US/Eastern. eg. 2021-01-08 20:39:52
    • getZonedDateTimeFromProjectNaiveUTC

      public static ZonedDateTime getZonedDateTimeFromProjectNaiveUTC(String dateString)
      Get a datetime zoned to UTC from an project-like endpoint date string. The project services store their dates in UTC, but depending on the resource do not indicate that in the response. Eg. "2020-09-13T03:10:13" rather than "2020-09-13T03:10:13Z".
      Parameters:
      dateString - A project-like date-string. eg. 2020-09-13T03:10:13
      Returns:
      UTC-zoned datetime
    • getZonedDateTimeFromISO

      public static ZonedDateTime getZonedDateTimeFromISO(String dateString)
      Get a datetime zoned to UTC from an ISO date string. Eg. "2020-09-13T03:10:13Z"
      Parameters:
      dateString - A project-like date-string. eg. 2020-09-13T03:10:13Z
      Returns:
      UTC-zoned datetime
    • convertContent

      public static void convertContent(Map<String,Object> data, String key, Object value)
      Add a key/value to the provided Map only if the value is not null.
      If the value is a List, then iterates over the list.
      If the value is an object implementing ConvertibleContent then it returns a Map of that object by calling getContent().
      Parameters:
      data - The Map to add to
      key - The key to add
      value - The value of the key if not null