Skip to content

Commit

Permalink
Merge branch 'unicode-org:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-oly authored Aug 9, 2024
2 parents 1547e60 + 9fb3f87 commit 83bd796
Show file tree
Hide file tree
Showing 28 changed files with 1,161 additions and 321 deletions.
102 changes: 96 additions & 6 deletions executors/icu4j/74/executor-icu4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,100 @@

<packaging>jar</packaging>

<!-- Profiles are used to set the version of ICU4J to test against -->
<profiles>
<profile>
<id>icu73</id>
<dependencies>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>73.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<!-- see: https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html -->
<include>**/collator/icu74/*Test.java</include>
<include>**/langnames/icu74/*Test.java</include>
<include>**/likelysubtags/icu74/*Test.java</include>
<include>**/listformatter/icu74/*Test.java</include>
<!-- <include>**/messageformat2/icu74/*Test.java</include> --> <!-- no MF2 in v73 & earlier -->
<include>**/numberformatter/icu74/*Test.java</include>
<include>**/pluralrules/icu74/*Test.java</include>
<include>**/relativedatetimeformat/icu74/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>icu74</id>
<dependencies>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>74.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<!-- see: https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html -->
<include>**/collator/icu74/*Test.java</include>
<include>**/langnames/icu74/*Test.java</include>
<include>**/likelysubtags/icu74/*Test.java</include>
<include>**/listformatter/icu74/*Test.java</include>
<include>**/messageformat2/icu74/*Test.java</include>
<include>**/numberformatter/icu74/*Test.java</include>
<include>**/pluralrules/icu74/*Test.java</include>
<include>**/relativedatetimeformat/icu74/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>icu75</id>
<dependencies>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>75.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<!-- see: https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html -->
<include>**/collator/icu74/*Test.java</include>
<include>**/langnames/icu74/*Test.java</include>
<include>**/likelysubtags/icu74/*Test.java</include>
<include>**/listformatter/icu74/*Test.java</include>
<include>**/messageformat2/icu75/*Test.java</include> <!-- latest MF2 version: ICU 75 -->
<include>**/numberformatter/icu74/*Test.java</include>
<include>**/pluralrules/icu74/*Test.java</include>
<include>**/relativedatetimeformat/icu74/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>junit</groupId>
Expand All @@ -27,12 +121,8 @@
<scope>test</scope>
</dependency>

<!-- ICU4J 74 (library under test) -->
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>74.2</version>
</dependency>
<!-- Note: ICU4J (library under test) must be enabled via activating the desired
profile corresponding to the version -->

