Audit Trail : Default timezone for parsing DateTime in java action.

1
Hi there, So I have a project where we have attached the AuditTrail functionality to a person entity that has a date-of-birth. This date-of-birth(somehow), is expected to change over time. So naturally we monitor it with audit. I ran into a problem where no matter what date I gave this attribute, it would write the date in a UTC format resulting in a different DoB, even though I had selected a +2 timezone as the default. I soon figured out that it does this because inside the java action that does the magic for the audit trail, a hardcoded UTC timezone is retrieved when parsing dates to a string. I changed the hardcoded timezone to the code of the one that I wanted - that fixed the issue. My concern is that this is hardcoded and anyone with these requirements would need to do this manual fix. How can I retrieve the default Timezone and use that? (FYI the code you need to change is below). Files: CreateDeleteLog.java CreateLogObject.java CreateNewUpdateLog.java Code to look for: private String parseDate(Date date) { DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); TimeZone zone = TimeZone.getTimeZone("Africa/Johannesburg"); dateFormat.setTimeZone( zone ); String dateOutput = dateFormat.format(date); return dateOutput + "+2 Johannesburg"; }
asked
0 answers