From ccfedec8a642a890a533eacc0f2dee1cf5a77814 Mon Sep 17 00:00:00 2001 From: Enrique Zamudio Date: Wed, 18 Dec 2013 18:13:42 -0600 Subject: [PATCH] format with timezone for #21 --- src/main/java/com/solab/iso8583/IsoType.java | 22 +++++++++++++------ src/main/java/com/solab/iso8583/IsoValue.java | 12 +++++++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/solab/iso8583/IsoType.java b/src/main/java/com/solab/iso8583/IsoType.java index 2a74328..eb1b1d6 100644 --- a/src/main/java/com/solab/iso8583/IsoType.java +++ b/src/main/java/com/solab/iso8583/IsoType.java @@ -19,7 +19,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA package com.solab.iso8583; import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.util.Date; +import java.util.TimeZone; /** Defines the possible values types that can be used in the fields. * Some types required the length of the value to be specified (NUMERIC @@ -76,17 +78,23 @@ public enum IsoType { /** Formats a Date if the receiver is DATE10, DATE4, DATE_EXP or TIME; throws an exception * otherwise. */ - public String format(Date value) { + public String format(final Date value, final TimeZone tz) { + final SimpleDateFormat sdf; if (this == DATE10) { - return String.format("%Tm% implements Cloneable { private CustomField encoder; private int length; private String encoding; + private TimeZone tz; public IsoValue(IsoType t, T value) { this(t, value, null); @@ -172,6 +174,14 @@ public class IsoValue implements Cloneable { return encoding; } + /** Sets the timezone, useful for date fields. */ + public void setTimeZone(TimeZone value) { + tz = value; + } + public TimeZone getTimeZone() { + return tz; + } + /** Returns the formatted value as a String. The formatting depends on the type of the * receiver. */ public String toString() { @@ -195,7 +205,7 @@ public class IsoValue implements Cloneable { } else if (type == IsoType.LLVAR || type == IsoType.LLLVAR) { return encoder == null ? value.toString() : encoder.encodeField(value); } else if (value instanceof Date) { - return type.format((Date)value); + return type.format((Date)value, tz); } else if (type == IsoType.BINARY) { if (value instanceof byte[]) { final byte[] _v = (byte[])value;