ACF Library

LocalizedDate

Back to List

Description: Convert at Date or Timestamp value to a localized string

FileMaker Prototype:

Set Variable [$res; ACF_Run("LocalizedDate"; timestamp_ts;  string_fmt)]

Category: TRANSLATIONS

Function source:

/*
   LocalizedDate helper
   --------------------
   This function builds a date string where %A (weekday full), %B (month full),
   %a (weekday short) and %b (month short) are translated via _().

   The following strings are here only to ensure they are picked up by
   the translation extractor and included in the POT file:

   // Weekdays
   _("Monday") _("Tuesday") _("Wednesday") _("Thursday")
   _("Friday") _("Saturday") _("Sunday")

   // Months
   _("January") _("February") _("March") _("April")
   _("May") _("June") _("July") _("August")
   _("September") _("October") _("November") _("December")

   // Short forms
   _("Mon") _("Tue") _("Wed") _("Thu") _("Fri") _("Sat") _("Sun")
   _("Jan") _("Feb") _("Mar") _("Apr") _("May") _("Jun")
   _("Jul") _("Aug") _("Sep") _("Oct") _("Nov") _("Dec")
*/

function LocalizedDate ( timestamp ts , string fmt ) // -> string
    string result;
    string weekdayFull, monthFull, weekdayShort, monthShort;

    result = string(ts, fmt);

    // Full forms
    
    if (pos(fmt, "%A") >= 0) then
       weekdayFull = string(ts, "%A");
        result = substitute(result, weekdayFull, _(weekdayFull));
    end if;

    
    if (pos(fmt, "%B") >= 0) then
       monthFull = string(ts, "%B");
        result = substitute(result, monthFull, _(monthFull));
    end if;

    // Short forms
    
    if (pos(fmt, "%a") >= 0) then
       weekdayShort = string(ts, "%a");
        result = substitute(result, weekdayShort, _(weekdayShort));
    end if;

    
    if (pos(fmt, "%b") >= 0) then
       monthShort = string(ts, "%b");
        result = substitute(result, monthShort, _(monthShort));
    end if;

    return result;
end

The LocalizedDate Function

This function builds a date string where %A (weekday full), %B (month full), %a (weekday short) and %b (month short) are translated via _().

The regular string conversion function in the ACF-language produces english names for months and dates. To have a date string in the actual language, this function can be used for that.

The comment section in the function has all the day and month names defined so that the DDRparser's --scan function can pick them up and add to the POT file for the project. When translated and the MO file is loaded, the function will produce localized names.

Example

Set Variable [$res; ACF_Run("LocalizedDate"; timestamp_ts;  string_fmt)]
Back to List