Atrium: accept date and time as string in ISO 8601 format for ChronoZonedDateTime

Created on 28 Apr 2020  路  10Comments  路  Source: robstoll/atrium

Platform (jvm, js, android): jvm
Extension (none, kotlin 1.3, jdk8): jdk8

Code related feature

expect(ZonedDateTime.now()).isAfter("2020-04-28T12:00Z")

//instead of

expect(ZonedDateTime.now()).isAfter(ZonedDateTime.of(2020,4,28,12,0,0,0, ZoneId.of("Z")))

Following the things you need to do:

atrium-logic:

  • [ ] duplicate each method in ChronoZonedDateTimeAssertions and:

    • [ ] accept a String instead of a ChronoZonedDateTime and parse it to ZonedDateTime and pass it to the existing overload where the following formats shall be supported. This is a slight deviation of ISO 8601, e.g. we do not want to support the alternative notation e.g. 20200401120001Z instead of 2020-04-01T12:00:01Z

      The format is composed of {DateTime}{ZoneDesignator}, first the spec for DateTime:


  And for ZoneDesignator:
  * Z
  * Z+hh
  * Z+hh:mm
  * Z-hh
  * Z-hh:mm

  Following a few examples how it looks combined:
  - yyyy-mm-ddThh:mm:ssZ
  - yyyy-mm-ddThh:mmZ+01
  - yyyy-mm-ddZ-04:30

  Right now we don't intend to support things like Europe/Zurich as ZoneDesignators (would be supported by jdk). So do a check upfront if in correct format and throw a DateTimeParseException if wrong and only then use ZonedDateTime.parse
    Note that #481 deals also with parsing DateTime. You should reuse the logic from there.

api-fluent

  • [ ] duplicate each method in chronoZonedDateTimeAssertions.kt and:

    • [ ] accept a String instead of a ChronoZonedDateTime - call the corresponding logic function

    • [ ] change since to 0.14.0 (adopt to current milestone)

  • [ ] add the string version to ChronoZonedDateTimeAssertionsSpec:

    • [ ] add an object StringSpec, create functions in the companion object which corresponds to the signature of the existing functions (i.e. accept a ChronoZonedDateTime) where inside you turn the ChronoZonedDateTime into a string in ISO format and pass it to your new function

  • [ ] create ChronoZonedDateTimeAsStringAssertionSpec by copying ch.tutteli.atrium.specs.integration.ChronoLocalDateTimeAsStringAssertionSpec and adapt it, it should cover the following cases for a wrong format:

    • one passes a ZonedDateTime in format yyyymmddhhmmssSSSZ

    • one passes a ZonedDateTime in format yyyymmddhhmmssZ

    • one passes a ZonedDateTime in format yyyymmddhhmmZ

    • one passes a ZonedDateTime in format yyyymmddZ

    • one passes a ZonedDateTime in format yyyy-m-ddThh:mmZ

    • one passes a ZonedDateTime in format yyyy-mm-dThh:mmZ

    • one passes a ZonedDateTime in format yy-mm-ddThh:mmZ

    • one passes a ZonedDateTime in format yyyy-mm-ddTh:mmZ

    • one passes a ZonedDateTime in format yyyy-mm-ddThh:mZ

    • one passes a ZonedDateTime in format yyyy-mm-ddThh:mm:sZ

    • one passes a ZonedDateTime in format yyyy-mm-ddthh:mmZ (note lower case t)

    • one passes a ZonedDateTime in format yyyy-mm-ddThh:mmZ+h

    • one passes a ZonedDateTime in format yyyy-mm-ddThh:mmZ+h:mm

    • one passes a ZonedDateTime in format yyyy-mm-ddThh:mmZ+hh:m

    • one passes a ZonedDateTime in format yyyy-mm-ddThh:mmZ-h

    • one passes a ZonedDateTime in format yyyy-mm-ddThh:mmZ-h:mm

    • one passes a ZonedDateTime in format yyyy-mm-ddThh:mmZ-hh:m

    • [ ] add describe("allowed shortcuts") with at least the following test cases:

    • one passes a ZonedDateTime in format yyyy-mm-ddThh:mm:ssZ

    • one passes a ZonedDateTime in format yyyy-mm-ddThh:mmZ

    • one passes a ZonedDateTime in format yyyy-mm-ddZ

  • [ ] adopt ChronoZonedDateTimeAssertionsSpec (see ch.tutteli.atrium.api.fluent.en_GB.ChronoLocalDateTimeAssertionSpec as a guideline)

    • [ ] add an object ChronoZonedDateTimeAsStringSpec which extends the above copied spec

    • [ ] add the string version to the ambiguityTests

api-infix

  • same same but different

Your first contribution?

  • Write a comment I'll work on this if you would like to take this issue over.
    This way we get the chance to revise the description in case things have changed in the meantime, we might give you additional hints and we can assign the task to you, so that others do not start as well.
  • See Your first code contribution for guidelines.
  • Do not hesitate to ask questions here or to contact us via Atrium's slack channel if you need help
    (Invite yourself in case you do not have an account yet).

Hint
Have a look at the following PR for ChronoLocalDateTime:
https://github.com/robstoll/atrium/pull/556/files

good first issue help wanted

All 10 comments

You can assign me this one :-)

Sure 馃檪馃憤
I have sent you a collaborator invitation. Once accepted you can assign task yourself

Sure 馃檪馃憤
I have sent you a collaborator invitation. Once accepted you can assign task yourself

I didn't get the mail, because I haven't updated my Profile Email in a long time. If you don't mind, can you send the invitation again? Thank you 馃檪

@Valefant I have re-sent it yesterday, did you get it? Forget it, I just saw that you have accepted the invitation.

@Valefant I have re-sent it yesterday, did you get it? Forget it, I just saw that you have accepted the invitation.

I got it. Thank you @robstoll 馃檪

@Valefant do you need help with this one? No stress, I just want to offer my help

@robstoll I could takeover if @Valefant doesn't want to continue it. Or I'll gladly take some other entry-level issue if you have something available.

@khliwa feel free to start, in the worst case you both do the same and you can compare the two solutions

@robstoll Sry for replying so late. I would start working on it now.
@khliwa What's your status? :-)

This issue can be closed as the pull request was accepted

Was this page helpful?
0 / 5 - 0 ratings

Related issues

robstoll picture robstoll  路  4Comments

robstoll picture robstoll  路  3Comments

dalewking picture dalewking  路  6Comments

robstoll picture robstoll  路  7Comments

robstoll picture robstoll  路  5Comments