Skip to content

Commit

Permalink
Issue 17: Include AM/PM indicator in times
Browse files Browse the repository at this point in the history
  • Loading branch information
stewbis committed May 15, 2016
1 parent 5c02013 commit 9132775
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class DateFormatter implements TemporalFormatter<Date> {

private static final String DATE_TIME_FORMAT = "EEE, dd MMM yyyy hh:mm:ss.SSS";
private static final String DATE_TIME_FORMAT = "EEE, dd MMM yyyy hh:mm:ss.SSS a";
private static final String DATE_FORMAT = "EEE, dd MMM yyyy";

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class LocalDateTimeFormatter implements TemporalFormatter<LocalDateTime> {

private static DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy hh:mm:ss.SSS");
private static DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy hh:mm:ss.SSS a");
private static DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy");

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class LocalTimeFormatter implements TemporalFormatter<LocalTime> {

private static DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("hh:mm:ss");
private static DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("hh:mm:ss a");

@Override
public String describe(final LocalTime temporal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
public class ZonedDateTimeFormatter implements TemporalFormatter<ZonedDateTime> {

private static DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy hh:mm:ss.SSS Z");
private static DateTimeFormatter DATE_TIME_FORMAT = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy hh:mm:ss.SSS a Z");
private static DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy");

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.exparity.hamcrest.date.core.format;

import static org.hamcrest.MatcherAssert.assertThat;

import org.exparity.hamcrest.date.testutils.Dates;
import org.hamcrest.Matchers;
import org.testng.annotations.Test;

/**
* Unit test for the {@link DateFormatter} class
*
* @author Stewart Bissett
*/
public class DateFormatterTest {

@Test
public void canDescribe() {
String description = new DateFormatter().describe(Dates.AUG_04_2015_1159_AS_DATE);
assertThat(description, Matchers.equalTo("Tue, 04 Aug 2015 11:59:00.000 AM"));
}

@Test
public void canDescribeDate() {
String description = new DateFormatter().describeDate(Dates.AUG_04_2015_1159_AS_DATE);
assertThat(description, Matchers.equalTo("Tue, 04 Aug 2015"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.exparity.hamcrest.date.core.format;

import static org.hamcrest.MatcherAssert.assertThat;

import org.exparity.hamcrest.date.testutils.Dates;
import org.hamcrest.Matchers;
import org.testng.annotations.Test;

/**
* Unit test for the {@link LocalDateFormatter} class
*
* @author Stewart Bissett
*/
public class LocalDateFormatterTest {

@Test
public void canDescribe() {
String description = new LocalDateFormatter().describe(Dates.AUG_04_2015);
assertThat(description, Matchers.equalTo("Tue, 04 Aug 2015"));
}

@Test
public void canDescribeDate() {
String description = new LocalDateFormatter().describeDate(Dates.AUG_04_2015);
assertThat(description, Matchers.equalTo("Tue, 04 Aug 2015"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.exparity.hamcrest.date.core.format;

import static org.hamcrest.MatcherAssert.assertThat;

import org.exparity.hamcrest.date.testutils.Dates;
import org.hamcrest.Matchers;
import org.testng.annotations.Test;

/**
* Unit test for the {@link LocalDateTimeFormatter} class
*
* @author Stewart Bissett
*/
public class LocalDateTimeFormatterTest {

@Test
public void canDescribe() {
String description = new LocalDateTimeFormatter().describe(Dates.AUG_04_2015_1159);
assertThat(description, Matchers.equalTo("Tue, 04 Aug 2015 11:59:00.000 AM"));
}

@Test
public void canDescribeDate() {
String description = new LocalDateTimeFormatter().describeDate(Dates.AUG_04_2015_1159);
assertThat(description, Matchers.equalTo("Tue, 04 Aug 2015"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.exparity.hamcrest.date.core.format;

import static org.hamcrest.MatcherAssert.assertThat;

import java.time.LocalTime;
import java.time.temporal.ChronoUnit;

import org.hamcrest.Matchers;
import org.testng.annotations.Test;

/**
* Unit test for the {@link LocalTimeFormatter} class
*
* @author Stewart Bissett
*/
public class LocalTimeFormatterTest {

@Test
public void canDescribe() {
String description = new LocalTimeFormatter().describe(LocalTime.NOON.minus(1, ChronoUnit.SECONDS));
assertThat(description, Matchers.equalTo("11:59:59 AM"));
}

@Test(expectedExceptions = UnsupportedOperationException.class)
public void canDescribeDate() {
new LocalTimeFormatter().describeDate(LocalTime.NOON.minus(1, ChronoUnit.SECONDS));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.exparity.hamcrest.date.core.format;

import static org.hamcrest.MatcherAssert.assertThat;

import org.exparity.hamcrest.date.testutils.Dates;
import org.hamcrest.Matchers;
import org.testng.annotations.Test;

/**
* Unit test for the {@link ZonedDateTimeFormatter} class
*
* @author Stewart Bissett
*/
public class ZonedDateTimeFormatterTest {

@Test
public void canDescribe() {
String description = new ZonedDateTimeFormatter().describe(Dates.AUG_04_2015_11AM_UTC);
assertThat(description, Matchers.equalTo("Tue, 04 Aug 2015 11:59:00.000 AM +0000"));
}

@Test
public void canDescribeDate() {
String description = new ZonedDateTimeFormatter().describeDate(Dates.AUG_04_2015_11AM_UTC);
assertThat(description, Matchers.equalTo("Tue, 04 Aug 2015"));
}

}

0 comments on commit 9132775

Please sign in to comment.