Skip to content

Commit

Permalink
Merge pull request #977 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
fix date conversion edge cases
  • Loading branch information
ashitsalesforce authored Feb 11, 2024
2 parents e34306d + ec30e2d commit 2cfb7f9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ Calendar getNAValueCalendar() {
return NACalendarValue.getInstance();
}

/* Helper function to produce all the patterns that DL supports */
/*
* Helper function to produce all the patterns that DL supports.
* These patterns are a subset of patterns supported by Java text.SimpleDateFormat
* https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
*/
static List<String> getSupportedPatterns(boolean europeanDates) {

List<String> basePatterns = new ArrayList<String>();
Expand Down Expand Up @@ -290,7 +294,14 @@ static List<String> getSupportedPatterns(boolean europeanDates) {
basePatterns.addAll(slashPatternsWithT);

List<String> timeZones = new ArrayList<>();
// uppercase Z => RFC822 TimeZone
basePatterns.forEach(p -> timeZones.add(p + "Z"));
basePatterns.forEach(p -> timeZones.add(p + " Z"));

// uppercase X => ISO8601 TimeZone
basePatterns.forEach(p -> timeZones.add(p + "XXX"));
basePatterns.forEach(p -> timeZones.add(p + " XXX"));

basePatterns.addAll(timeZones);

return basePatterns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ public void testDateConverterNegative() {
assertInvalidDate("20A4-11-08", null, false);
}

// test user-specified timezones and date formats specified at
// https://developer.salesforce.com/docs/atlas.en-us.dataLoader.meta/dataLoader/supported_data_types.htm
@Test
public void testUserSpecifiedTimeZoneIsUsed() throws Exception {
DateTimeConverter AsianTZDateConverter = new DateTimeConverter(TimeZone.getTimeZone("Asia/Tokyo"));
Expand Down Expand Up @@ -774,6 +776,51 @@ public void testUserSpecifiedTimeZoneIsUsed() throws Exception {
assertEquals(7, result.get(Calendar.DAY_OF_MONTH));
assertEquals(TimeZone.getTimeZone("America/Los_Angeles"), result.getTimeZone());

result = (Calendar) USTZDateConverter.convert(null, "2012-06-07 00:00:00 PST");
assertEquals(6, result.get(Calendar.MONTH) + 1);
assertEquals(7, result.get(Calendar.DAY_OF_MONTH));
assertEquals(TimeZone.getTimeZone("America/Los_Angeles"), result.getTimeZone());

result = (Calendar) USTZDateConverter.convert(null, "2012-06-07 00:00:00Pacific Standard Time");
assertEquals(6, result.get(Calendar.MONTH) + 1);
assertEquals(7, result.get(Calendar.DAY_OF_MONTH));
assertEquals(TimeZone.getTimeZone("America/Los_Angeles"), result.getTimeZone());

result = (Calendar) USTZDateConverter.convert(null, "2012-06-07 00:00:00 Pacific Standard Time");
assertEquals(6, result.get(Calendar.MONTH) + 1);
assertEquals(7, result.get(Calendar.DAY_OF_MONTH));
assertEquals(TimeZone.getTimeZone("America/Los_Angeles"), result.getTimeZone());

result = (Calendar) USTZDateConverter.convert(null, "2012-06-07 00:00:00GMT-08:00");
assertEquals(6, result.get(Calendar.MONTH) + 1);
assertEquals(7, result.get(Calendar.DAY_OF_MONTH));
assertEquals(TimeZone.getTimeZone("America/Los_Angeles"), result.getTimeZone());

result = (Calendar) USTZDateConverter.convert(null, "2012-06-07 00:00:00 GMT-08:00");
assertEquals(6, result.get(Calendar.MONTH) + 1);
assertEquals(7, result.get(Calendar.DAY_OF_MONTH));
assertEquals(TimeZone.getTimeZone("America/Los_Angeles"), result.getTimeZone());

result = (Calendar) USTZDateConverter.convert(null, "2012-06-07 00:00:00-08:00");
assertEquals(6, result.get(Calendar.MONTH) + 1);
assertEquals(7, result.get(Calendar.DAY_OF_MONTH));
assertEquals(TimeZone.getTimeZone("America/Los_Angeles"), result.getTimeZone());

result = (Calendar) USTZDateConverter.convert(null, "2012-06-07 00:00:00 -08:00");
assertEquals(6, result.get(Calendar.MONTH) + 1);
assertEquals(7, result.get(Calendar.DAY_OF_MONTH));
assertEquals(TimeZone.getTimeZone("America/Los_Angeles"), result.getTimeZone());

result = (Calendar) USTZDateConverter.convert(null, "2012-06-07 00:00:00-0800");
assertEquals(6, result.get(Calendar.MONTH) + 1);
assertEquals(7, result.get(Calendar.DAY_OF_MONTH));
assertEquals(TimeZone.getTimeZone("America/Los_Angeles"), result.getTimeZone());

result = (Calendar) USTZDateConverter.convert(null, "2012-06-07 00:00:00 -0800");
assertEquals(6, result.get(Calendar.MONTH) + 1);
assertEquals(7, result.get(Calendar.DAY_OF_MONTH));
assertEquals(TimeZone.getTimeZone("America/Los_Angeles"), result.getTimeZone());

result = (Calendar) AsianTZDateConverter.convert(null, "2012-06-07 00:00:00JST");
assertEquals(6, result.get(Calendar.MONTH) + 1);
assertEquals(7, result.get(Calendar.DAY_OF_MONTH));
Expand Down

0 comments on commit 2cfb7f9

Please sign in to comment.