setLocale static method

Future<void> setLocale(
  1. String locale
)

Sets the locale for this Jiffy instance based on the locale provided.

The locale parameter is expected to be a string representation of a supported locale, such as 'en_US' or 'fr_FR'. If the locale provided is not supported, a JiffyException will be thrown.

await Jiffy().setLocale('en_US');

Throws a JiffyException if the locale provided is not supported in Jiffy.

Implementation

static Future<void> setLocale(String locale) async {
  if (supported_locales.isLocalSupported(locale)) {
    Intl.defaultLocale = locale;
    await initializeDateFormatting();
  } else {
    // todo add github readme locale link to this exception and also
    // update the doc comment
    throw JiffyException('The locale `$locale` is not supported, '
        'please check here for a list of supported locales');
  }
}