Return-Path: Delivered-To: apmail-jakarta-velocity-dev-archive@apache.org Received: (qmail 21122 invoked from network); 14 May 2002 12:41:03 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 14 May 2002 12:41:03 -0000 Received: (qmail 10970 invoked by uid 97); 14 May 2002 12:41:03 -0000 Delivered-To: qmlist-jakarta-archive-velocity-dev@jakarta.apache.org Received: (qmail 10929 invoked by uid 97); 14 May 2002 12:41:02 -0000 Mailing-List: contact velocity-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Velocity Developers List" Reply-To: "Velocity Developers List" Delivered-To: mailing list velocity-dev@jakarta.apache.org Received: (qmail 10917 invoked by uid 98); 14 May 2002 12:41:01 -0000 X-Antivirus: nagoya (v4198 created Apr 24 2002) Message-ID: <00e301c1fb44$604d2160$0501a8c0@turin.savoirweb.com> From: "Claude Brisson" To: "Velocity Developers List" References: <009501c1ef95$13de8400$a102a8c0@zeus.esha.com> <3CD1A571.50507@teamup.ch> <016a01c1f224$831265d0$a102a8c0@zeus.esha.com> <3CD2B172.2020406@teamup.ch> <025d01c1f547$1889ed20$a102a8c0@zeus.esha.com> <058701c1f7a9$62b669a0$a102a8c0@zeus.esha.com> <00aa01c1fa92$695a7670$a102a8c0@zeus.esha.com> Subject: [Veltools] Proposed patch for the DateTool Date: Tue, 14 May 2002 14:39:22 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_00E0_01C1FB55.233EE180" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------=_NextPart_000_00E0_01C1FB55.233EE180 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi all. Here is a proposed patch for DateTool : a new toDate(format,object) method that allows the parsing of a date according to the specified format. The format is used only if the passed object is not of Date or Calendar type (hence expected to be a String) : this is homogeneic with the existing toDate(obj) method. Sincerely, CloD ------=_NextPart_000_00E0_01C1FB55.233EE180 Content-Type: application/octet-stream; name="dateformat.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="dateformat.patch" diff -ur = jakarta-velocity-tools/tools/src/java/org/apache/velocity/tools/tools/Dat= eTool.java = patched-tools/tools/src/java/org/apache/velocity/tools/tools/DateTool.jav= a=0A= --- = jakarta-velocity-tools/tools/src/java/org/apache/velocity/tools/tools/Dat= eTool.java Tue May 14 12:13:05 2002=0A= +++ = patched-tools/tools/src/java/org/apache/velocity/tools/tools/DateTool.jav= a Tue May 14 12:47:12 2002=0A= @@ -249,6 +249,44 @@=0A= return null;=0A= }=0A= }=0A= + =0A= + =0A= + /**=0A= + * Returns a Date object representing the specified date, parsed = with the specified format if it is a string=0A= + * =0A= + * This method uses the same parsing instructions as =0A= + * {@link SimpleDateFormat}:=0A= + *=0A= + * @param format the format to use to parse obj if it is a String=0A= + * @param obj the date to convert=0A= + *=0A= + * @return the converted date=0A= + */=0A= + public static Date toDate(String format,Object obj)=0A= + {=0A= + if (obj =3D=3D null)=0A= + {=0A= + return null;=0A= + }=0A= + if (obj instanceof Date)=0A= + {=0A= + return (Date)obj;=0A= + }=0A= + if (obj instanceof Calendar)=0A= + {=0A= + return ((Calendar)obj).getTime();=0A= + }=0A= + try=0A= + {=0A= + //try treating obj as a string and parsing it=0A= + SimpleDateFormat parser =3D new SimpleDateFormat(format);=0A= + return parser.parse(String.valueOf(obj));=0A= + }=0A= + catch (Exception e)=0A= + {=0A= + return null;=0A= + }=0A= + }=0A= =0A= =0A= /**=0A= ------=_NextPart_000_00E0_01C1FB55.233EE180 Content-Type: text/plain; charset=us-ascii -- To unsubscribe, e-mail: For additional commands, e-mail: ------=_NextPart_000_00E0_01C1FB55.233EE180--