gouv-calendar-compilator 1.0.3 → 1.0.4

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: 719614f1e5fe0516488dc08ffec1858e799d846142414f8f646530eacb289014
4
- data.tar.gz: a6bdee0f7bf814f57798b06d24f21cdf287ffff9e614f58b20fd6646b8321e09
3
+ metadata.gz: 7c1b039734ff757775f636a2c51a770693989af6b681ace240a11b902e9a13c0
4
+ data.tar.gz: e0e374e47fef2515d86adfc4388150fba03cb012d9d0bf00f80501f2c2c67cc8
5
5
  SHA512:
6
- metadata.gz: 27825a82df74477ac8761be1f588af5ecd4ea8dbbab452642816bb10a61650f322e7d2dbe0facb9ee95f829628ff8e66bcfde5281f05a9c88144caef8cd5a9fc
7
- data.tar.gz: 066332f68d70708fe297bade2d8e4e4da1f7402facc7e44473d9f2604d439f55468a01727bd71ce40457b24a759a8c3be63a294992906aa72bcb82c54a1ae405
6
+ metadata.gz: 0a9b85b4249d1b2a5414d112aff6a7b5daebec944cd42e154727b61b31a1b607c4c8a55e7c20b9117452623a309d3c0cfcfd35ffa6f34610970f5d29b3a7bca5
7
+ data.tar.gz: a233828c6292b4ed30e7fbd0b90ac4ff594d85813ebb689469081c24d65a288ce9677c2713506181b206339135963d6120a20727681768bc90e350fbb29d9f5d
@@ -82,17 +82,10 @@ module GouvCalendarCompilator
82
82
  included_in_vacation = true
83
83
  splitted_vacation = ndo_split_holidays_period_insert_day_off(calendar[zone_name][index], day_off_date)
84
84
 
85
- # replacing current holiday with the first part of the splitted one
86
- # except if day off is first day of holiday (then deleting the first part of the splitted vacation)
87
- if calendar[zone_name][index][:start] == day_off_date.to_s
88
- calendar[zone_name].delete(calendar[zone_name][index])
89
- else
90
- calendar[zone_name][index] = splitted_vacation[0]
91
- end
92
- # inserting national day off
93
- calendar[zone_name] << splitted_vacation[1]
94
- # inserting other part of the splitted vacation
95
- calendar[zone_name] << splitted_vacation[2]
85
+ keeped_periods = determines_what_to_keep(splitted_vacation, calendar[zone_name][index], day_off_date)
86
+ # remove the current vacation before adding the correct parts of the splitted_vacation
87
+ calendar[zone_name].delete(calendar[zone_name][index])
88
+ calendar[zone_name].push(*keeped_periods)
96
89
  end
97
90
 
98
91
  # if day off not in the middle of a vacation period, simply insert it inside the dataset
@@ -106,6 +99,31 @@ module GouvCalendarCompilator
106
99
  end
107
100
  calendar
108
101
  end
102
+
103
+ # Determines what parts of the splitted vacation to keep to replace current vacation
104
+ #
105
+ # - if vacation is 1 day and day off is the first and the last day of it, then keep only the day_off
106
+ # - if day off is first day of holiday, then do not keep the first part of the splitted vacation
107
+ # - if day off is last day of holiday, then do not keep the last part of the splitted vacation
108
+ def determines_what_to_keep(splitted_vacation, period, day_off_date)
109
+ # inserting national day off
110
+ elements_to_add = [splitted_vacation[1]]
111
+ return elements_to_add if period[:start] == day_off_date.to_s && period[:end] == (day_off_date + 1).to_s
112
+
113
+ if period[:start] == day_off_date.to_s
114
+ # inserting last part of the splitted vacation
115
+ elements_to_add << splitted_vacation[2]
116
+ elsif period[:end] == (day_off_date + 1).to_s
117
+ # inserting first part of the splitted vacation
118
+ elements_to_add << splitted_vacation[0]
119
+ else
120
+ # inserting first & last part of the splitted vacation
121
+ elements_to_add << splitted_vacation[0]
122
+ elements_to_add << splitted_vacation[2]
123
+ end
124
+
125
+ elements_to_add
126
+ end
109
127
  end
110
128
  end
111
129
  end
@@ -74,13 +74,22 @@ module GouvCalendarCompilator
74
74
  approximate_start_date.to_date.to_s
75
75
  end
76
76
 
77
- # Trims dataset to desired time era
77
+ # Trims dataset to desired time era and remove possibly wrong data.
78
+ #
79
+ # Example of bad data:
80
+ # "end_date"=>"2023-07-08T00:00:00+02:00", "start_date"=>"2023-07-08T00:00:00+02:00",
81
+ # "zones"=>"Zone C", "description"=>"Debut des Vacances d'ete"
82
+ #
83
+ # Almost "OK" data but not needed here, and that should appear as a national day off somewhere else.
84
+ # "end_date"=>"2020-03-19T00:00:00+01:00", "start_date"=>"2020-03-19T00:00:00+01:00",
85
+ # "zones"=>"Guadeloupe", "description"=>"Mi-careme"
78
86
  def sh_trim_not_necessary_data(raw_sh_dataset)
79
87
  date_range = ::GouvCalendarCompilator::DATETIME_START...::GouvCalendarCompilator::DATETIME_END
80
88
  filtered_data =
81
89
  raw_sh_dataset.select do |record|
82
90
  date_range.include?(::Date.parse(record['fields']['start_date'])) &&
83
- (record['fields']['end_date'] ? date_range.include?(::Date.parse(record['fields']['end_date'])) : true)
91
+ (record['fields']['end_date'] ? date_range.include?(::Date.parse(record['fields']['end_date'])) : true) &&
92
+ record['fields']['start_date'] != record['fields']['end_date']
84
93
  end
85
94
  filtered_data.uniq do |record|
86
95
  [
data/lib/version.rb CHANGED
@@ -6,6 +6,6 @@
6
6
  # frozen_string_literal: true
7
7
 
8
8
  module GouvCalendarCompilator
9
- VERSION = '1.0.3'
9
+ VERSION = '1.0.4'
10
10
  public_constant :VERSION
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gouv-calendar-compilator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin ALBERT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-22 00:00:00.000000000 Z
11
+ date: 2022-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct