DateTime

Formatage des dates

<script>
    import { DateTime } from 'gros/date'

    const date = DateTime.format('2022-01-01', { 
        year: 'numeric', 
        month: 'short', 
        day: '2-digit'
    })
</script>

<p>{date}</p>
// 01 janv. 2022

1 janv. 2022 Default format
01/01/2022 { year: 'numeric', month: 'numeric', day: 'numeric'}
01/22 sam. { year: '2-digit', month: 'numeric', weekday: 'short'}
1 janvier 2022 { year: 'numeric', month: 'long', day: 'numeric'}
samedi 01 janvier { month: 'long', day: '2-digit', weekday: 'long'}

type Format = {
    year    ?: 'numeric' | '2-digit'
    month   ?: 'numeric' | '2-digit' | 'narrow' | 'short' | 'long'
    day     ?: 'numeric' | '2-digit'
    weekday ?: 'narrow'  | 'short'   | 'long'
}


Temps relatif

Passé

Futur


<script>
    import { DateTime } from 'gros/date'
</script>

<p>{DateTime.relative('2021-06-04')}</p>


Opérations

Ajouter une durée

1 mars 2024 DateTime.plus('2022-03-01', 2, 'year')
1 mai 2022 DateTime.plus('2022-03-01', 2, 'month')
15 mars 2022 DateTime.plus('2022-03-01', 2, 'week')
3 mars 2022 DateTime.plus('2022-03-01', 2, 'day')

Soustraire une durée

1 mars 2020 DateTime.minus('2022-03-01', 2, 'year')
1 janvier 2022 DateTime.minus('2022-03-01', 2, 'month')
15 février 2022 DateTime.minus('2022-03-01', 2, 'week')
27 février 2022 DateTime.minus('2022-03-01', 2, 'day')

type Unit = 'year' | 'month' | 'week' | 'day'