README.md in timespan-0.2.8 vs README.md in timespan-0.3.1
- old
+ new
@@ -111,10 +111,47 @@
account.period.start_date
account.period.end_date
account.period.days
account.period.duration # => Duration
+## Searching periods
+
+```ruby
+Account.where(:'period.from'.lt => 6.days.ago.to_i)
+Account.where(:'period.from'.gt => 3.days.ago.to_i)
+
+# in range
+Account.where(:'period.from'.gt => 3.days.ago.to_i, :'period.to'.lt => Time.now.utc.to_i)
+```
+
+Make it easier by introducing a class helper:
+
+```ruby
+class Account
+ include Mongoid::Document
+ field :period, :type => TimeSpan
+
+ def self.between from, to
+ Account.where(:'period.from'.gt => from.to_i, :'period.to'.lte => to.to_i)
+ end
+end
+```
+
+`Account.between(6.days.ago, 1.day.ago)`
+
+Alternatively auto-generate a `#between` helper for the field:
+
+```ruby
+class Account
+ include Mongoid::Document
+ field :period, :type => TimeSpan, :between => true
+```
+
+`Account.period_between(6.days.ago, 1.day.ago)`
+
+See the `mongoid_search_spec.rb` for examples:
+
## Chronic duration
Is used to parse duration strings if Spanner can't be handle it
`ChronicDuration.parse('4 minutes and 30 seconds')
@@ -145,9 +182,30 @@
1.week.each {|week| ...} #=> Automatically chooses week as its iterator
7.days.each {|day| ...} #=> Automatically chooses day as its iterator
1.week.each_day {|day| ...} #=> Forcing the week to iterate through days
1.week.each(10.hours) {|ten_hour_segment| ...} #=> Using a custom iterator of 10 hours. There would be 17 of them, but notice that the last iteration will only be 8 hours.
``
+
+## Configuration and overrides
+
+Timespan by default uses `Time.now.utc` to set the current time, fx used when either `end_date` or `start_date` otherwise would be nil. This is used in order to work with Mongoid (see [issue #400](https://github.com/mongoid/mongoid/issues/400))
+
+You can customize `now` to return fx `Time.now`, `Date.today` or whatever suits you.
+
+```ruby
+class Timespan
+ def now
+ Time.now # or Date.today
+ end
+end
+```
+
+By default the `TimeSpan` is stored using `:from` and `:to` for the start and end times. This can be customized as follows:
+
+```ruby
+TimeSpan.start_field = :start
+TimeSpan.end_field = :end
+```
## Contributing to Timespan
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.