toBeBefore

Expects that the subject of this expectation (a ChronoLocalDate) is before the expected.

Return

an Expect for the subject of this expectation.

Since

0.17.0

Samples

expect(LocalDate.of(2021, Month.JUNE, 6)) toBeBefore LocalDate.of(2021, Month.JULY, 1)

infix fun <T : ChronoLocalDate> Expect<T>.toBeBefore(expected: String): Expect<T>(source)

Expects that the subject of this expectation (a ChronoLocalDate) is before the expected given as String.

Return

an Expect for the subject of this expectation.

Since

0.17.0

Throws

in case expected is not in the form of yyyy-mm-dd

Samples

expect(LocalDate.of(2021, Month.JUNE, 6)) toBeBefore "2021-07-01"

Expects that the subject of this expectation (a ChronoLocalDateTime) is before the expected.

Return

an Expect for the subject of this expectation.

Since

0.17.0

Samples

expect(LocalDateTime.of(2021, Month.JUNE, 6, 10, 5, 35, 103)) toBeBefore LocalDateTime.of(2021, Month.JUNE, 6, 12, 10, 0, 0)

Expects that the subject of this expectation (a ChronoLocalDateTime) is before the expected given as String in (modified) ISO 8601 format. The string will be converted to a LocalDateTime according to ISO 8601 but with a slight deviation. The alternative notation (e.g. 20200401120001 instead of 2020-04-01T12:00:01) is not supported and we accept a date without time in which case 00:00:00 is used. Following the supported formats from the longest to the shortest: yyyy-mm-ddThh:mm:ss.sss (up to 9 digits for nanoseconds) yyyy-mm-ddThh:mm:ss yyyy-mm-ddThh:mm yyyy-mm-dd

Return

an Expect for the subject of this expectation.

Since

0.17.0

Throws

in case an unsupported format is given.

Samples

expect(LocalDateTime.of(2021, Month.JUNE, 6, 10, 5, 35, 103)) toBeBefore "2021-06-06T12:10:00.000000000"

// format yyyy-MM-ddThh:mm:SS can be used, in which case .000000000 is used for the omitted part
expect(LocalDateTime.of(2021, Month.JUNE, 6, 10, 5, 35, 103)) toBeBefore "2021-06-06T12:10:00"

// format yyyy-MM-ddThh:mm can be used, in which case 00.000000000 is used for the omitted part
expect(LocalDateTime.of(2021, Month.JUNE, 6, 10, 5, 35, 103)) toBeBefore "2021-06-06T12:10"

// format yyyy-MM-dd can be used, in which case 00:00:00.000000000 is used for the omitted part
expect(LocalDateTime.of(2021, Month.JUNE, 6, 10, 5, 35, 103)) toBeBefore "2021-06-07"

Expects that the subject of this expectation (a ChronoZonedDateTime) is before the expected.

Return

an Expect for the subject of this expectation.

Since

0.17.0

Samples

expect(ZonedDateTime.of(2021, 6, 6, 10, 5, 35, 103, ZoneId.of("America/Sao_Paulo"))) toBeBefore ZonedDateTime.of(2021, 6, 6, 12, 10, 0, 0, ZoneId.of("America/Sao_Paulo"))

Expects that the subject of this expectation (a ChronoZonedDateTime) is before or equals the expected given as String.

The format is composed of {DateTime}{ZoneDesignator}.

DateTime:

  • yyyy-mm-ddThh:mm:ss.SSS (up to 9 digits for nanoseconds)

  • yyyy-mm-ddThh:mm:ss

  • yyyy-mm-ddThh:mm

  • yyyy-mm-dd

And for ZoneDesignator:

  • Z

  • +hh

  • +hh:mm

  • -hh

  • -hh:mm

Here are some examples on how it can look combined

  • 2020-01-02T03:04:05Z

  • 2020-01-02T03:04Z

  • 2020-01-02Z

  • 2020-01-02+01:30

Return

an Expect for the subject of this expectation.

Since

0.17.0

Throws

in case an unsupported format is given.

Samples

expect(ZonedDateTime.of(2021, 6, 6, 10, 5, 35, 103, ZoneId.of("America/Sao_Paulo"))) toBeBefore "2021-06-06T12:10:00.000000000-03:00"

// format yyyy-MM-ddThh:mm:SS can be used, in which case .000000000 is used for the omitted part
expect(ZonedDateTime.of(2021, 6, 6, 10, 5, 35, 103, ZoneId.of("America/Sao_Paulo"))) toBeBefore "2021-06-06T12:10:00-03:00"

// format yyyy-MM-ddThh:mm can be used, in which case 00.000000000 is used for the omitted part
expect(ZonedDateTime.of(2021, 6, 6, 10, 5, 35, 103, ZoneId.of("America/Sao_Paulo"))) toBeBefore "2021-06-06T12:10-03:00"

// format yyyy-MM-dd can be used, in which case 00:00:00.000000000 is used for the omitted part
expect(ZonedDateTime.of(2021, 6, 6, 10, 5, 35, 103, ZoneId.of("America/Sao_Paulo"))) toBeBefore "2021-06-07-03:00"