Skip to content

Commit

Permalink
feat: use postal code as province parameter for french country
Browse files Browse the repository at this point in the history
  • Loading branch information
Thibaut authored and Thibaut MADELAINE committed Dec 19, 2022
1 parent 9fb9d2c commit e285320
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 3 deletions.
31 changes: 28 additions & 3 deletions sql/countries/france.pgsql
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ DECLARE
WEEKEND INTEGER[] := ARRAY[0, 6];
-- Provinces
PROVINCES TEXT[] := ARRAY[
'Métropole', 'Alsace-Moselle', 'Guadeloupe', 'Guyane', 'Martinique',
'Mayotte', 'Nouvelle-Calédonie', 'La Réunion', 'Polynésie Française',
'Métropole', 'Alsace-Moselle', 'Guadeloupe', 'Martinique', 'Guyane',
'La Réunion', 'Mayotte', 'Nouvelle-Calédonie', 'Polynésie Française',
'Saint-Barthélémy', 'Saint-Martin', 'Wallis-et-Futuna'
];
-- Primary Loop
Expand All @@ -61,6 +61,31 @@ DECLARE
t_holiday holidays.holiday%rowtype;

BEGIN
IF p_province ~ '^[0-9]{5}$' THEN
-- set province from postal code
IF LEFT(p_province, 2) IN ('57', '67', '68') THEN
p_province := 'Alsace-Moselle';
ELSE
CASE LEFT(p_province, 3)
WHEN '971' THEN
IF p_province = '97133'
THEN p_province := 'Saint-Barthélémy';
ELSIF p_province = '97150'
THEN p_province := 'Saint-Martin';
ELSE p_province := 'Guadeloupe';
END IF;
WHEN '972' THEN p_province := 'Martinique';
WHEN '973' THEN p_province := 'Guyane';
WHEN '974' THEN p_province := 'La Réunion';
WHEN '976' THEN p_province := 'Mayotte';
WHEN '988' THEN p_province := 'Nouvelle-Calédonie';
WHEN '987' THEN p_province := 'Polynésie Française';
WHEN '986' THEN p_province := 'Wallis-et-Futuna';
ELSE p_province := 'Métropole';
END CASE;
END IF;
END IF;

FOREACH t_year IN ARRAY t_years
LOOP
-- Defaults for additional attributes
Expand Down Expand Up @@ -245,4 +270,4 @@ BEGIN
END LOOP;
END;

$$ LANGUAGE plpgsql;
$$ LANGUAGE plpgsql;
67 changes: 67 additions & 0 deletions test/expected/french_holiday_with_postal_code.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
BEGIN
CREATE EXTENSION
datestamp | reference | description | authority | day_off | observation_shifted | start_time | end_time
------------+-----------------------+--------------------+-----------+---------+---------------------+------------+----------
01-01-2023 | New Year's Day | Jour de l'an | national | t | f | 00:00:00 | 24:00:00
05-01-2023 | Labour Day | Fête du Travail | national | t | f | 00:00:00 | 24:00:00
05-08-2023 | Victory in Europe Day | Armistice 1945 | national | t | f | 00:00:00 | 24:00:00
07-14-2023 | Bastille Day | Fête nationale | national | t | f | 00:00:00 | 24:00:00
11-11-2023 | Remembrance Day | Armistice 1918 | national | t | f | 00:00:00 | 24:00:00
04-10-2023 | Easter Monday | Lundi de Pâques | national | t | f | 00:00:00 | 24:00:00
05-29-2023 | Pentecost | Lundi de Pentecôte | national | t | f | 00:00:00 | 24:00:00
05-18-2023 | Ascension | Ascension | national | t | f | 00:00:00 | 24:00:00
08-15-2023 | Assumption | Assomption | national | t | f | 00:00:00 | 24:00:00
11-01-2023 | All Saints' Day | Toussaint | national | t | f | 00:00:00 | 24:00:00
12-25-2023 | Christmas Day | Noël | national | t | f | 00:00:00 | 24:00:00
(11 lignes)

