date.ts

Overview

The date.ts file provides a collection of utility functions for formatting and manipulating dates and times using the dayjs library. It centralizes common date/time formatting patterns and relative date calculations to ensure consistent date handling across the application. The functions convert input dates into standardized string representations suitable for display or further processing.


Functions

formatDate(date: any): string

Formats the provided date into the string format "DD/MM/YYYY HH:mm:ss".


formatTime(date: any): string

Formats the provided date or time into the string format "HH:mm:ss".


today(): string

Returns the current date and time formatted as "DD/MM/YYYY HH:mm:ss".


lastDay(): string

Returns the date and time exactly one day before the current moment, formatted as "DD/MM/YYYY HH:mm:ss".


lastWeek(): string

Returns the date and time exactly one week before the current moment, formatted as "DD/MM/YYYY HH:mm:ss".


formatPureDate(date: any): string

Formats the provided date into the string format "DD/MM/YYYY" (date only, no time).


formatStandardDate(date: any): string

Formats the provided date into the ISO-like string format "YYYY-MM-DD".


Important Implementation Details


Interaction with the System


Mermaid Diagram: Function Flowchart

flowchart TD
    A[formatDate(date)] -->|uses| D[dayjs(date).format('DD/MM/YYYY HH:mm:ss')]
    B[formatTime(date)] -->|uses| E[dayjs(date).format('HH:mm:ss')]
    C[today()] -->|calls| A
    F[lastDay()] -->|calls| A
    G[lastWeek()] -->|calls| A
    H[formatPureDate(date)] -->|uses| I[dayjs(date).format('DD/MM/YYYY')]
    J[formatStandardDate(date)] -->|validates| K[dayjs(date).isValid()]
    K -->|true| L[dayjs(date).format('YYYY-MM-DD')]
    K -->|false| M[return '']

Summary

The date.ts file is a focused utility collection providing consistent and reusable date/time formatting and relative date calculations using the dayjs library. It encapsulates common patterns and safeguards against invalid or missing inputs, making it a dependable core utility module for date handling throughout the application.