We're updating the issue view to help you get more done. 

Locale fallback handling for RelativeDateTimeFormatter doesn't work correctly

Description

The following ICU4C program reports "invalid format error", because ureldatefmt_format returns with U_INVALID_FORMAT_ERROR which seems to indicate that the fallback to the root locale doesn't work as expected.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #include <stddef.h> #include <stdint.h> #include <stdio.h> #include "unicode/ureldatefmt.h" #include "unicode/ustdio.h" int main() { UErrorCode status = U_ZERO_ERROR; URelativeDateTimeFormatter* rtf = ureldatefmt_open("ak", nullptr, UDAT_STYLE_LONG, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, &status); if (U_FAILURE(status)) { printf("failure = %d\n", status); return -1; } constexpr size_t size = 256; char16_t chars[size] = {0}; int32_t ret = ureldatefmt_format(rtf, 1, UDAT_REL_UNIT_SECOND, chars, size, &status); if (U_FAILURE(status)) { if (status == U_INVALID_FORMAT_ERROR) { printf("invalid format error\n"); } else { printf("failure = %d\n", status); } return -1; } u_printf("result = %S\n", chars); return 0; }

The equivalent ICU4J program works as expected and prints "+1 s".

1 2 3 4 5 6 7 8 9 10 11 12 import com.ibm.icu.text.DisplayContext; import com.ibm.icu.text.RelativeDateTimeFormatter; import com.ibm.icu.util.ULocale; public class RelativeTimeFormatFallback { public static void main(String[] args) { var rtf = RelativeDateTimeFormatter.getInstance(ULocale.forLanguageTag("ak"), null, RelativeDateTimeFormatter.Style.LONG, DisplayContext.CAPITALIZATION_FOR_STANDALONE); var relativeUnit = RelativeDateTimeFormatter.RelativeDateTimeUnit.SECOND; System.out.println(rtf.format(1, relativeUnit)); } }

Environment

Status

Assignee

Peter Edberg

Reporter

André Bargull

Time Needed

Hours

Components

Fix versions

Priority

critical