Compare commits

...

2 Commits

Author SHA1 Message Date
Zhiwei Xue
ef49a85ae3 feat(TUP-29014): bugfix 2021-03-16 (#4127) 2021-03-16 17:11:37 +08:00
Laurent BOURGEOIS
216b30089f fix(TBD-11964): Different time zone for Standard jobs and BD Batch (#4082) (#4122) 2021-03-15 18:10:25 +01:00
3 changed files with 175 additions and 127 deletions

View File

@@ -144,11 +144,34 @@ public class TalendDate {
*
* {example} formatDate("yyyy-MM-dd", new Date()) #
*/
public synchronized static String formatDateInUTC(String pattern, java.util.Date date) {
return formatDateInTimeZone(pattern, date, "UTC");
}
/**
* Formats a Date into a date/time string under the given timezone.
*
* @param pattern the pattern to format.
* @param date the date to be formatted into a date string.
* @param zoneId the timezone id in which formatting the date
* @return the formatted time string.
*
* {talendTypes} String
*
* {Category} TalendDate
*
* {param} string("yyyy-MM-dd HH:mm:ss") pattern : the pattern to format
*
* {param} date(myDate) date : the time value to be formatted into a time string
*
* {param] string(zoneId) : id of timezone
*
* {example} formatDate("yyyy-MM-dd", new Date(), "Europe/Paris") #
*/
public synchronized static String formatDateInTimeZone(String pattern, java.util.Date date, String zoneId) {
DateFormat format = FastDateParser.getInstance(pattern);
TimeZone originalTZ = format.getTimeZone();
format.setTimeZone(TimeZone.getTimeZone("UTC"));
format.setTimeZone(TimeZone.getTimeZone(zoneId));
String dateStr = format.format(date);
format.setTimeZone(originalTZ);
return dateStr;
@@ -264,24 +287,24 @@ public class TalendDate {
/**
* Tests string value as a date with right pattern using strict rules.
* This validation uses Java 8 time tools.
*
*
* The range of time-zone offsets is restricted to -18:00 to 18:00 inclusive.
*
*
* @param stringDate (The <code>String</code> of the date to judge)
* @param pattern (The <code>String</code> of a specified pattern, like: "yyyy-MM-dd HH:mm:ss")
* @return A boolean value that whether the stringDate is a date string with a right pattern.
* @throws IllegalArgumentException if pattern is not defined.
*
*
* {talendTypes} Boolean
*
*
* {Category} TalendDate
*
*
* {param} String(mydate) stringDate : the date to judge
*
*
* {param} String("yyyy-MM-dd HH:mm:ss") pattern : the specified pattern
*
*
* {examples}
*
*
* ->> isDateStrict("20110327 121711", "yyyyMMdd HHmmss") return true
* ->> isDateStrict("01100327 121711", "yyyyMMdd HHmmss") return false
* ->> isDateStrict("20180229 221711", "yyyyMMdd HHmmss") return false
@@ -1166,7 +1189,7 @@ public class TalendDate {
*/
public static void test_getRandomDate() {
System.out
.println("getRandomDate: " + TalendDate.formatDate("yyyy-MM-dd HH:mm:ss", TalendDate.getRandomDate(null, null))); //$NON-NLS-1$
.println("getRandomDate: " + TalendDate.formatDate("yyyy-MM-dd HH:mm:ss", TalendDate.getRandomDate(null, null))); //$NON-NLS-1$
}
/**
@@ -1178,7 +1201,7 @@ public class TalendDate {
*/
public static void test_compareDate() {
System.out
.println("compareDate: " + Boolean.toString(TalendDate.compareDate(new Date(), new Date(System.currentTimeMillis() - 10000)) == 1)); //$NON-NLS-1$
.println("compareDate: " + Boolean.toString(TalendDate.compareDate(new Date(), new Date(System.currentTimeMillis() - 10000)) == 1)); //$NON-NLS-1$
}
/**
@@ -1321,100 +1344,100 @@ public class TalendDate {
test4.start();
test5.start();
}
/**
*
*
* @param string Must be a string datatype. Passes the values that you want to convert.
* @param format Enter a valid TO_DATE format string. The format string must match the parts of the string argument
* default formate is "MM/DD/yyyy HH:mm:ss.sss" if not specified.
* @return Date
* @return Date
* @throws ParseException
* {example} TO_DATE("1464576463231", "J") #Mon May 30 10:47:43 CST 2016
* {example} TO_DATE("2015-11-21 13:23:45","yyyy-MM-dd HH:mm:ss") #Sat Nov 21 13:23:45 CST 2015
*
*
*/
public static Date TO_DATE(String string, String format) throws ParseException {
String defaultFormat = "MM/dd/yyyy HH:mm:ss.SSS";
if (StringHandling.isVacant(string)) {
return null;
}
if (!StringHandling.isVacant(format)) {
if (format.equals("J")) {
return new Date(Long.parseLong(string));
}
SimpleDateFormat sdf = new SimpleDateFormat(dateFormatConvert(format));
return sdf.parse(string);
} else {
SimpleDateFormat sdf = new SimpleDateFormat(defaultFormat);
return sdf.parse(string);
}
String defaultFormat = "MM/dd/yyyy HH:mm:ss.SSS";
if (StringHandling.isVacant(string)) {
return null;
}
if (!StringHandling.isVacant(format)) {
if (format.equals("J")) {
return new Date(Long.parseLong(string));
}
SimpleDateFormat sdf = new SimpleDateFormat(dateFormatConvert(format));
return sdf.parse(string);
} else {
SimpleDateFormat sdf = new SimpleDateFormat(defaultFormat);
return sdf.parse(string);
}
}
}
public static Date TO_DATE(String string) throws ParseException {
return TO_DATE(string, null);
}
public static Date TO_DATE(String string) throws ParseException {
return TO_DATE(string, null);
}
private static String dateFormatConvert(String format) {
/**
* we do not support the type list below:
* D : Day of week (1-7), where Sunday equals 1.
* NS: Nanoseconds (0-999999999). SSSSS: Seconds since midnight (00000 - 86399).
* US: Microseconds (0-999999).
* Q: Quarter of year (1-4), where January to March equals 1.
*/
format = format.replaceAll("Y", "y");
format = format.replaceAll("RR", "yy");
format = format.replaceAll("MONTH", "MMMM");
format = format.replaceAll("MON", "MMM");
format = format.replaceAll("WW", "w");// Week of year (01-53)
format = format.replaceAll("W", "F");// Week of month (1-5)
format = format.replaceAll("(AM|A.M.|PM|P.M.)", "a");
format = format.replaceAll("DY", "E");// Abbreviated three-character
// name for a day (for example,
// Wed).
format = format.replaceAll("DDD", "D");// Day of year (001-366,
// including leap years).
format = format.replaceAll("DD", "d");// Day of month (01-31).
format = format.replaceAll("HH24", "zx@i#o%l!");//protect HH24 from HH
format = format.replaceAll("(HH|HH12)", "hh");
format = format.replaceAll("zx@i#o%l!", "HH");
format = format.replaceAll("MS", "sss");
format = format.replaceAll("MI", "mm");
format = format.replaceAll("SS", "ss");
private static String dateFormatConvert(String format) {
/**
* we do not support the type list below:
* D : Day of week (1-7), where Sunday equals 1.
* NS: Nanoseconds (0-999999999). SSSSS: Seconds since midnight (00000 - 86399).
* US: Microseconds (0-999999).
* Q: Quarter of year (1-4), where January to March equals 1.
*/
format = format.replaceAll("Y", "y");
format = format.replaceAll("RR", "yy");
format = format.replaceAll("MONTH", "MMMM");
format = format.replaceAll("MON", "MMM");
format = format.replaceAll("WW", "w");// Week of year (01-53)
format = format.replaceAll("W", "F");// Week of month (1-5)
format = format.replaceAll("(AM|A.M.|PM|P.M.)", "a");
format = format.replaceAll("DY", "E");// Abbreviated three-character
// name for a day (for example,
// Wed).
format = format.replaceAll("DDD", "D");// Day of year (001-366,
// including leap years).
format = format.replaceAll("DD", "d");// Day of month (01-31).
format = format.replaceAll("HH24", "zx@i#o%l!");//protect HH24 from HH
format = format.replaceAll("(HH|HH12)", "hh");
format = format.replaceAll("zx@i#o%l!", "HH");
format = format.replaceAll("MS", "sss");
format = format.replaceAll("MI", "mm");
format = format.replaceAll("SS", "ss");
return format;
}
/**
*
* @param date Passes the values you want to change
* @param format A format string specifying the portion of the date value you want to change.For example, 'mm'.
* @param amount An integer value specifying the amount of years, months, days, hours,
* and so on by which you want to change the date value.
* @return Date NULL if a null value is passed as an argument to the function.
* @throws ParseException
* {example} ADD_TO_DATE(new Date(1464576463231l), "HH",2) #Mon May 30 12:47:43 CST 2016
*/
public static Date ADD_TO_DATE(Date date, String format, int amount) throws ParseException{
if (date == null || StringHandling.isVacant(format)) {
return null;
}
if (format != null) {
format = dateFormatADD_TO_DATE(format);
}
Long time = date.getTime();
Calendar calender = Calendar.getInstance();
calender.setTime(date);
switch (format) {
case "Y":
calender.add(Calendar.YEAR, amount);
time = calender.getTimeInMillis();
break;
case "MONTH":
calender.add(Calendar.MONTH, amount);
time = calender.getTimeInMillis();
break;
return format;
}
/**
*
* @param date Passes the values you want to change
* @param format A format string specifying the portion of the date value you want to change.For example, 'mm'.
* @param amount An integer value specifying the amount of years, months, days, hours,
* and so on by which you want to change the date value.
* @return Date NULL if a null value is passed as an argument to the function.
* @throws ParseException
* {example} ADD_TO_DATE(new Date(1464576463231l), "HH",2) #Mon May 30 12:47:43 CST 2016
*/
public static Date ADD_TO_DATE(Date date, String format, int amount) throws ParseException{
if (date == null || StringHandling.isVacant(format)) {
return null;
}
if (format != null) {
format = dateFormatADD_TO_DATE(format);
}
Long time = date.getTime();
Calendar calender = Calendar.getInstance();
calender.setTime(date);
switch (format) {
case "Y":
calender.add(Calendar.YEAR, amount);
time = calender.getTimeInMillis();
break;
case "MONTH":
calender.add(Calendar.MONTH, amount);
time = calender.getTimeInMillis();
break;
case "DAY":
time += (long)amount * (long)86400000;
break;
@@ -1427,47 +1450,47 @@ public class TalendDate {
case "SS":
time += (long)amount * (long)1000;
break;
case "MS":
time += amount;
break;
case "US":
time += amount / 1000;
break;
case "NS":
time += amount / 1000000;
break;
default:
throw new ParseException("Please enter a vaild format.", 0);
}
return new Date(time);
case "MS":
time += amount;
break;
case "US":
time += amount / 1000;
break;
case "NS":
time += amount / 1000000;
break;
default:
throw new ParseException("Please enter a vaild format.", 0);
}
return new Date(time);
}
}
private static String dateFormatADD_TO_DATE(String format) {
if (format.equals("Y") || format.equals("YY") || format.equals("YYY") || format.equals("YYYY")) {
return "Y";
}
if (format.equals("MONTH") || format.equals("MM") || format.equals("MON")) {
return "MONTH";
}
if (format.equals("D") || format.equals("DD") || format.equals("DDD") || format.equals("DAY")
|| format.equals("DY")) {
return "DAY";
}
if (format.equals("HH") || format.equals("HH12") || format.equals("HH24")) {
return "HH";
}
return format;
private static String dateFormatADD_TO_DATE(String format) {
if (format.equals("Y") || format.equals("YY") || format.equals("YYY") || format.equals("YYYY")) {
return "Y";
}
if (format.equals("MONTH") || format.equals("MM") || format.equals("MON")) {
return "MONTH";
}
if (format.equals("D") || format.equals("DD") || format.equals("DDD") || format.equals("DAY")
|| format.equals("DY")) {
return "DAY";
}
if (format.equals("HH") || format.equals("HH12") || format.equals("HH24")) {
return "HH";
}
return format;
}
}
/**
*
*
* @param date Date/Time datatype. Passes the date values you want to convert to character strings.
* @param format Enter a valid TO_CHAR format string. The format string defines the format of the return value,
* @return String. NULL if a value passed to the function is NULL.
*/
public static String TO_CHAR(Date date, String format) {
if (date == null) {
return null;

View File

@@ -45,7 +45,7 @@ public class FormatterUtils {
} else if(obj instanceof Date) {
return TalendDate.formatDate(pattern == null ? Constant.dateDefaultPattern : pattern, (Date)obj);
} else if(obj instanceof Boolean) {
return obj.toString();
return obj.toString();
} else if(obj instanceof BigDecimal) {
return ((BigDecimal)obj).toPlainString();
} else if(obj instanceof Double) {
@@ -159,6 +159,23 @@ public class FormatterUtils {
}
}
/**
* Formats a Date into a date/time string under an user specified timezone.
*
* @param date the time value to be formatted into a time string.
* @param pattern the pattern to format.
* @param zoneId id of the timezone to consider
* @return the formatted time string.
*
*/
public static String format_DateInTimeZone(java.util.Date date, String pattern, String zoneId) {
if (date != null) {
return TalendDate.formatDateInTimeZone(pattern == null ? Constant.dateDefaultPattern : pattern, date, zoneId);
} else {
return null;
}
}
public static String format_Date_Locale(java.util.Date date, String pattern, String locale) {
if (date != null) {
return TalendDate.formatDateLocale(pattern == null ? Constant.dateDefaultPattern : pattern, date, locale);

View File

@@ -29,6 +29,7 @@ import org.apache.commons.lang.StringUtils;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -85,6 +86,8 @@ import org.talend.core.service.IExchangeService;
import org.talend.core.ui.advanced.composite.FilteredCheckboxTree;
import org.talend.core.ui.component.ComponentPaletteUtilities;
import org.talend.designer.core.IMultiPageTalendEditor;
import org.talend.designer.maven.tools.AggregatorPomsHelper;
import org.talend.designer.maven.tools.MavenPomSynchronizer;
import org.talend.repository.items.importexport.handlers.ImportExportHandlersManager;
import org.talend.repository.items.importexport.handlers.imports.ImportCacheHelper;
import org.talend.repository.items.importexport.handlers.model.EmptyFolderImportItem;
@@ -1065,6 +1068,11 @@ public class ImportItemsWizardPage extends WizardPage {
}
}
});
// FIXME add back since it could avoid deadlock "luckily"
// remove this part later since no use to update here
// regression check must be done for TUP-25372 & TESB-27401
MavenPomSynchronizer.addChangeLibrariesListener();
new AggregatorPomsHelper().updateCodeProjects(new NullProgressMonitor(), false, false);
}
};