Skip to content

Example

Mohammad Badar Hashimi edited this page Feb 23, 2020 · 1 revision

Business Working Hour

@Test
    public void parseAnyPeriod() {
        BusinessWorkingHour bh = new BusinessWorkingHour("");
        Temporal temporal = LocalDateTime.now();
        for (int i = 0; i < 86400; i++) {
            temporal.plus(1, ChronoUnit.SECONDS);
            assertEquals(bh.isOpen(temporal), true);
            assertEquals(bh.timeBeforeOpening(temporal, ChronoUnit.NANOS), Long.MAX_VALUE);
        }
    }

    @Test
    public void hourBoundaries() {
        BusinessWorkingHour bh = new BusinessWorkingHour("hr {09-5pm}");
        Temporal t = LocalDateTime.parse("2014-04-22T08:59:59");
        assertEquals(bh.isOpen(t), false);
        t = LocalDateTime.parse("2014-04-22T09:00:00");
        assertEquals(bh.isOpen(t), true);
        t = LocalDateTime.parse("2014-04-22T17:59:59");
        assertEquals(bh.isOpen(t), true);
        t = LocalDateTime.parse("2014-04-22T18:00:00");
        assertEquals(bh.isOpen(t), false);
    }

    @Test
    public void mergeHours() {
        assertEquals(BusinessWorkingHourParser.parse("hr {09-17}, hr {11am-12am}"), BusinessWorkingHourParser.parse("hr {9-0}"));
    }

    @Test
    public void timeBeforeOpening() {
        BusinessWorkingHour bh = new BusinessWorkingHour("wday {tu-thu} hr {08-5pm}");
        assertEquals(bh.timeBeforeOpening(LocalDateTime.parse("2014-04-22T07:08:09"), ChronoUnit.SECONDS), 51 * 60 + 51);
        assertEquals(bh.timeBeforeOpening(LocalDateTime.parse("2014-04-21T07:08:09"), ChronoUnit.SECONDS), 86400 + 51 * 60 + 51);
        assertEquals(bh.timeBeforeOpening(LocalDateTime.parse("2014-04-22T18:00:00"), ChronoUnit.SECONDS), 14 * 3600);

        bh = new BusinessWorkingHour("wday {we-mon} hr {21-03}");
        assertEquals(bh.timeBeforeOpening(LocalDateTime.parse("2014-12-23T23:59:00"), ChronoUnit.MINUTES), 1L);
    }

    @Test
    public void numericWeekDay() {
        assertEquals(new BusinessWorkingHour("wday {mo-we}"), new BusinessWorkingHour("wday {1-3}"));
        assertEquals(new BusinessWorkingHour("wday {mo-we}").hashCode(), new BusinessWorkingHour("wday {1-3}").hashCode());
    }

    @Test
    public void letterHours() {
        assertEquals(new BusinessWorkingHour("hr{12am}"), new BusinessWorkingHour("hr{0}"));
        assertEquals(new BusinessWorkingHour("hr{1am}"), new BusinessWorkingHour("hr{1}"));
        assertEquals(new BusinessWorkingHour("hr{12pm}"), new BusinessWorkingHour("hr{12}"));
        assertEquals(new BusinessWorkingHour("hr{12noon}"), new BusinessWorkingHour("hr{12}"));
        assertEquals(new BusinessWorkingHour("hr{1pm}"), new BusinessWorkingHour("hr{13}"));
    }

    @Test
    public void reverseBoundaries() {
        BusinessWorkingHour bh = new BusinessWorkingHour("wday {sa-mo} hr {10pm-8am} min{50-10}");
        assertEquals(bh.isOpen(LocalDateTime.parse("2014-04-25T22:00:00")), false);
        assertEquals(bh.isOpen(LocalDateTime.parse("2014-04-26T22:49:59")), false);
        assertEquals(bh.isOpen(LocalDateTime.parse("2014-04-26T22:50:00")), true);
        assertEquals(bh.isOpen(LocalDateTime.parse("2014-04-26T22:10:59")), true);
        assertEquals(bh.isOpen(LocalDateTime.parse("2014-04-26T22:11:00")), false);
        assertEquals(bh.isOpen(LocalDateTime.parse("2014-04-26T23:49:59")), false);
        assertEquals(bh.isOpen(LocalDateTime.parse("2014-04-26T23:55:12")), true);
    }

    @Test
    public void BusinessWorkingHourtoString() {
        assertEquals(new BusinessWorkingHour("wday {mon-Fri} hr {9-18}").toString(), "wday {mon-Fri} hr {9-18}");
    }

    @Test
    public void openingCrons() {
        assertEquals(new BusinessWorkingHour("wday{Mon-Fri} hr{9-18}").getOpeningCrons(), Collections.singleton("0 9 * * 1-5"));
        assertEquals(new BusinessWorkingHour("wday{Sa} hr{12-23}, wday{Su}").getOpeningCrons(), Collections.singleton("0 12 * * 6"));
        //every Wednesday and Thursday, from 20h30 to 4am
        //It opens on Wednesday at midnight, and on Wednesdays and Thursday at 20h30
        assertEquals(
                new BusinessWorkingHour("wday{We-Th} hr{21-3}, wday{We-Th} hr{20} min{30-59}").getOpeningCrons(),
                new HashSet<String>() {
                    {
                        add("0 0 * * 3");
                        add("30 20 * * 3-4");
                    }
                });
    }

    @Test
    public void closingCrons() {
        assertEquals(new BusinessWorkingHour("wday{Mon-Fri} hr{9-18}").getClosingCrons(), Collections.singleton("0 19 * * 1-5"));
        assertEquals(new BusinessWorkingHour("wday{Sa} hr{12-23}, wday{Su}").getClosingCrons(), Collections.singleton("0 0 * * 1"));
        //every Wednesday and Thursday, from 9pm to 4:30am
        //It closes on Wednesday and Thursday at 4:30am, and Friday at midnight
        assertEquals(
                new BusinessWorkingHour("wday{We-Th} hr{21-3}, wday{We-Th} hr{4} min{0-29}").getClosingCrons(),
                new HashSet<String>() {
                    {
                        add("0 0 * * 5");
                        add("30 4 * * 3-4");
                    }
                });
    }

