Helper functions for date and time formatting and conversion across the application. Enhanced with Indonesian localization and country-specific formatting.
Summary
Functions
Formats datetime for display with both local time and relative time.
Parses an ISO 8601 datetime string and returns a DateTime struct.
Returns a list of supported country codes with their timezones.
Converts a UTC datetime to a human-readable relative time. Supports both English and Indonesian.
Converts a UTC datetime to local date only (no time).
Converts a UTC datetime to local time and formats it for display.
Converts local datetime input to UTC for database storage.
Functions
Formats datetime for display with both local time and relative time.
Examples
iex> utc_time = ~U[2023-03-15 14:30:00Z]
iex> Voile.Utils.DateHelper.display_datetime(utc_time)
"15/03/2023 21:30 WIB (2 days ago)"
iex> Voile.Utils.DateHelper.display_datetime(utc_time, format: :indonesian)
"Rabu, 15 Maret 2023 21:30 (2 hari yang lalu)"
Parses an ISO 8601 datetime string and returns a DateTime struct.
Examples
iex> Voile.Utils.DateHelper.parse("2025-10-06T05:22:32Z")
{:ok, ~U[2025-10-06 05:22:32Z]}
Returns a list of supported country codes with their timezones.
Converts a UTC datetime to a human-readable relative time. Supports both English and Indonesian.
Examples
iex> now = DateTime.utc_now()
iex> past = DateTime.add(now, -3600, :second)
iex> Voile.Utils.DateHelper.time_ago(past)
"1 hour ago"
iex> Voile.Utils.DateHelper.time_ago(past, :indonesian)
"1 jam yang lalu"
Converts a UTC datetime to local date only (no time).
Examples
iex> utc_time = ~U[2023-03-15 14:30:00Z]
iex> Voile.Utils.DateHelper.to_local_date(utc_time)
"15/03/2023"
Converts a UTC datetime to local time and formats it for display.
Parameters
utc_datetime- The UTC datetime to convert (%DateTime{} or %NaiveDateTime{})timezone- The target timezone (default: "Asia/Jakarta")format- The format type:- String (strftime format) - e.g., "%d/%m/%Y %H:%M %Z"
- :indonesian - "Senin, 6 Oktober 2025 12:22"
- :indonesian_short - "Sen, 6 Okt 2025 12:22"
- :indonesian_date - "Senin, 6 Oktober 2025"
- Country code (e.g., "US", "JP") - Country-specific format
Examples
iex> utc_time = ~U[2023-03-15 14:30:00Z]
iex> Voile.Utils.DateHelper.to_local_time(utc_time)
"15/03/2023 21:30 WIB"
iex> Voile.Utils.DateHelper.to_local_time(utc_time, "Asia/Jakarta", :indonesian)
"Rabu, 15 Maret 2023 21:30"
iex> Voile.Utils.DateHelper.to_local_time(utc_time, "America/New_York", "US")
"03/15/2023 10:30:00 AM"
Converts local datetime input to UTC for database storage.
Examples
iex> local_time = ~N[2023-03-15 21:30:00]
iex> Voile.Utils.DateHelper.to_utc(local_time, "Asia/Jakarta")
~U[2023-03-15 14:30:00Z]