Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joda Period generators #5

Merged
merged 4 commits into from
Jul 7, 2016
Merged

Joda Period generators #5

merged 4 commits into from
Jul 7, 2016

Conversation

noelmarkham
Copy link
Collaborator

@noelmarkham noelmarkham commented Jul 4, 2016

Generators for Joda Period classes:

  • Full-range generators for the different Period types (Years, Months, Weeks, Days, Hours, Minutes, Seconds)
  • Full-range generator for a Period consisting of years, days, hours, minutes, seconds, milliseconds
  • A generator method taking a DateTime and a Period, and this will generate a DateTime between the given DateTime and the offset given by the period. Note this is different from previous discussions (which was DateTime ± Period), as I believe this makes things a little clearer.
   DateTime
      ▼
<-----|------------------------------------------|------------->

      ~------------------------------------------~
                        ▲
                 Period (range)

Everything seems quite straightforward right now, but I'd love to get some early input on the code, as well as some fundamental things like:

  • Package name: One idea could be to change the package to org.scalacheck.datetime or similar, copying other libraries such as scalacheck-shapeless.
  1. Class names. I expect I'll add an ArbitraryDateTime sometime soon containing sensible default arbitraries.
  2. Other generator methods. I was thinking of adding some "helper" generators which defer to genDateTimeWithinPeriod, by calculating the correct parameters, such as methods which take:

A period either side of a DateTime (as noted above):

                       DT
                       ▼
<-----|----------------|----------------|------------->

      ~----------------~----------------~
              ▲               ▲
              P               P

Two periods, so that the offset either side of the given DateTime can be different:

                       DT
                       ▼
<-----|----------------|-------|------------->

      ~----------------~-------~
              ▲            ▲
              P1           P2

Note these two suggestions are not completely logical as a period has a notion of being positive or negative, and there's no abstraction that represents just the magnitude of a period (what does it mean to have a negative period for the time before the given DateTime???), I'm half thinking of just including documentation as to how to do this, to keep the API clean and reducing confusion due to ambiguity.

Finally, just to mention this code so far is only for Joda's classes, I intend to update this to generate different classes from other libraries, such as Java 8's Date and Time API.

Closes #1

@noelmarkham noelmarkham self-assigned this Jul 4, 2016
@raulraja
Copy link
Contributor

raulraja commented Jul 4, 2016

LGTM! This is awesome. Should add references back to the ScalaCheck docs to point to the lib once is stable and we have a solid version.

@noelmarkham noelmarkham merged commit 16b0c23 into master Jul 7, 2016
@noelmarkham noelmarkham deleted the period-generators branch July 7, 2016 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants