Skip to content

Instantly share code, notes, and snippets.

@trplll
Last active July 8, 2016 14:01
Show Gist options
  • Save trplll/81a70a278b3338982c2626413cf314aa to your computer and use it in GitHub Desktop.
Save trplll/81a70a278b3338982c2626413cf314aa to your computer and use it in GitHub Desktop.
Talend Java Dates
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class AC Talend Functions {
/**
* JavaDateToJdeDate: translate from a Java Date to the JDEdwards Julian date format.
*
* {talendTypes} int | Integer
* {Category} User Defined
* {param} Date("1/10/2008") input: The Java Date to be converted.
* {example} JavaDateToJdeDate(1/10/2008) # 108010.
*/
public static int JavaDateToJdeDate(Date d) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyDDD");
String tmp = sdf.format(d);
return (Integer.parseInt(tmp)) - 1900000;
}
/**
* JdeDateToJavaDate: translate from the JDEdwards Julian date format to a Java Date.
*
* {talendTypes} Date
* {Category} User Defined
* {param} int(108010) input: The JDE Julian date to be converted.
* {example} JdeDateToJavaDate(108010) # 1/10/2008.
*/
public static Date JdeDateToJavaDate(int jDate) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyDDD");
String tmp = String.valueOf(jDate + 1900000); // Creating a 4-digit year representation of the JDE Date
return sdf.parse(tmp);
}
/**
* JulianFirstDayLastMonth: return int representing first day of last month in jde julian format
* {talendTypes} Date
* {Category} User Defined
*/
public static Integer JulianFirstDayLastMonth() {
Calendar aCalendar = Calendar.getInstance();
aCalendar.add(Calendar.MONTH, -1);
aCalendar.set(Calendar.DATE, 1);
StringBuilder sb = new StringBuilder();
Calendar cal = Calendar.getInstance();
cal.setTime(aCalendar.getTime());
return Integer.parseInt(sb.append("1")
.append(Integer.toString(cal.get(Calendar.YEAR)).substring(2, 4))
.append(String.format("%03d", cal.get(Calendar.DAY_OF_YEAR)))
.toString());
}
/**
* JulianLastDayPreviousMonth: return int representing first day of last month in jde julian format
* {talendTypes} Date
* {Category} User Defined
*/
public static Integer JulianLastDayPreviousMonth() {
Calendar aCalendar = Calendar.getInstance();
aCalendar.add(Calendar.MONTH, -1);
aCalendar.set(Calendar.DATE, aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
StringBuilder sb = new StringBuilder();
Calendar cal = Calendar.getInstance();
cal.setTime(aCalendar.getTime());
return Integer.parseInt(sb.append("1")
.append(Integer.toString(cal.get(Calendar.YEAR)).substring(2, 4))
.append(String.format("%03d", cal.get(Calendar.DAY_OF_YEAR)))
.toString());
}
/**
* DateLastDayPreviousMonth: return int representing first day of last month in jde julian format
* {talendTypes} Date
* {Category} User Defined
*/
public static String DateLastDayPreviousMonth() {
Calendar aCalendar = Calendar.getInstance();
aCalendar.add(Calendar.MONTH, -1);
aCalendar.set(Calendar.DATE, aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
Calendar cal = Calendar.getInstance();
cal.setTime(aCalendar.getTime());
return (new SimpleDateFormat("MM/dd/yyyy").format(cal.getTime()));
}
/**
* DateFirstDayLastMonth: return int representing first day of last month in jde julian format
* {talendTypes} Date
* {Category} User Defined
*/
public static String DateFirstDayLastMonth() {
Calendar aCalendar = Calendar.getInstance();
aCalendar.add(Calendar.MONTH, -1);
aCalendar.set(Calendar.DATE, 1);
Calendar cal = Calendar.getInstance();
cal.setTime(aCalendar.getTime());
return (new SimpleDateFormat("MM/dd/yyyy").format(cal.getTime()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment