Skip to content

Commit

Permalink
Only apply timezone adjustment if explicitly specified
Browse files Browse the repository at this point in the history
  • Loading branch information
stewbis committed Sep 28, 2019
1 parent dea7c9e commit 0bd226d
Show file tree
Hide file tree
Showing 33 changed files with 164 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ public static TemporalMatcher<java.sql.Date> sameMonth(final java.util.Date date
* @param date the reference date against which the examined date is checked
*/
public static TemporalMatcher<java.sql.Date> sameMonthOfYear(final Date date) {
return isMonth(SQLDATE_AS_MONTH.apply(date, ZoneId.systemDefault()));
return new IsMonth<Date>(SQLDATE_AS_MONTH, month(date));
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/exparity/hamcrest/date/core/IsAfter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.ZoneId;
import java.util.Locale;
import java.util.Optional;

import org.hamcrest.Description;

Expand All @@ -19,12 +20,12 @@ public class IsAfter<T, E> extends TemporalMatcher<T> {
private final TemporalConverter<T, E> converter;
private final TemporalFunction<E> functions;
private final Locale locale;
private final ZoneId zone;
private final Optional<ZoneId> zone;

public IsAfter(TemporalConverter<T, E> converter,
TemporalProvider<E> expected,
TemporalFunction<E> functions,
ZoneId zone,
Optional<ZoneId> zone,
Locale locale) {
this.expected = expected;
this.converter = converter;
Expand All @@ -34,7 +35,7 @@ public IsAfter(TemporalConverter<T, E> converter,
}

public IsAfter(TemporalConverter<T, E> converter, TemporalProvider<E> expected, TemporalFunction<E> functions) {
this(converter, expected, functions, ZoneId.systemDefault(), Locale.getDefault(Locale.Category.FORMAT));
this(converter, expected, functions, Optional.empty(), Locale.getDefault(Locale.Category.FORMAT));
}

@Override
Expand All @@ -55,7 +56,7 @@ public void describeTo(final Description description) {

@Override
public TemporalMatcher<T> atZone(ZoneId zone) {
return new IsAfter<>(converter, expected, functions, zone, locale);
return new IsAfter<>(converter, expected, functions, Optional.of(zone), locale);
}

@Override
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/exparity/hamcrest/date/core/IsBefore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.ZoneId;
import java.util.Locale;
import java.util.Optional;

import org.hamcrest.Description;

Expand All @@ -19,12 +20,12 @@ public class IsBefore<T, E> extends TemporalMatcher<T> {
private final TemporalConverter<T, E> converter;
private final TemporalFunction<E> functions;
private final Locale locale;
private final ZoneId zone;
private final Optional<ZoneId> zone;

public IsBefore(TemporalConverter<T, E> converter,
TemporalProvider<E> expected,
TemporalFunction<E> functions,
ZoneId zone,
Optional<ZoneId> zone,
Locale locale) {
this.expected = expected;
this.converter = converter;
Expand All @@ -34,7 +35,7 @@ public IsBefore(TemporalConverter<T, E> converter,
}

public IsBefore(TemporalConverter<T, E> converter, TemporalProvider<E> expected, TemporalFunction<E> functions) {
this(converter, expected, functions, ZoneId.systemDefault(), Locale.getDefault(Locale.Category.FORMAT));
this(converter, expected, functions, Optional.empty(), Locale.getDefault(Locale.Category.FORMAT));
}

@Override
Expand All @@ -55,7 +56,7 @@ public void describeTo(final Description description) {

@Override
public TemporalMatcher<T> atZone(ZoneId zone) {
return new IsBefore<>(converter, expected, functions, zone, locale);
return new IsBefore<>(converter, expected, functions, Optional.of(zone), locale);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.ZoneId;
import java.util.Locale;
import java.util.Optional;

import org.exparity.hamcrest.date.core.types.DayOfMonth;
import org.hamcrest.Description;
Expand All @@ -16,11 +17,11 @@ public class IsDayOfMonth<T> extends TemporalMatcher<T> {
private final TemporalConverter<T, DayOfMonth> converter;
private final TemporalProvider<DayOfMonth> expected;
private final Locale locale;
private final ZoneId zone;
private final Optional<ZoneId> zone;

public IsDayOfMonth(TemporalConverter<T, DayOfMonth> converter,
TemporalProvider<DayOfMonth> expected,
ZoneId zone,
Optional<ZoneId> zone,
Locale locale) {
this.expected = expected;
this.converter = converter;
Expand All @@ -29,7 +30,7 @@ public IsDayOfMonth(TemporalConverter<T, DayOfMonth> converter,
}

public IsDayOfMonth(TemporalConverter<T, DayOfMonth> converter, TemporalProvider<DayOfMonth> expected) {
this(converter, expected, ZoneId.systemDefault(), Locale.getDefault(Locale.Category.FORMAT));
this(converter, expected, Optional.empty(), Locale.getDefault(Locale.Category.FORMAT));
}

@Override
Expand All @@ -50,7 +51,7 @@ public void describeTo(final Description description) {

@Override
public TemporalMatcher<T> atZone(ZoneId zone) {
return new IsDayOfMonth<>(converter, expected, zone, locale);
return new IsDayOfMonth<>(converter, expected, Optional.of(zone), locale);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.format.TextStyle;
import java.util.List;
import java.util.Locale;
import java.util.Optional;

import org.hamcrest.Description;

Expand All @@ -20,11 +21,11 @@ public class IsDayOfWeek<T> extends TemporalMatcher<T> {
private final TemporalConverter<T, DayOfWeek> converter;
private final TemporalProvider<List<DayOfWeek>> expected;
private final Locale locale;
private final ZoneId zone;
private final Optional<ZoneId> zone;

public IsDayOfWeek(TemporalConverter<T, DayOfWeek> converter,
TemporalProvider<List<DayOfWeek>> expected,
ZoneId zone,
Optional<ZoneId> zone,
Locale locale) {
this.expected = expected;
this.converter = converter;
Expand All @@ -33,7 +34,7 @@ public IsDayOfWeek(TemporalConverter<T, DayOfWeek> converter,
}

public IsDayOfWeek(TemporalConverter<T, DayOfWeek> converter, TemporalProvider<List<DayOfWeek>> expected) {
this(converter, expected, ZoneId.systemDefault(), Locale.getDefault(Locale.Category.FORMAT));
this(converter, expected, Optional.empty(), Locale.getDefault(Locale.Category.FORMAT));
}

@Override
Expand Down Expand Up @@ -64,7 +65,7 @@ public void describeTo(final Description description) {

@Override
public TemporalMatcher<T> atZone(ZoneId zone) {
return new IsDayOfWeek<>(converter, expected, zone, locale);
return new IsDayOfWeek<>(converter, expected, Optional.of(zone), locale);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.time.temporal.TemporalAccessor;
import java.time.temporal.ValueRange;
import java.util.Locale;
import java.util.Optional;

import org.hamcrest.Description;

Expand All @@ -17,16 +18,16 @@ public class IsFirstDayOfMonth<T> extends TemporalMatcher<T> {

private final TemporalConverter<T, ? extends TemporalAccessor> converter;
private final Locale locale;
private final ZoneId zone;
private final Optional<ZoneId> zone;

public IsFirstDayOfMonth(TemporalConverter<T, ? extends TemporalAccessor> converter, ZoneId zone, Locale locale) {
public IsFirstDayOfMonth(TemporalConverter<T, ? extends TemporalAccessor> converter, Optional<ZoneId> zone, Locale locale) {
this.converter = converter;
this.locale = locale;
this.zone = zone;
}

public IsFirstDayOfMonth(TemporalConverter<T, ? extends TemporalAccessor> converter) {
this(converter, ZoneId.systemDefault(), Locale.getDefault(Locale.Category.FORMAT));
this(converter, Optional.empty(), Locale.getDefault(Locale.Category.FORMAT));
}

@Override
Expand All @@ -49,7 +50,7 @@ public void describeTo(final Description description) {

@Override
public TemporalMatcher<T> atZone(ZoneId zone) {
return new IsFirstDayOfMonth<>(converter, zone, locale);
return new IsFirstDayOfMonth<>(converter, Optional.of(zone), locale);
}

@Override
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/exparity/hamcrest/date/core/IsHour.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.ZoneId;
import java.util.Locale;
import java.util.Optional;

import org.exparity.hamcrest.date.core.types.Hour;
import org.hamcrest.Description;
Expand All @@ -16,11 +17,11 @@ public class IsHour<T> extends TemporalMatcher<T> {
private final TemporalConverter<T, Hour> converter;
private final TemporalProvider<Hour> expected;
private final Locale locale;
private final ZoneId zone;
private final Optional<ZoneId> zone;

public IsHour(TemporalConverter<T, Hour> converter,
TemporalProvider<Hour> expected,
ZoneId zone,
Optional<ZoneId> zone,
Locale locale) {
this.expected = expected;
this.converter = converter;
Expand All @@ -29,7 +30,7 @@ public IsHour(TemporalConverter<T, Hour> converter,
}

public IsHour(TemporalConverter<T, Hour> converter, TemporalProvider<Hour> expected) {
this(converter, expected, ZoneId.systemDefault(), Locale.getDefault(Locale.Category.FORMAT));
this(converter, expected, Optional.empty(), Locale.getDefault(Locale.Category.FORMAT));
}

@Override
Expand All @@ -50,7 +51,7 @@ public void describeTo(final Description description) {

@Override
public TemporalMatcher<T> atZone(ZoneId zone) {
return new IsHour<>(converter, expected, zone, locale);
return new IsHour<>(converter, expected, Optional.of(zone), locale);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.time.temporal.TemporalAccessor;
import java.time.temporal.ValueRange;
import java.util.Locale;
import java.util.Optional;

import org.hamcrest.Description;

Expand All @@ -17,16 +18,16 @@ public class IsLastDayOfMonth<T> extends TemporalMatcher<T> {

private final TemporalConverter<T, ? extends TemporalAccessor> converter;
private final Locale locale;
private final ZoneId zone;
private final Optional<ZoneId> zone;

public IsLastDayOfMonth(TemporalConverter<T, ? extends TemporalAccessor> converter, ZoneId zone, Locale locale) {
public IsLastDayOfMonth(TemporalConverter<T, ? extends TemporalAccessor> converter, Optional<ZoneId> zone, Locale locale) {
this.converter = converter;
this.locale = locale;
this.zone = zone;
}

public IsLastDayOfMonth(TemporalConverter<T, ? extends TemporalAccessor> converter) {
this(converter, ZoneId.systemDefault(), Locale.getDefault(Locale.Category.FORMAT));
this(converter, Optional.empty(), Locale.getDefault(Locale.Category.FORMAT));
}

@Override
Expand All @@ -49,7 +50,7 @@ public void describeTo(final Description description) {

@Override
public TemporalMatcher<T> atZone(ZoneId zone) {
return new IsLastDayOfMonth<>(converter, zone, locale);
return new IsLastDayOfMonth<>(converter, Optional.of(zone), locale);
}

@Override
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/exparity/hamcrest/date/core/IsLeapYear.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.Year;
import java.time.ZoneId;
import java.util.Locale;
import java.util.Optional;

import org.hamcrest.Description;

Expand All @@ -15,16 +16,16 @@ public class IsLeapYear<T> extends TemporalMatcher<T> {

private final TemporalConverter<T, Year> converter;
private final Locale locale;
private final ZoneId zone;
private final Optional<ZoneId> zone;

public IsLeapYear(TemporalConverter<T, Year> converter, ZoneId zone, Locale locale) {
public IsLeapYear(TemporalConverter<T, Year> converter, Optional<ZoneId> zone, Locale locale) {
this.converter = converter;
this.locale = locale;
this.zone = zone;
}

public IsLeapYear(TemporalConverter<T, Year> converter) {
this(converter, ZoneId.systemDefault(), Locale.getDefault(Locale.Category.FORMAT));
this(converter, Optional.empty(), Locale.getDefault(Locale.Category.FORMAT));
}

@Override
Expand All @@ -45,7 +46,7 @@ public void describeTo(final Description description) {

@Override
public TemporalMatcher<T> atZone(ZoneId zone) {
return new IsLeapYear<>(converter, zone, locale);
return new IsLeapYear<>(converter, Optional.of(zone), locale);
}

@Override
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/exparity/hamcrest/date/core/IsMaximum.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.temporal.TemporalAccessor;
import java.time.temporal.ValueRange;
import java.util.Locale;
import java.util.Optional;
import java.util.stream.Stream;

import org.hamcrest.Description;
Expand All @@ -23,11 +24,11 @@ public class IsMaximum<T> extends TemporalMatcher<T> {
private final TemporalConverter<T, ? extends TemporalAccessor> converter;
private final ChronoField field;
private final Locale locale;
private final ZoneId zone;
private final Optional<ZoneId> zone;

public IsMaximum(TemporalConverter<T, ? extends TemporalAccessor> converter,
ChronoField field,
ZoneId zone,
Optional<ZoneId> zone,
Locale locale) {
this.converter = converter;
this.field = field;
Expand All @@ -36,7 +37,7 @@ public IsMaximum(TemporalConverter<T, ? extends TemporalAccessor> converter,
}

public IsMaximum(TemporalConverter<T, ? extends TemporalAccessor> converter, ChronoField field) {
this(converter, field, ZoneId.systemDefault(), Locale.getDefault(Locale.Category.FORMAT));
this(converter, field, Optional.empty(), Locale.getDefault(Locale.Category.FORMAT));
}

@Override
Expand All @@ -62,7 +63,7 @@ public void describeTo(final Description description) {

@Override
public TemporalMatcher<T> atZone(ZoneId zone) {
return new IsMaximum<>(converter, field, zone, locale);
return new IsMaximum<>(converter, field, Optional.of(zone), locale);
}

@Override
Expand Down

0 comments on commit 0bd226d

Please sign in to comment.