... | ... | @@ -201,4 +201,50 @@ NOT daterange(LOWER("events"."period")::date),UPPER("events"."period")::date) && |
|
|
NOT daterange((LOWER("events"."period") - "events"."interval")::date),(UPPER("events"."period") + "events"."interval")::date) && value
|
|
|
- OR -
|
|
|
NOT daterange((LOWER("events"."period") - "events"."interval")::date),(UPPER("events"."period") + "events"."interval")::date) && daterange(left, right)
|
|
|
```
|
|
|
|
|
|
### Instance methods
|
|
|
|
|
|
A couple of instance methods are provided as well. One of the options is to also use the new provided methods for the [Range](https://github.com/crashtech/torque-postgresql/wiki/Range) class.
|
|
|
|
|
|
#### `:current?` as `.current_period?`
|
|
|
Check if the value on the column represents a current period.
|
|
|
```ruby
|
|
|
(period.min < Time.zone.now && period.max > Time.zone.now) || default
|
|
|
```
|
|
|
|
|
|
#### `:current_on?` as `.current_period_on?(value)`
|
|
|
Similar to the above one, but allowing a valur to be passed.
|
|
|
```ruby
|
|
|
(period.min < value && period.max > value) || default
|
|
|
```
|
|
|
|
|
|
#### `:start` as `.period_start`
|
|
|
Get the beginning of the period.
|
|
|
```ruby
|
|
|
period.min
|
|
|
```
|
|
|
|
|
|
#### `:finish` as `.period_finish`
|
|
|
Get the ending of the period.
|
|
|
```ruby
|
|
|
period.max
|
|
|
```
|
|
|
|
|
|
#### `:real` as `.real_period` **(ONLY WITH THRESHOLD)**
|
|
|
Get the real range period while considering the threshold.
|
|
|
```ruby
|
|
|
((period.min - threshold)..(period.max + threshold))
|
|
|
```
|
|
|
|
|
|
#### `:real_start` as `.period_real_start`
|
|
|
Get the beginning of the period while considering the threshold.
|
|
|
```ruby
|
|
|
period.min - threshold
|
|
|
```
|
|
|
|
|
|
#### `:real_finish` as `.period_real_finish`
|
|
|
Get the ending of the period while considering the threshold.
|
|
|
```ruby
|
|
|
period.max + threshold
|
|
|
``` |
|
|
\ No newline at end of file |