Period

  @Test
    public void alwaysOpen() {
        assertTrue(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 0)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 59)))
                        .alwaysOpen());
        assertFalse(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 1)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 59)))
                        .alwaysOpen());
    }

    @Test
    public void isInPeriod() {

        assertTrue(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 10)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 15)))
                        .isInPeriod(LocalTime.of(0, 10, 00)));

        assertTrue(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 10)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 15)))
                        .isInPeriod(LocalTime.of(0, 15, 59)));

        assertFalse(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 10)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 15)))
                        .isInPeriod(LocalTime.of(0, 16, 0)));

        assertFalse(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 10)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 15)))
                        .isInPeriod(LocalTime.of(0, 9, 59)));
    }

    @Test
    public void timeBeforeOpening() {
        assertEquals(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 10)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 15)))
                        .timeBeforeOpening(LocalTime.of(0, 9, 1), ChronoUnit.SECONDS), 59);

        assertEquals(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 10)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 15)))
                        .timeBeforeOpening(LocalTime.of(0, 10, 0), ChronoUnit.SECONDS), 0);

        assertEquals(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 10)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 15)))
                        .timeBeforeOpening(LocalTime.of(0, 10, 1), ChronoUnit.SECONDS), 3599);

        assertEquals(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 0)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 59)))
                        .timeBeforeOpening(LocalTime.of(0, 0), ChronoUnit.MINUTES), Long.MAX_VALUE);
    }

    @Test
    public void getStartCron() {
        assertEquals(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 10)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 15)))
                        .getStartCron().toString(), "10 * * * *");

        assertNull(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 0)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 59)))
                        .getStartCron());
    }

    @Test
    public void getEndCron() {
        assertEquals(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 10)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 15)))
                        .getEndCron().toString(), "16 * * * *");

        assertNull(
                new BusinessWorkingPeriod(
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 0)),
                        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 59)))
                        .getEndCron());
    }

    @Test
    public void mergePeriods() {
        BusinessWorkingTemporal start1 = BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 10));
        BusinessWorkingTemporal end1 = BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 15));

        //the start of this period is included in the previous period
        BusinessWorkingTemporal start2 = BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 12));
        BusinessWorkingTemporal end2 = BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 20));

        //the start of this period is contiguous to the end of the previous period
        BusinessWorkingTemporal start3 = BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 21));
        BusinessWorkingTemporal end3 = BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 22));

        //this period is disjoint from the others
        BusinessWorkingTemporal start4 = BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 24));
        BusinessWorkingTemporal end4 = BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 27));

        assertEquals(
                BusinessWorkingPeriod.merge(
                        Arrays.asList(
                                new BusinessWorkingPeriod(start1, end1),
                                new BusinessWorkingPeriod(start2, end2),
                                new BusinessWorkingPeriod(start3, end3),
                                new BusinessWorkingPeriod(start4, end4))),
                new HashSet<BusinessWorkingPeriod>() {
                    {
                        add(new BusinessWorkingPeriod(start1, end3));
                        add(new BusinessWorkingPeriod(start4, end4));
                    }
                }
        );
    }

