Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
Refactor method naming conevtions
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmihalcea committed Nov 13, 2014
1 parent 9f78e8d commit 0d3607e
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions misc/src/test/java/com/vladmihalcea/datetime/DateTimeTest.java
Expand Up @@ -32,26 +32,37 @@ public void testSimpleDateFormatterWithUTCStrings() throws ParseException {

@Test
public void testJodaDateTimeWithUTCStrings() throws ParseException {
jodaParse("1970-01-01T00:00:00.200Z", 200L);
jodaParse("1970-01-01T00:00:00.200+0000", 200L);
jodaParse("1970-01-01T00:00:00.200+0100", 200L - 1000 * 60 * 60);
jodaTimeParse("1970-01-01T00:00:00.200Z", 200L);
jodaTimeParse("1970-01-01T00:00:00.200+0000", 200L);
jodaTimeParse("1970-01-01T00:00:00.200+0100", 200L - 1000 * 60 * 60);
}

private void dateFormatParse(String pattern, String stringValue, long expectedEpoch) throws ParseException {
/**
* DateFormat parsing utility
* @param pattern date/time pattern
* @param dateTimeString date/time string value
* @param expectedNumericTimestamp expected millis since epoch
*/
private void dateFormatParse(String pattern, String dateTimeString, long expectedNumericTimestamp) {
try {
Date utcDate = new SimpleDateFormat(pattern).parse(stringValue);
if(expectedEpoch != utcDate.getTime()) {
LOGGER.warn("pattern: {}, date: {} actual epoch {} while expected epoch: {}", new Object[]{pattern, stringValue, utcDate.getTime(), expectedEpoch});
Date utcDate = new SimpleDateFormat(pattern).parse(dateTimeString);
if(expectedNumericTimestamp != utcDate.getTime()) {
LOGGER.warn("Pattern: {}, date: {} actual epoch {} while expected epoch: {}", new Object[]{pattern, dateTimeString, utcDate.getTime(), expectedNumericTimestamp});
}
} catch (ParseException e) {
LOGGER.warn("pattern: {}, date: {} threw {}", new Object[]{pattern, stringValue, e.getClass().getSimpleName()});
LOGGER.warn("Pattern: {}, date: {} threw {}", new Object[]{pattern, dateTimeString, e.getClass().getSimpleName()});
}
}

private void jodaParse(String stringValue, long expectedEpoch) {
Date utcDate = DateTime.parse(stringValue).toDate();
if(expectedEpoch != utcDate.getTime()) {
LOGGER.warn("date: {} actual epoch {} while expected epoch: {}", new Object[]{stringValue, utcDate.getTime(), expectedEpoch});
/**
* Joda-Time parsing utility
* @param dateTimeString date/time string value
* @param expectedNumericTimestamp expected millis since epoch
*/
private void jodaTimeParse(String dateTimeString, long expectedNumericTimestamp) {
Date utcDate = DateTime.parse(dateTimeString).toDate();
if(expectedNumericTimestamp != utcDate.getTime()) {
LOGGER.warn("date: {} actual epoch {} while expected epoch: {}", new Object[]{dateTimeString, utcDate.getTime(), expectedNumericTimestamp});
}
}
}

0 comments on commit 0d3607e

Please sign in to comment.