<!-- JSON library -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.unicode.conformance.testtype.ITestType;
import org.unicode.conformance.testtype.ITestTypeOutputJson;
import org.unicode.conformance.testtype.collator.CollatorTester;
import org.unicode.conformance.testtype.datetimeformatter.DateTimeFormatterTester;
import org.unicode.conformance.testtype.langnames.LangNamesTester;
import org.unicode.conformance.testtype.likelysubtags.LikelySubtagsTester;
import org.unicode.conformance.testtype.listformatter.ListFormatterTester;
Expand Down Expand Up @@ -118,6 +119,8 @@ public static String getTestCaseResponse(String inputLine) throws Exception {
ITestType testType;
if (testTypeStr.equals("collation_short")) {
testType = CollatorTester.INSTANCE;
} else if (testTypeStr.equals("datetime_fmt")) {
testType = DateTimeFormatterTester.INSTANCE;
} else if (testTypeStr.equals("lang_names")) {
testType = LangNamesTester.INSTANCE;
} else if (testTypeStr.equals("likely_subtags")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.unicode.conformance.testtype.datetimeformatter;

public enum DateTimeFormatterDateStyle {
FULL,
LONG,
MEDIUM,
SHORT;

public static org.unicode.conformance.testtype.datetimeformatter.DateTimeFormatterDateStyle DEFAULT = MEDIUM;

public static org.unicode.conformance.testtype.datetimeformatter.DateTimeFormatterDateStyle getFromString(
String s) {
try {
return org.unicode.conformance.testtype.datetimeformatter.DateTimeFormatterDateStyle.valueOf(
s.toUpperCase());
} catch (Exception e) {
return DEFAULT;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.unicode.conformance.testtype.datetimeformatter;

import java.util.Date;
import com.ibm.icu.util.Calendar;

import org.unicode.conformance.testtype.ITestTypeInputJson;

public class DateTimeFormatterInputJson implements ITestTypeInputJson {

public String testType;

public String label;

public String locale;

// UTC formatted time
public String inputString;

public Date myDate;

public String skeleton;

public DateTimeFormatterDateStyle dateStyle;

public DateTimeFormatterTimeStyle timeStyle;

// TODO!!!
public String calendarString;
// Set calendar from calendarString!
public Calendar calendar;

public String numberingSystem;

public String timeZone;

public String timeZoneName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.unicode.conformance.testtype.datetimeformatter;

import org.unicode.conformance.testtype.ITestTypeOutputJson;

public class DateTimeFormatterOutputJson implements ITestTypeOutputJson {

public String test_type;

public String label;

public String result;

public String error;

public String error_message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
package org.unicode.conformance.testtype.datetimeformatter;

import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

import java.util.Date;

import com.ibm.icu.util.Calendar;
import com.ibm.icu.text.DateFormat;
import com.ibm.icu.util.ULocale;

import io.lacuna.bifurcan.IMap;
import io.lacuna.bifurcan.Map;


import org.unicode.conformance.ExecutorUtils;
import org.unicode.conformance.testtype.ITestType;
import org.unicode.conformance.testtype.ITestTypeInputJson;
import org.unicode.conformance.testtype.ITestTypeOutputJson;

public class DateTimeFormatterTester implements ITestType {

public static DateTimeFormatterTester INSTANCE = new DateTimeFormatterTester();

@Override
public ITestTypeInputJson inputMapToJson(Map<String, Object> inputMapData) {
DateTimeFormatterInputJson result = new DateTimeFormatterInputJson();

result.label = (String) inputMapData.get("label", null);
result.locale = (String) inputMapData.get("locale", null);
result.skeleton = (String) inputMapData.get("skeleton", null);

result.inputString = (String) inputMapData.get("input_string", null);

java.util.Map<String, Object> inputOptions =
(java.util.Map<String, Object>) inputMapData.get("options", null);

result.timeZone = (String) inputOptions.get("timeZone");
ZoneId thisZoneId;
if (result.timeZone == null) {
thisZoneId = ZoneId.systemDefault();
} else {
thisZoneId = ZoneId.of(result.timeZone);
}

// Extract ISO part of the input string to parse.
String inputStringDateTime = result.inputString.substring(0, 25);

// For parsing the input string and converting to java.util.date
LocalDateTime parsedLocalDateTime =
LocalDateTime.parse(inputStringDateTime, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
result.myDate =
java.util.Date.from(parsedLocalDateTime.atZone(thisZoneId)
.toInstant());

result.dateStyle = DateTimeFormatterDateStyle.getFromString(
"" + inputOptions.get("dateStyle")
);

result.timeStyle = DateTimeFormatterTimeStyle.getFromString(
"" + inputOptions.get("timeStyle")
);

result.calendarString = (String) inputOptions.get("calendar");

// TODO!!! Get calendar object. Depends on timezone and locale.
// Just a placeholder for now.
result.calendar = Calendar.getInstance();

result.numberingSystem = (String) inputOptions.get("numberingSystem");

result.timeZoneName = (String) inputOptions.get("timeZoneName");

return result;
}

public ITestTypeOutputJson execute(ITestTypeInputJson inputJson) {
DateTimeFormatterInputJson input = (DateTimeFormatterInputJson) inputJson;

// partially construct output
DateTimeFormatterOutputJson output = (DateTimeFormatterOutputJson) getDefaultOutputJson();
output.label = input.label;

try {
output.result = getDateTimeFormatterResultString(input);
} catch (Exception e) {
output.error = e.getMessage();
output.error_message = e.getMessage();
return output;
}

// If we get here, it's a pass/fail result (supported options and no runtime errors/exceptions)
return output;
}

@Override
public ITestTypeOutputJson getDefaultOutputJson() {
return new DateTimeFormatterOutputJson();
}

public IMap<String, Object> convertOutputToMap(ITestTypeOutputJson outputJson) {
DateTimeFormatterOutputJson output = (DateTimeFormatterOutputJson) outputJson;
return new io.lacuna.bifurcan.Map<String, Object>()
.put("label", output.label)
.put("result", output.result);
}

@Override
public String formatOutputJson(ITestTypeOutputJson outputJson) {
return ExecutorUtils.GSON.toJson((DateTimeFormatterOutputJson) outputJson);
}

public String getDateTimeFormatterResultString(DateTimeFormatterInputJson input) {

ULocale locale = ULocale.forLanguageTag(input.locale);

int dateStyle;
switch (input.dateStyle) {
case FULL:
dateStyle = DateFormat.FULL;
break;
case LONG:
dateStyle = DateFormat.LONG;
break;
default:
case MEDIUM:
dateStyle = DateFormat.MEDIUM;
break;
case SHORT:
dateStyle = DateFormat.SHORT;
break;
}

int timeStyle;
switch (input.timeStyle) {
case FULL:
timeStyle = DateFormat.FULL;
break;
case LONG:
timeStyle = DateFormat.LONG;
break;
default:
case MEDIUM:
timeStyle = DateFormat.MEDIUM;
break;
case SHORT:
timeStyle = DateFormat.SHORT;
break;

}

// Get calendar and timezone as needed.
Calendar cal = input.calendar;

DateFormat dtf;
if (input.skeleton != null) {
dtf = DateFormat.getInstanceForSkeleton(cal, input.skeleton, locale);
} else {
dtf = DateFormat.getDateTimeInstance(cal, dateStyle, timeStyle, locale);
}

return dtf.format(input.myDate);
}

}
Loading

0 comments on commit 83bd796

Please sign in to comment.