Business Working Temporal

@Test(expected = DateTimeException.class)
    public void fromNonContiguousFields() {
        BusinessWorkingTemporal.of(new HashMap<ChronoField, Integer>() {
            {
                put(ChronoField.MILLI_OF_SECOND, 0);
                put(ChronoField.MINUTE_OF_HOUR, 0);
            }
        });
    }

    @Test(expected = DateTimeException.class)
    public void fromVariableLengthFields() {
        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.DAY_OF_MONTH, 1));
    }

    @Test
    public void temporalQueries() {
        assertEquals(
                BusinessWorkingTemporal.of(toMap(ChronoField.HOUR_OF_DAY, 0, ChronoField.MINUTE_OF_HOUR, 0))
                        .query(TemporalQueries.precision()),
                ChronoUnit.MINUTES);
        assertEquals(
                BusinessWorkingTemporal.of(toMap(ChronoField.HOUR_OF_DAY, 0, ChronoField.MINUTE_OF_HOUR, 0, ChronoField.SECOND_OF_MINUTE, 0))
                        .query(TemporalQueries.precision()),
                ChronoUnit.SECONDS);
        assertNull(
                BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.HOUR_OF_DAY, 0))
                        .query(TemporalQueries.zoneId()));
    }

    @Test
    public void supportedFields() {
        BusinessWorkingTemporal bt = BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.DAY_OF_WEEK, 1));
        assertEquals(bt.isSupported(ChronoField.DAY_OF_WEEK), true);
        assertEquals(bt.isSupported(ChronoField.HOUR_OF_DAY), false);
        assertEquals(bt.isSupported(WeekFields.SUNDAY_START.dayOfWeek()), true);
        assertEquals(bt.isSupported(IsoFields.QUARTER_OF_YEAR), false);
    }

    @Test
    public void getSupportedField() {
        BusinessWorkingTemporal bt = BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.DAY_OF_WEEK, 1));
        assertEquals(bt.getLong(ChronoField.DAY_OF_WEEK), 1);
        assertEquals(bt.getLong(WeekFields.SUNDAY_START.dayOfWeek()), 2);
    }

    @Test(expected = UnsupportedTemporalTypeException.class)
    public void getUnsupportedChronoField() {
        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.DAY_OF_WEEK, 1)).getLong(ChronoField.HOUR_OF_DAY);
    }

    @Test(expected = UnsupportedTemporalTypeException.class)
    public void getUnsupportedField() {
        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.DAY_OF_WEEK, 1)).getLong(IsoFields.QUARTER_OF_YEAR);
    }

    @Test
    public void withSupportedField() {
        BusinessWorkingTemporal bt = BusinessWorkingTemporal.of(toMap(ChronoField.DAY_OF_WEEK, 1, ChronoField.HOUR_OF_DAY, 0));
        Temporal temporal = bt.with(ChronoField.DAY_OF_WEEK, 2);
        assertEquals(temporal.getLong(ChronoField.DAY_OF_WEEK), 2);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 0);

        temporal = bt.with(WeekFields.SUNDAY_START.dayOfWeek(), 4);
        assertEquals(temporal.getLong(ChronoField.DAY_OF_WEEK), 3);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 0);
    }

    @Test(expected = DateTimeException.class)
    public void withInvalidFieldValue() {
        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.SECOND_OF_MINUTE, 0)).with(ChronoField.SECOND_OF_MINUTE, 61);
    }

    @Test(expected = UnsupportedTemporalTypeException.class)
    public void withUnsupportedChronoField() {
        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.DAY_OF_WEEK, 1)).with(ChronoField.HOUR_OF_DAY, 0);
    }

    @Test(expected = UnsupportedTemporalTypeException.class)
    public void withUnsupportedField() {
        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.DAY_OF_WEEK, 1)).with(IsoFields.QUARTER_OF_YEAR, 0);
    }

    @Test
    public void supportedUnits() {
        BusinessWorkingTemporal bt = BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.DAY_OF_WEEK, 1));
        assertEquals(bt.isSupported(ChronoUnit.DAYS), true);
        assertEquals(bt.isSupported(ChronoUnit.WEEKS), false);
        assertEquals(bt.isSupported(IsoFields.QUARTER_YEARS), false);
    }

    @Test
    public void plusSupportedUnit() {
        BusinessWorkingTemporal bt = BusinessWorkingTemporal.of(toMap(ChronoField.HOUR_OF_DAY, 0, ChronoField.MINUTE_OF_HOUR, 0));
        Temporal temporal = bt.plus(1, ChronoUnit.MINUTES);
        assertEquals(temporal.getLong(ChronoField.MINUTE_OF_HOUR), 1);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 0);

        temporal = bt.plus(60, ChronoUnit.MINUTES);
        assertEquals(temporal.getLong(ChronoField.MINUTE_OF_HOUR), 0);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 1);

        temporal = bt.plus(1440, ChronoUnit.MINUTES);
        assertEquals(temporal.getLong(ChronoField.MINUTE_OF_HOUR), 0);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 0);

        temporal = bt.plus(1, ChronoUnit.HOURS);
        assertEquals(temporal.getLong(ChronoField.MINUTE_OF_HOUR), 0);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 1);

        temporal = bt.plus(24, ChronoUnit.HOURS);
        assertEquals(temporal.getLong(ChronoField.MINUTE_OF_HOUR), 0);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 0);

        temporal = bt.minus(1, ChronoUnit.MINUTES);
        assertEquals(temporal.getLong(ChronoField.MINUTE_OF_HOUR), 59);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 23);

        temporal = bt.minus(60, ChronoUnit.MINUTES);
        assertEquals(temporal.getLong(ChronoField.MINUTE_OF_HOUR), 0);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 23);

        temporal = bt.minus(1440, ChronoUnit.MINUTES);
        assertEquals(temporal.getLong(ChronoField.MINUTE_OF_HOUR), 0);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 0);

        temporal = bt.minus(1, ChronoUnit.HOURS);
        assertEquals(temporal.getLong(ChronoField.MINUTE_OF_HOUR), 0);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 23);

        temporal = bt.minus(24, ChronoUnit.HOURS);
        assertEquals(temporal.getLong(ChronoField.MINUTE_OF_HOUR), 0);
        assertEquals(temporal.getLong(ChronoField.HOUR_OF_DAY), 0);
    }

    @Test(expected = UnsupportedTemporalTypeException.class)
    public void plusUnsupportedChronoUnit() {
        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 0)).plus(1, ChronoUnit.HOURS);
    }

    @Test(expected = UnsupportedTemporalTypeException.class)
    public void plusUnsupportedUnit() {
        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.MINUTE_OF_HOUR, 0)).plus(1, IsoFields.QUARTER_YEARS);
    }

    @Test
    public void increment() {
        BusinessWorkingTemporal bt = BusinessWorkingTemporal.of(toMap(ChronoField.HOUR_OF_DAY, 0, ChronoField.MINUTE_OF_HOUR, 0)).increment();
        assertEquals(bt.getLong(ChronoField.MINUTE_OF_HOUR), 1);
        assertEquals(bt.getLong(ChronoField.HOUR_OF_DAY), 0);

        bt = BusinessWorkingTemporal.of(toMap(ChronoField.HOUR_OF_DAY, 0, ChronoField.MINUTE_OF_HOUR, 59)).increment();
        assertEquals(bt.getLong(ChronoField.MINUTE_OF_HOUR), 0);
        assertEquals(bt.getLong(ChronoField.HOUR_OF_DAY), 1);
    }

    @Test
    public void untilChronoUnit() {
        BusinessWorkingTemporal bt = BusinessWorkingTemporal.of(toMap(ChronoField.HOUR_OF_DAY, 11, ChronoField.MINUTE_OF_HOUR, 30));
        assertEquals(bt.until(LocalTime.of(13, 29), ChronoUnit.MINUTES), 119);
        assertEquals(bt.until(LocalTime.of(13, 29), ChronoUnit.HOURS), 1);
        assertEquals(bt.until(LocalTime.of(13, 29), ChronoUnit.DAYS), 0);
        assertEquals(bt.until(LocalTime.of(13, 29), IsoFields.QUARTER_YEARS), 0);
    }

    @Test(expected = UnsupportedTemporalTypeException.class)
    public void sinceInvalidTemporal() {
        BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.DAY_OF_WEEK, 1)).until(LocalTime.of(0, 0), ChronoUnit.DAYS);
    }

    @Test
    public void since() {
        assertEquals(BusinessWorkingTemporal
                .of(toMap(ChronoField.HOUR_OF_DAY, 13, ChronoField.MINUTE_OF_HOUR, 29))
                .since(LocalTime.of(11, 30, 1), ChronoUnit.HOURS), 1);

        assertEquals(BusinessWorkingTemporal
                .of(toMap(ChronoField.HOUR_OF_DAY, 13, ChronoField.MINUTE_OF_HOUR, 29))
                .since(LocalTime.of(11, 30, 1), ChronoUnit.MINUTES), 118);

        assertEquals(BusinessWorkingTemporal
                .of(toMap(ChronoField.HOUR_OF_DAY, 13, ChronoField.MINUTE_OF_HOUR, 29))
                .since(LocalTime.of(11, 30, 1), ChronoUnit.SECONDS), 7139);

        assertEquals(BusinessWorkingTemporal
                .of(toMap(ChronoField.HOUR_OF_DAY, 13, ChronoField.MINUTE_OF_HOUR, 29))
                .since(LocalTime.of(11, 30, 1), ChronoUnit.MILLIS), 7139000);

        assertEquals(BusinessWorkingTemporal
                .of(toMap(ChronoField.HOUR_OF_DAY, 11, ChronoField.MINUTE_OF_HOUR, 30))
                .since(LocalTime.of(13, 29, 1), ChronoUnit.MILLIS), 79259000);
    }

    @Test
    public void compare() {
        assertEquals(BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.HOUR_OF_DAY, 1)).compareTo(LocalTime.of(1, 0)), 0);
        assertTrue(BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.HOUR_OF_DAY, 2)).compareTo(LocalTime.of(1, 0)) > 0);
        assertTrue(BusinessWorkingTemporal.of(Collections.singletonMap(ChronoField.HOUR_OF_DAY, 0)).compareTo(LocalTime.of(1, 0)) < 0);
    }

    private static Map<ChronoField, Integer> toMap(
            ChronoField field1, Integer value1,
            ChronoField field2, Integer value2) {
        return new HashMap<ChronoField, Integer>() {
            {
                put(field1, value1);
                put(field2, value2);
            }
        };
    }

    private static Map<ChronoField, Integer> toMap(
            ChronoField field1, Integer value1,
            ChronoField field2, Integer value2,
            ChronoField field3, Integer value3) {
        return new HashMap<ChronoField, Integer>() {
            {
                put(field1, value1);
                put(field2, value2);
                put(field3, value3);
            }
        };
    }

Clone this wiki locally