public class Dates extends Object
Utility to provide the following to all layers:
All times use the UTC time zone unless otherwise specified
Modifier and Type | Field and Description |
---|---|
static int |
CHECKSUM_MODULUS |
static int |
NUMBER_OF_SECONDS_IN_A_DAY |
Modifier and Type | Method and Description |
---|---|
static org.joda.time.DateTime |
bitcoinGenesis() |
static com.google.common.util.concurrent.ListenableFuture<Integer> |
calculateDriftInMillis(String sntpHost)
Non-blocking call to an SNTP time server.
|
static String |
formatBackupDate(org.joda.time.ReadableInstant when) |
static String |
formatCompactDate(org.joda.time.ReadableInstant when) |
static String |
formatCompactDate(org.joda.time.ReadableInstant when,
Locale locale) |
static String |
formatCompactDateLocal(org.joda.time.ReadableInstant when) |
static String |
formatCompactDateLocal(org.joda.time.ReadableInstant when,
Locale locale) |
static String |
formatCompactDateWithHyphens(org.joda.time.ReadableInstant when) |
static String |
formatCompactDateWithHyphensLocal(org.joda.time.ReadableInstant when) |
static String |
formatDeliveryDate(org.joda.time.ReadableInstant when) |
static String |
formatDeliveryDate(org.joda.time.ReadableInstant when,
Locale locale) |
static String |
formatDeliveryDateLocal(org.joda.time.ReadableInstant when) |
static String |
formatDeliveryDateLocal(org.joda.time.ReadableInstant when,
Locale locale) |
static String |
formatHttpDateHeader(org.joda.time.ReadableInstant when) |
static String |
formatHttpDateHeaderLocal(org.joda.time.ReadableInstant when) |
static String |
formatIso8601(org.joda.time.ReadableInstant when) |
static String |
formatIso8601(org.joda.time.ReadableInstant when,
Locale locale) |
static String |
formatIso8601Local(org.joda.time.ReadableInstant when) |
static String |
formatIso8601Local(org.joda.time.ReadableInstant when,
Locale locale) |
static String |
formatShortTime(org.joda.time.ReadableInstant when) |
static String |
formatShortTimeLocal(org.joda.time.ReadableInstant when) |
static String |
formatSmtpDate(org.joda.time.ReadableInstant when) |
static String |
formatSmtpDate(org.joda.time.ReadableInstant when,
Locale locale) |
static String |
formatSmtpDateLocal(org.joda.time.ReadableInstant when) |
static String |
formatSmtpDateLocal(org.joda.time.ReadableInstant when,
Locale locale) |
static String |
formatTransactionDate(org.joda.time.ReadableInstant when) |
static String |
formatTransactionDate(org.joda.time.ReadableInstant when,
Locale locale) |
static String |
formatTransactionDateLocal(org.joda.time.ReadableInstant when) |
static String |
formatTransactionDateLocal(org.joda.time.ReadableInstant when,
Locale locale) |
static org.joda.time.DateTime |
midnightLocal() |
static org.joda.time.DateTime |
midnightUtc() |
static String |
newSeedTimestamp()
A seed timestamp is the number of days elapsed since Bitcoin genesis block with a modulo 97 checksum appended.
|
static long |
nowInSeconds()
Get the current date since epoch in seconds
|
static org.joda.time.DateTime |
nowUtc() |
static org.joda.time.DateTime |
parseBackupDate(String text) |
static org.joda.time.DateTime |
parseIso8601(String text) |
static org.joda.time.DateTime |
parseSeedTimestamp(String text) |
static org.joda.time.DateTime |
parseSmtpUtc(String text) |
static org.joda.time.DateTime |
parseSmtpUtc(String text,
Locale locale) |
static long |
thenInSeconds(org.joda.time.ReadableInstant then)
Get the number of seconds since epoch for the given instant
|
static org.joda.time.DateTime |
thenUtc(int year,
int month,
int day,
int hour,
int minute,
int second) |
public static final int CHECKSUM_MODULUS
public static final int NUMBER_OF_SECONDS_IN_A_DAY
public static org.joda.time.DateTime midnightUtc()
public static org.joda.time.DateTime midnightLocal()
public static org.joda.time.DateTime nowUtc()
public static org.joda.time.DateTime thenUtc(int year, int month, int day, int hour, int minute, int second)
year
- The year (e.g. 2000)month
- The month (e.g. January is 1, December is 12)day
- The day of the month (e.g. 1 through to 31)hour
- The hour of the day (e.g. 0 through to 23)minute
- The minute of the day (e.g. 0 through to 59)second
- The second of the day (e.g. 0 through to 59)public static long nowInSeconds()
public static long thenInSeconds(org.joda.time.ReadableInstant then)
then
- The instantpublic static String formatShortTime(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatShortTimeLocal(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatCompactDate(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatCompactDateLocal(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatCompactDate(org.joda.time.ReadableInstant when, Locale locale)
when
- The instantlocale
- The required localepublic static String formatCompactDateLocal(org.joda.time.ReadableInstant when, Locale locale)
when
- The instantlocale
- The required localepublic static String formatBackupDate(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatCompactDateWithHyphens(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatCompactDateWithHyphensLocal(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatDeliveryDate(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatDeliveryDateLocal(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatDeliveryDate(org.joda.time.ReadableInstant when, Locale locale)
when
- The instantlocale
- The required localepublic static String formatDeliveryDateLocal(org.joda.time.ReadableInstant when, Locale locale)
when
- The instantlocale
- The required localepublic static String formatTransactionDate(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatTransactionDateLocal(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatTransactionDate(org.joda.time.ReadableInstant when, Locale locale)
when
- The instantlocale
- The required localepublic static String formatTransactionDateLocal(org.joda.time.ReadableInstant when, Locale locale)
when
- The instantlocale
- The required localepublic static String formatSmtpDate(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatSmtpDateLocal(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatSmtpDate(org.joda.time.ReadableInstant when, Locale locale)
when
- The instantlocale
- The required localepublic static String formatSmtpDateLocal(org.joda.time.ReadableInstant when, Locale locale)
when
- The instantlocale
- The required localepublic static String formatHttpDateHeader(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatHttpDateHeaderLocal(org.joda.time.ReadableInstant when)
when
- The instantpublic static String formatIso8601(org.joda.time.ReadableInstant when)
when
- The instant in its timezonepublic static String formatIso8601Local(org.joda.time.ReadableInstant when)
when
- The instant in its timezonepublic static String formatIso8601(org.joda.time.ReadableInstant when, Locale locale)
when
- The instantlocale
- The required localepublic static String formatIso8601Local(org.joda.time.ReadableInstant when, Locale locale)
when
- The instantlocale
- The required localepublic static org.joda.time.DateTime parseIso8601(String text)
text
- The text representing a date and time in ISO8601 format (e.g. "2000-01-02T03:04:05Z") in UTCIllegalArgumentException
- If the text cannot be parsedpublic static org.joda.time.DateTime parseSmtpUtc(String text)
text
- The text representing a date and time in SMTP format (e.g. "01 Jan 2000") in UTCIllegalArgumentException
- If the text cannot be parsedpublic static org.joda.time.DateTime parseSmtpUtc(String text, Locale locale)
text
- The text representing a date and time in SMTP format (e.g. "01 Jan 2000") in UTClocale
- The specific local to useIllegalArgumentException
- If the text cannot be parsedpublic static org.joda.time.DateTime bitcoinGenesis()
public static String newSeedTimestamp()
A seed timestamp is the number of days elapsed since Bitcoin genesis block with a modulo 97 checksum appended. This gives a short representation that avoids user error during input and works in all locales.
public static org.joda.time.DateTime parseSeedTimestamp(String text)
text
- The text representing a date in seed timestamp format (e.g. "1850/07")IllegalArgumentException
- If the text cannot be parsedpublic static org.joda.time.DateTime parseBackupDate(String text)
text
- The text representing a date and time in backup format (e.g. "20000203235958") in UTCIllegalArgumentException
- If the text cannot be parsedpublic static com.google.common.util.concurrent.ListenableFuture<Integer> calculateDriftInMillis(String sntpHost)
Non-blocking call to an SNTP time server.
sntpHost
- The SNTP host (e.g. "pool.ntp.org" or "")Copyright © 2015–2016. All rights reserved.