Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions stdlib/date_fr.catala_fr
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ déclaration énumération Mois:
-- Décembre

## Renvoie le numéro de mois (à partir de 1) associé à un mois nommé.
déclaration month_to_int
déclaration mois_vers_entier
contenu entier
dépend de m contenu Mois
égal à
Expand All @@ -146,7 +146,7 @@ déclaration structure MoisDansAnnée:

## Renvoie le mois nommé correspondant au numéro de mois (à partir de 1).
## Si l'argument n'est pas entre 1 et 12, échoue avec l'erreur `impossible`.
déclaration month_of_int
déclaration mois_depuis_entier
contenu Mois
dépend de i contenu entier
égal à
Expand All @@ -166,14 +166,14 @@ déclaration month_of_int

## Transforme un `MoisDansAnnée` vers une `date` en choisissant le premier jour
## du mois.
déclaration month_of_year_to_premier_jour_du_mois
déclaration mois_dans_année_vers_premier_jour_du_mois
contenu date
dépend de m contenu MoisDansAnnée
égal à
depuis_année_mois_jour de (m.numéro_année, (month_to_int de m.nom_mois), 1)

## Extrait le mois nommé et le numéro de l'année dans une date.
déclaration to_month_of_year
déclaration vers_mois_dans_année
contenu MoisDansAnnée
dépend de d contenu date
égal à
Expand Down
25 changes: 25 additions & 0 deletions stdlib/period_en.catala_en
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ declaration structure Period:
# The end date is included in the period
data end content date

## Returns a period ranging over the given month of the given year.
declaration of_month_and_year
content Period
depends on
pmonth content Date.Month,
pyear content integer
equals
let pbegin equals
Date.of_year_month_day of (pyear, (Date.month_to_int of pmonth), 1)
in
Period {
-- begin: pbegin
-- end: Date.last_day_of_month of pbegin
}

## Returns a period ranging over the given year.
declaration of_year
content Period
depends on pyear content integer
equals
Period {
-- begin: Date.of_year_month_day of (pyear, 1, 1)
-- end: Date.of_year_month_day of (pyear, 12, 31)
}

## Ensures that the period is coherent (it begins before its end).
declaration valid
content boolean
Expand Down
25 changes: 25 additions & 0 deletions stdlib/period_fr.catala_fr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ déclaration structure Période:
# La date de fin est incluse dans la période par convention.
donnée fin contenu date

## Retourne la période englobant le mois donné de l'année donnée.
déclaration depuis_mois_et_année
contenu Période
dépend de
pmois contenu Date.Mois,
pannée contenu entier
égal à
soit pbegin égal à
Date.depuis_année_mois_jour de (pannée, (Date.mois_vers_entier de pmois), 1)
dans
Période {
-- début: pbegin
-- fin: Date.dernier_jour_du_mois de pbegin
}

## Retourne la période englobant l'année donnée.
déclaration depuis_année
contenu Période
dépend de pannée contenu entier
égal à
Période {
-- début: Date.depuis_année_mois_jour de (pannée, 1, 1)
-- fin: Date.depuis_année_mois_jour de (pannée, 12, 31)
}

## Vérifie si la période est bien cohérente (elle débute avant sa fin).
déclaration valide
contenu booléen
Expand Down
61 changes: 61 additions & 0 deletions tests/stdlib/period.catala_en
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
```catala
declaration mk_p
content Period.Period
depends on b content date, e content date
equals Period.Period { -- begin: b -- end: e }

#[test]
declaration scope Tunit:
output p_one_day content Period.Period
output p_bad content Period.Period
output p_succ_one_day content Period.Period
output p_in_succ_one_day content Period.Period
output p_from_month_and_year content Period.Period
output p_from_year content Period.Period

scope Tunit:
definition p_one_day equals mk_p of (|2020-01-01|, |2020-01-01|)
assertion (Period.valid of p_one_day and Period.duration of p_one_day = 1 day)

definition p_bad equals mk_p of (|2020-01-02|, |2020-01-01|)
assertion (not (Period.valid of p_bad))

definition p_succ_one_day equals mk_p of (|2020-01-02|, |2020-01-03|)
assertion (
Period.valid of p_succ_one_day
and Period.are_adjacent of p_one_day, p_succ_one_day
and (Period.intersection of p_one_day, p_succ_one_day) with pattern Absent
and Period.join of p_one_day, p_succ_one_day = mk_p of |2020-01-01|, |2020-01-03|
and Period.contained of p_succ_one_day, |2020-01-02|
)

definition p_in_succ_one_day equals mk_p of (|2020-01-03|, |2020-01-03|)
assertion (
Period.valid of p_in_succ_one_day
and not (Period.are_adjacent of p_succ_one_day, p_in_succ_one_day)
and (
(Period.intersection of p_succ_one_day, p_in_succ_one_day) with pattern Present content p
and p = (mk_p of |2020-01-03|, |2020-01-03|)
)
and Period.join of p_succ_one_day, p_in_succ_one_day = p_succ_one_day
)

assertion (
(Period.find_period of [ p_one_day ; p_succ_one_day ; p_in_succ_one_day ], |2020-01-04|) with pattern Absent
and (
(
Period.find_period of
[ p_one_day ; p_succ_one_day ; p_in_succ_one_day ],
|2020-01-03|
) with pattern Present content p
and p = p_succ_one_day
)
)

definition p_from_month_and_year equals Period.of_month_and_year of Date.Month.May, 1968
assertion p_from_month_and_year = Period.Period { -- begin: |1968-05-01| -- end: |1968-05-31| }

definition p_from_year equals Period.of_year of 2002
assertion p_from_year = Period.Period { -- begin: |2002-01-01| -- end: |2002-12-31| }
```

```catala
#[test]
declaration scope Tsort:
Expand Down
Loading