Skip to content

How to get the list of month names in the current locale ? #6773

Answered by RenjiSann
RenjiSann asked this question in Q&A
Discussion options

You must be logged in to vote

Here's how I eventually did it

pub fn get_abbr_month_names(loc: Locale) -> Result<Vec<String>, DataError> {
    if loc == DEFAULT_LOCALE {
        const DEFAULT_ABBR_MONTHS: &[&str] = &[
            "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC",
        ];
        return Ok(DEFAULT_ABBR_MONTHS
            .iter()
            .map(ToString::to_string)
            .collect());
    }
    let data_locale = DataLocale::from(loc);

    let request = DataRequest {
        id: DataIdentifierBorrowed::for_marker_attributes_and_locale(ABBR_STANDALONE, &data_locale),
        metadata: DataRequestMetadata::default(),
    };

    let response: DataResponse<Datetime…

Replies: 3 comments 15 replies

Comment options

You must be logged in to vote
12 replies
@RenjiSann
Comment options

@Manishearth
Comment options

@sffc
Comment options

sffc Jul 25, 2025
Maintainer

@sffc
Comment options

sffc Jul 25, 2025
Maintainer

@RenjiSann
Comment options

Comment options

You must be logged in to vote
1 reply
@RenjiSann
Comment options

Comment options

You must be logged in to vote
2 replies
@Manishearth
Comment options

@RenjiSann
Comment options

Answer selected by RenjiSann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants