mongoid_occurrences 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2a314d87b9ef1b779dd6b1d267225fa9e8d0aed71ec3cd50aa0985eb8ba18d0
4
- data.tar.gz: 68b93f8530a9d9ee95a27819e8d1351a819080e0fd37d1aabfbf29242b9df068
3
+ metadata.gz: 475b41580d7ffc83d7c4d794425a52f53a6e56e31d0a979f18d44f99339a1904
4
+ data.tar.gz: 869e8ff6af04f48fa176cefc0753833b320f225d937e956449820c8f1e2a3206
5
5
  SHA512:
6
- metadata.gz: 22a2554e94b5512fc9ab6393050b1c3b959a3410ceda5b31508d5b93a4164b8cb2cc1a94293f411859a2eeb58f6daf178dcb3c1a8307a2dc4b47c60c4706ec7d
7
- data.tar.gz: 1a3b5c2b93f38e83d35558fa7d94c878b50abda16d7509657fea8b017091e7b0558720e34696c1ee1920395f97fb14b012b2168324cb31c20c76996e66f18b6f
6
+ metadata.gz: 6a80de303c833964bd19546d4f76fd818e0bafff5c81f52204f206e2f90d24bc504ce33b4a13473c04d5a4f896f815ea26d68b95440d07dd076dd2ea785cd7d3
7
+ data.tar.gz: 1b5499f8123d85bcbd9f4b68fece8269f8471e32e2e8d130a30fd69170aa70c0be5c3c0c5fb6a3263fd4b680111bfeec56194862fafe83f9a6f08f00926f54d4
data/.travis.yml CHANGED
@@ -2,7 +2,7 @@ language: ruby
2
2
  cache: bundler
3
3
  script: 'bundle exec rake'
4
4
  rvm:
5
- - 2.5.1
5
+ - 2.6.0
6
6
  services:
7
7
  - mongodb
8
8
 
@@ -15,5 +15,5 @@ notifications:
15
15
 
16
16
  matrix:
17
17
  include:
18
- - rvm: 2.5.1
18
+ - rvm: 2.6.0
19
19
  env: MONGOID_VERSION=7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.1.1
4
+
5
+ * FIX: issues with handling time zone in daily occurrences and queries
6
+ * ADD: validation on `Occurrence` for `dtend` being after `dtstart`
7
+
3
8
  ## 1.1.0
4
9
 
5
10
  * CHANGE: `#embedded_in_event` requires `name` (`#embedded_in_event(name, options)`)
@@ -3,9 +3,7 @@ module MongoidOccurrences
3
3
  module HasDailyOccurrences
4
4
  def daily_occurrences
5
5
  adjust_dates_for_all_day!
6
-
7
- daily_occurrences_from_schedule +
8
- daily_occurrences_from_date_range
6
+ daily_occurrences_from_schedule + daily_occurrences_from_date_range
9
7
  end
10
8
 
11
9
  private
@@ -13,14 +11,11 @@ module MongoidOccurrences
13
11
  def daily_occurrences_from_schedule
14
12
  return [] unless dtstart? && dtend?
15
13
  return [] unless recurring?
16
-
17
14
  schedule.occurrences(schedule_dtend).map do |occurrence|
18
- MongoidOccurrences::DailyOccurrence.new(
19
- dtstart: occurrence.start_time.change(hour: dtstart.hour, min: dtstart.minute),
20
- dtend: occurrence.end_time.change(hour: dtend.hour, min: dtend.minute),
21
- occurrence_id: id,
22
- operator: operator
23
- )
15
+ occurrence_dtstart = occurrence.start_time.in_time_zone(Time.zone).change(hour: dtstart.hour, minute: dtstart.minute)
16
+ occurrence_dtend = occurrence.end_time.in_time_zone(Time.zone).change(hour: dtend.hour, minute: dtend.minute)
17
+
18
+ build_daily_occurrence(occurrence_dtstart, occurrence_dtend, id, operator)
24
19
  end
