diff --git a/sql/countries/france.pgsql b/sql/countries/france.pgsql index 17ff944..88fc6b1 100644 --- a/sql/countries/france.pgsql +++ b/sql/countries/france.pgsql @@ -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 @@ -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 @@ -245,4 +270,4 @@ BEGIN END LOOP; END; -$$ LANGUAGE plpgsql; \ No newline at end of file +$$ LANGUAGE plpgsql; diff --git a/test/expected/french_holiday_with_postal_code.out b/test/expected/french_holiday_with_postal_code.out new file mode 100644 index 0000000..44d05ef --- /dev/null +++ b/test/expected/french_holiday_with_postal_code.out @@ -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 diff --git a/test/sql/french_holiday_with_postal_code.sql b/test/sql/french_holiday_with_postal_code.sql new file mode 100644 index 0000000..3ee09a7 --- /dev/null +++ b/test/sql/french_holiday_with_postal_code.sql @@ -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;