datestamp | reference | description | authority | day_off | observation_shifted | start_time | end_time
------------+-----------------------+--------------------+-----------+---------+---------------------+------------+----------
01-01-2023 | New Year's Day | Jour de l'an | national | t | f | 00:00:00 | 24:00:00
05-01-2023 | Labour Day | Fête du Travail | national | t | f | 00:00:00 | 24:00:00
05-08-2023 | Victory in Europe Day | Armistice 1945 | national | t | f | 00:00:00 | 24:00:00
07-14-2023 | Bastille Day | Fête nationale | national | t | f | 00:00:00 | 24:00:00
11-11-2023 | Remembrance Day | Armistice 1918 | national | t | f | 00:00:00 | 24:00:00
04-10-2023 | Easter Monday | Lundi de Pâques | national | t | f | 00:00:00 | 24:00:00
05-29-2023 | Pentecost | Lundi de Pentecôte | national | t | f | 00:00:00 | 24:00:00
05-18-2023 | Ascension | Ascension | national | t | f | 00:00:00 | 24:00:00
08-15-2023 | Assumption | Assomption | national | t | f | 00:00:00 | 24:00:00
11-01-2023 | All Saints' Day | Toussaint | national | t | f | 00:00:00 | 24:00:00
12-25-2023 | Christmas Day | Noël | national | t | f | 00:00:00 | 24:00:00
(11 lignes)

datestamp | reference | description | authority | day_off | observation_shifted | start_time | end_time
------------+-------------------------+-----------------------+-----------+---------+---------------------+------------+----------
01-01-2023 | New Year's Day | Jour de l'an | national | t | f | 00:00:00 | 24:00:00
05-01-2023 | Labour Day | Fête du Travail | national | t | f | 00:00:00 | 24:00:00
05-08-2023 | Victory in Europe Day | Armistice 1945 | national | t | f | 00:00:00 | 24:00:00
07-14-2023 | Bastille Day | Fête nationale | national | t | f | 00:00:00 | 24:00:00
11-11-2023 | Remembrance Day | Armistice 1918 | national | t | f | 00:00:00 | 24:00:00
04-07-2023 | Good Friday | Vendredi saint | national | t | f | 00:00:00 | 24:00:00
04-10-2023 | Easter Monday | Lundi de Pâques | national | t | f | 00:00:00 | 24:00:00
05-29-2023 | Pentecost | Lundi de Pentecôte | national | t | f | 00:00:00 | 24:00:00
05-18-2023 | Ascension | Ascension | national | t | f | 00:00:00 | 24:00:00
08-15-2023 | Assumption | Assomption | national | t | f | 00:00:00 | 24:00:00
11-01-2023 | All Saints' Day | Toussaint | national | t | f | 00:00:00 | 24:00:00
12-25-2023 | Christmas Day | Premier jour de Noël | national | t | f | 00:00:00 | 24:00:00
12-26-2023 | Second Day of Christmas | Deuxième jour de Noël | national | t | f | 00:00:00 | 24:00:00
(13 lignes)

datestamp | reference | description | authority | day_off | observation_shifted | start_time | end_time
------------+-------------------------+-----------------------+-----------+---------+---------------------+------------+----------
01-01-2023 | New Year's Day | Jour de l'an | national | t | f | 00:00:00 | 24:00:00
05-01-2023 | Labour Day | Fête du Travail | national | t | f | 00:00:00 | 24:00:00
05-08-2023 | Victory in Europe Day | Armistice 1945 | national | t | f | 00:00:00 | 24:00:00
07-14-2023 | Bastille Day | Fête nationale | national | t | f | 00:00:00 | 24:00:00
11-11-2023 | Remembrance Day | Armistice 1918 | national | t | f | 00:00:00 | 24:00:00
04-07-2023 | Good Friday | Vendredi saint | national | t | f | 00:00:00 | 24:00:00
04-10-2023 | Easter Monday | Lundi de Pâques | national | t | f | 00:00:00 | 24:00:00
05-29-2023 | Pentecost | Lundi de Pentecôte | national | t | f | 00:00:00 | 24:00:00
05-18-2023 | Ascension | Ascension | national | t | f | 00:00:00 | 24:00:00
08-15-2023 | Assumption | Assomption | national | t | f | 00:00:00 | 24:00:00
11-01-2023 | All Saints' Day | Toussaint | national | t | f | 00:00:00 | 24:00:00
12-25-2023 | Christmas Day | Premier jour de Noël | national | t | f | 00:00:00 | 24:00:00
12-26-2023 | Second Day of Christmas | Deuxième jour de Noël | national | t | f | 00:00:00 | 24:00:00
(13 lignes)

ROLLBACK
13 changes: 13 additions & 0 deletions test/sql/french_holiday_with_postal_code.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
BEGIN;

CREATE EXTENSION holidays;

SELECT * FROM holidays.by_country ('FR'::text, 2023, 2023, '14610');

SELECT * FROM holidays.by_country ('FR'::text, 2023, 2023, 'Basse Normandie');

SELECT * FROM holidays.by_country ('FR'::text, 2023, 2023, '67270');

SELECT * FROM holidays.by_country ('FR'::text, 2023, 2023, 'Alsace-Moselle');

ROLLBACK;

0 comments on commit e285320

Please sign in to comment.