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

Implement day-increment duration calculations #17

Merged
merged 8 commits into from
Mar 20, 2015
Merged

Conversation

craiglittle
Copy link
Collaborator

The impetus for this feature came from #14.

This implements day-increment calculations with a similar syntax to currently-supported units:

Biz.time(5, :days).after(Time.now)

If the equivalent time in the specified number of days is in business hours, that time is returned. If that time is not in business hours, the next time in the calculation direction (e.g. before or after) will be returned.

Refer to the original issue for a more thorough discussion of the behavior and reasoning.

@alex-stone

/cc @take

Now:

```ruby
Biz::Schedule.new
```

returns a default schedule.
This brings in Clavius and sets up a number of convenience methods to
make it easier to perform date-level calculations. Where possible,
those methods are used to simplify methods.
Here's the syntax:
```ruby
Biz.time(5, :days).after(Time.now)
```

Behavior notes:
* The next business time at least 24 hours in the indicated direction
  will be returned.
* If the equivalent time in the specified number of days isn't a
  business time, the *next* business time in the direction of the
  calculation (e.g. before or after) will be returned.
@take
Copy link
Contributor

take commented Mar 20, 2015

Tested this in my local, looks sweet! :D :D

irb(main):012:0> Biz.time(1, :day).after(Time.utc(2015, 3, 9, 12))
=> 2015-03-10 12:00:00 UTC
irb(main):013:0> Biz.time(1, :day).after(Time.utc(2015, 3, 9, 20))
=> 2015-03-11 09:00:00 UTC
irb(main):014:0> Biz.time(1, :day).after(Time.utc(2015, 3, 8, 12))
=> 2015-03-09 12:00:00 UTC
irb(main):015:0> Biz.time(1, :omg).after(Time.utc(2015, 3, 8, 12))
ArgumentError: The unit is not supported.

Directional `Periods` objects were made smarter by intuiting which
the direction in which their timelines should run.

For example:

Before, you had to do this:
```ruby
Biz.periods.after(Time.now).timeline.forward
```

Now, you can do do this:
```ruby
Biz.periods.after(Time.now).timeline
```

However, users of the "dumb" versions should still be able to use the
old interface without issue until we reach v2.0.
@alex-stone
Copy link

👍 💥

craiglittle added a commit that referenced this pull request Mar 20, 2015
Implement day-increment duration calculations
@craiglittle craiglittle merged commit cc8ee61 into master Mar 20, 2015
@craiglittle craiglittle deleted the craig/day-calcs branch March 20, 2015 19:07
@craiglittle
Copy link
Collaborator Author

Released in v1.2.0!

@take
Copy link
Contributor

take commented Mar 21, 2015

woot thanks! 🙆‍♀️

@take take mentioned this pull request Mar 23, 2015
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.

3 participants