25
20
  end
26
21
 
@@ -32,17 +27,15 @@ module MongoidOccurrences
32
27
  is_single_day = (date_range.first == date_range.last)
33
28
 
34
29
  date_range.map do |date|
35
- occurence_dtstart = is_single_day || date == date_range.first ? dtstart : date.beginning_of_day
36
- occurence_dtend = is_single_day || date == date_range.last ? dtend : date.end_of_day
37
-
38
- MongoidOccurrences::DailyOccurrence.new(
39
- dtstart: occurence_dtstart,
40
- dtend: occurence_dtend,
41
- occurrence_id: id,
42
- operator: operator
43
- )
30
+ occurrence_dtstart = is_single_day || date == date_range.first ? dtstart : date.beginning_of_day
31
+ occurrence_dtend = is_single_day || date == date_range.last ? dtend : date.end_of_day
32
+ build_daily_occurrence(occurrence_dtstart, occurrence_dtend, id, operator)
44
33
  end
45
34
  end
35
+
36
+ def build_daily_occurrence(dtstart, dtend, occurrence_id, operator)
37
+ MongoidOccurrences::DailyOccurrence.new(dtstart: dtstart, dtend: dtend, occurrence_id: occurrence_id, operator: operator)
38
+ end
46
39
  end
47
40
  end
48
41
  end
@@ -17,7 +17,7 @@ module MongoidOccurrences
17
17
 
18
18
  def schedule_dtstart
19
19
  read_attribute(:schedule_dtstart) ||
20
- (dtstart.try(:to_time) || Time.now)
20
+ (dtstart.try(:to_time) || Time.zone.now)
21
21
  end
22
22
 
23
23
  def schedule_dtend
@@ -30,6 +30,8 @@ module MongoidOccurrences
30
30
 
31
31
  validates :dtstart, presence: true
32
32
  validates :dtend, presence: true
33
+
34
+ validate :dtend_must_be_after_dtstart
33
35
  end
34
36
  end
35
37
 
@@ -49,5 +51,15 @@ module MongoidOccurrences
49
51
  self.dtstart = dtstart.beginning_of_day
50
52
  self.dtend = dtend.end_of_day
51
53
  end
54
+
55
+ private
56
+
57
+ def dtend_must_be_after_dtstart
58
+ return unless dtstart.present? && dtend.present?
59
+
60
+ if dtend < dtstart
61
+ errors.add(:dtend, :must_be_after_dtstart)
62
+ end
63
+ end
52
64
  end
53
65
  end
@@ -14,8 +14,8 @@ module MongoidOccurrences
14
14
  end
15
15
 
16
16
  def criteria
17
- base_criteria.lte(dtstart_field => adjusted_dtend)
18
- .gte(dtend_field => adjusted_dtstart)
17
+ base_criteria.lte(dtstart_field => adjusted_dtend.utc)
18
+ .gte(dtend_field => adjusted_dtstart.utc)
19
19
  end
20
20
 
21
21
  private
@@ -10,7 +10,7 @@ module MongoidOccurrences
10
10
  end
11
11
 
12
12
  def criteria
13
- OccursBetween.criteria(base_criteria, adjusted_dtstart, adjusted_dtend, options)
13
+ OccursBetween.criteria(base_criteria, adjusted_dtstart.utc, adjusted_dtend.utc, options)
14
14
  end
15
15
 
16
16
  private
@@ -12,7 +12,7 @@ module MongoidOccurrences
12
12
  end
13
13
 
14
14
  def criteria
15
- base_criteria.lte(dtend_field => adjusted_date_time)
15
+ base_criteria.lte(dtend_field => adjusted_date_time.utc)
16
16
  end
17
17
 
18
18
  private
@@ -1,3 +1,3 @@
1
1
  module MongoidOccurrences
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_occurrences
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-01-23 00:00:00.000000000 Z
12
+ date: 2019-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ice_cube