Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with timeZone. In Brazil when file contains date in this format yyyyMMdd. For example (<DTPOSTED>20190102). That information is parsed for 20190101. #30

Open
darlanads opened this issue Jan 11, 2019 · 2 comments

Comments

@darlanads
Copy link

Problem with timeZone. In Brazil when file contains date in this format yyyyMMdd. For example (20190102). That information is parsed for 20190101.

@stoicflame
Copy link
Owner

Do you have a proposed fix?

@edudoda
Copy link

edudoda commented Jan 10, 2020

Hi @darlanads, today I suffered the same problem as you.
This happens because Default implementation of StringConversion uses GMT time:
public static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone("GMT");

Usually OFX Date fields like <DTPOSTED>, <DTSERVER>, <DTSTART> ... (should) come with TimeZone explicitly (eg: <DTPOSTED>20180312120000[-3:BRT]</DTPOSTED>), but some banks/files are coming without it (like Banrisul, in my case: <DTPOSTED>20191203000000).

So the solution is to create a new class, implementing StingConversion and setting the default timezone to one you want: TimeZone.getTimeZone("Brazil/East") in my case.

Then when parseDate(String value) is invoked, it will not found an informed TimeZone and will use the one you specified.

public class StringConversionOfx implements StringConversion {

      public static final TimeZone GMT_TIME_ZONE = TimeZone.getTimeZone("Brazil/East");  
     //original default is: TimeZone.getTimeZone("GMT");
...

protected Date parseDate(String value) {
...
if (index < valueChars.length && valueChars[index] == '[') {
      String tzoffset = value.substring(index);
      calendar.setTimeZone(parseTimeZone(tzoffset));
    }
    else {
      calendar.setTimeZone(GMT_TIME_ZONE); //default
...  
  }
...  

To use it, just setConversion for AggregateUnmarshaller:

AggregateUnmarshaller a = new AggregateUnmarshaller(ResponseEnvelope.class);
 ResponseEnvelope re = null;    
 StringConversionOfx conv = new StringConversionOfx(); 
 	a.setConversion(conv);
     re = (ResponseEnvelope) a.unmarshal(reader);
   ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants