diff --git a/java/semantickernel-core-skills/src/main/java/com/microsoft/semantickernel/coreskills/TimeSkill.java b/java/semantickernel-core-skills/src/main/java/com/microsoft/semantickernel/coreskills/TimeSkill.java index c140f19627cc..ae855f3073e3 100644 --- a/java/semantickernel-core-skills/src/main/java/com/microsoft/semantickernel/coreskills/TimeSkill.java +++ b/java/semantickernel-core-skills/src/main/java/com/microsoft/semantickernel/coreskills/TimeSkill.java @@ -70,8 +70,7 @@ public class TimeSkill { public String date( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { // Example: Sunday, 12 January, 2025 return DateTimeFormatter.ofPattern(DAY_MONTH_DAY_YEAR) @@ -90,8 +89,7 @@ public String date( public String time( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { // Example: 09:15:07 PM return DateTimeFormatter.ofPattern("hh:mm:ss a") @@ -110,8 +108,7 @@ public String time( public String utcNow( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern(DAY_MONTH_DAY_YEAR + " h:mm a") .withLocale(parseLocale(locale)) @@ -129,8 +126,7 @@ public String utcNow( public String today( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return date(locale); } @@ -148,8 +144,7 @@ public String today( public String now( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern(DAY_MONTH_DAY_YEAR + " h:mm a") .withLocale(parseLocale(locale)) @@ -167,8 +162,7 @@ public String now( public String year( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern("yyyy") .withLocale(parseLocale(locale)) @@ -186,8 +180,7 @@ public String year( public String month( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern("MMMM") .withLocale(parseLocale(locale)) @@ -205,8 +198,7 @@ public String month( public String monthNumber( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern("MM") .withLocale(parseLocale(locale)) @@ -224,8 +216,7 @@ public String monthNumber( public String day( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern("d") .withLocale(parseLocale(locale)) @@ -243,8 +234,7 @@ public String day( public String dayOfWeek( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern("EEEE") .withLocale(parseLocale(locale)) @@ -262,8 +252,7 @@ public String dayOfWeek( public String hour( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern("h a") .withLocale(parseLocale(locale)) @@ -281,8 +270,7 @@ public String hour( public String hourNumber( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern("HH") .withLocale(parseLocale(locale)) @@ -305,8 +293,7 @@ public static String daysAgo( String days, @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { int offsetDays = Integer.parseInt(days); return DateTimeFormatter.ofPattern(DAY_MONTH_DAY_YEAR) @@ -329,8 +316,7 @@ public static String dateMatchingLastDayName( String dayName, @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { ZonedDateTime currentDate = ZonedDateTime.now(); for (int i = 1; i <= 7; i++) { @@ -358,8 +344,7 @@ public static String dateMatchingLastDayName( public String minute( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern("mm") .withLocale(parseLocale(locale)) @@ -377,8 +362,7 @@ public String minute( public String second( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern("ss") .withLocale(parseLocale(locale)) @@ -398,8 +382,7 @@ public String second( public String timeZoneOffset( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { return DateTimeFormatter.ofPattern("XXX") .withLocale(parseLocale(locale)) @@ -417,8 +400,7 @@ public String timeZoneOffset( public String timeZoneName( @SKFunctionParameters( name = "locale", - description = "Locale to use when formatting the date", - defaultValue = "en_US") + description = "Locale to use when formatting the date") String locale) { ZoneId zoneId = ZoneId.systemDefault(); return zoneId.getDisplayName(TextStyle.FULL, parseLocale(locale)); diff --git a/java/semantickernel-core-skills/src/main/java/com/microsoft/semantickernel/util/LocaleParser.java b/java/semantickernel-core-skills/src/main/java/com/microsoft/semantickernel/util/LocaleParser.java index 78f6f6590258..891900e391c1 100644 --- a/java/semantickernel-core-skills/src/main/java/com/microsoft/semantickernel/util/LocaleParser.java +++ b/java/semantickernel-core-skills/src/main/java/com/microsoft/semantickernel/util/LocaleParser.java @@ -5,6 +5,9 @@ import java.util.Locale; import java.util.Map; +import com.microsoft.semantickernel.skilldefinition.annotations.SKFunctionInputAttribute; +import com.microsoft.semantickernel.skilldefinition.annotations.SKFunctionParameters; + /** * Locale parser to support Java 8 and Java 9+ due to JEP 252. * @@ -34,7 +37,9 @@ public static final Locale parseLocale(String locale) { Locale parsedLocale = null; - if (locale.indexOf("-") > -1) { + if (locale == null || "".equals(locale.trim()) || locale == SKFunctionParameters.NO_DEFAULT_VALUE) { + return Locale.getDefault(); + } else if (locale.indexOf("-") > -1) { parsedLocale = Locale.forLanguageTag(locale); } else if (locale.indexOf("_") > -1) { String[] parts = locale.split("_");