Package net.amcintosh.freshbooks
Class Util
java.lang.Object
net.amcintosh.freshbooks.Util
Utility functions. Mostly around dates and timezones.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Add a key/value to the provided Map only if the value is not null.static DateTimeFormatter
Get a DateTimeFormatter configured for accounting endpoint format ("yyyy-MM-dd HH:mm:ss").static String
Get a date string in the accounting endpoint format and timezone from a ZonedDateTime object.static DateTimeFormatter
Get a DateTimeFormatter configured for date fields ("yyyy-MM-dd").static ZonedDateTime
getZonedDateTimeFromAccountingLocalTime
(String dateString) Get a datetime zoned to UTC from an accounting endpoint date string.static ZonedDateTime
getZonedDateTimeFromISO
(String dateString) Get a datetime zoned to UTC from an ISO date string.static ZonedDateTime
getZonedDateTimeFromProjectNaiveUTC
(String dateString) Get a datetime zoned to UTC from an project-like endpoint date string.
-
Field Details
-
UTC_ZONE
UTC timezone. -
ACCOUNTING_LOCAL_ZONE
Local timezone used by the FreshBooks accounting service.
-
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
getStandardDateFormatter
Get a DateTimeFormatter configured for date fields ("yyyy-MM-dd").- Returns:
- The formatter for dates. Eg. 2021-01-08
-
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
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
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
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
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
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 implementingConvertibleContent
then it returns a Map of that object by callinggetContent()
.- Parameters:
data
- The Map to add tokey
- The key to addvalue
- The value of the key if not null
-