Skip to content

Commit

Permalink
@W-15086056 .OriginDateTime in formula returns 1/1/1357, 12:00 AM for…
Browse files Browse the repository at this point in the history
… some app servers (#145)
  • Loading branch information
bairenlong-sfdc committed May 30, 2024
1 parent 234e461 commit 4c4732f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions api/src/main/java/com/force/formula/util/SystemFormulaContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.force.formula.util;

import java.util.Calendar;
import java.util.Locale;

import com.force.formula.ContextualFormulaFieldInfo;
import com.force.formula.DisplayField;
Expand All @@ -23,7 +24,7 @@
import com.force.i18n.BaseLocalizer;

/**
* Example of a formula context that returns some fixed constants.
* Example of a formula context that returns some fixed constants.
* @author dchasman
* @since 146
*/
Expand Down Expand Up @@ -67,11 +68,11 @@ public FormulaReturnType getFormulaReturnType() {
@Override
public ContextualFormulaFieldInfo lookup(String name, boolean isDynamicRefBase) throws InvalidFieldReferenceException, UnsupportedTypeException {
if (ORIGIN_DATE_TIME.equalsIgnoreCase(name)) {
FormulaSqlStyle style = FormulaEngine.getHooks().getSqlStyle();
if (style != null && style.isMysqlStyle()) {
return originDateTime_MYSQL;
} else if (style != null && style.isTransactSqlStyle()) {
return originDateTime_TSQL;
FormulaSqlStyle style = FormulaEngine.getHooks().getSqlStyle();
if (style != null && style.isMysqlStyle()) {
return originDateTime_MYSQL;
} else if (style != null && style.isTransactSqlStyle()) {
return originDateTime_TSQL;
} else if (style != null && (style.isPrestoStyle() || style.isH2Style())) {
return originDateTime_PRESTO;
} else if (style != null && style.isGoogleStyle()) {
Expand All @@ -98,7 +99,7 @@ public String toJavascriptName(String name) throws InvalidFieldReferenceExceptio
return name;
}


@Override
public String fromDurableName(String reference) throws InvalidFieldReferenceException, UnsupportedTypeException {
return reference;
Expand Down Expand Up @@ -150,7 +151,13 @@ public SQLPair getSQL(ITableAliasRegistry registry) {
private static DisplayField[] displayFields = new DisplayField[] { new DisplayField(SYSTEM_NAMESPACE, SYSTEM_NAMESPACE, originDateTime) };

static {
Calendar c = FormulaI18nUtils.getLocalizer().getCalendar(BaseLocalizer.GMT);
Calendar c;
if ("th-TH".equals(FormulaI18nUtils.getLocalizer().getLocale().toLanguageTag())) {
c = Calendar.getInstance(Locale.US); // Use Gregorian instead of Buddhist, see W-15086056
}
else {
c = FormulaI18nUtils.getLocalizer().getCalendar(BaseLocalizer.GMT);
}
c.clear();
c.set(1900, 0, 1); // Months are zero-based in Java Calenders

Expand Down

0 comments on commit 4c4732f

Please sign in to comment.