You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gc...@apache.org on 2009/07/27 19:35:16 UTC

svn commit: r798229 - in /myfaces/trinidad/branches/1.2.11.4-branch: trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/DateTimeConverter.java

Author: gcrawford
Date: Mon Jul 27 17:35:16 2009
New Revision: 798229

URL: http://svn.apache.org/viewvc?rev=798229&view=rev
Log:
TRINIDAD-1512 ConvertDateTime uses static GMT+x string for timezone display, doesn't update for daylight savings

Modified:
    myfaces/trinidad/branches/1.2.11.4-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java
    myfaces/trinidad/branches/1.2.11.4-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/DateTimeConverter.java

Modified: myfaces/trinidad/branches/1.2.11.4-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.4-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java?rev=798229&r1=798228&r2=798229&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.4-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java (original)
+++ myfaces/trinidad/branches/1.2.11.4-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java Mon Jul 27 17:35:16 2009
@@ -332,7 +332,7 @@
       throw new ClassCastException(_LOG.getMessage(
         "VALUE_IS_NOT_DATE_TYPE_IT_IS", new Object[]{value,value.getClass()}));
 
-    DateFormat format = _getDateFormat(context, getPattern(), false);
+    DateFormat format = _getDateFormat(context, getPattern(), false, (Date)value);
     return format.format(value);
   }
 
@@ -543,7 +543,7 @@
       if (pattern == null)
       {
         // get the pattern based on the style and type that has been set.
-        DateFormat format = getDateFormat(context, null, true);
+        DateFormat format = getDateFormat(context, null, true, null);
         if (format instanceof SimpleDateFormat)
         {
           pattern = ((SimpleDateFormat)format).toPattern();
@@ -687,7 +687,7 @@
     String pattern
     )
   {
-    DateFormat fmt = getDateFormat(context, pattern, true);
+    DateFormat fmt = getDateFormat(context, pattern, true, null);
     try
     {
       return fmt.parse(value);
@@ -1124,13 +1124,14 @@
   protected final DateFormat getDateFormat(
     FacesContext context,
     String pattern,
-    boolean forParsing
+    boolean forParsing,
+    Date    targetDate
     ) throws ConverterException
   {
     ConverterException exception = null;
     try
     {
-      DateFormat format = _getDateFormat(context, pattern, forParsing);
+      DateFormat format = _getDateFormat(context, pattern, forParsing, targetDate);
       return format;
     }
     catch (ConverterException ce)
@@ -1152,6 +1153,16 @@
    */
   protected TimeZone getFormattingTimeZone(TimeZone tZone)
   {
+    return getFormattingTimeZone (tZone, null);
+  }
+
+  /**
+   * Returns the timeZone for formatting and parsing the date. 
+   * TRINIDAD-1512: In some cases,timezone varies depending on the targetDate, 
+   * e.g. daylight savings.
+   */
+  protected TimeZone getFormattingTimeZone(TimeZone tZone, Date targetDate)
+  {
     return tZone;
   }
 
@@ -1171,7 +1182,7 @@
 
       try
       {
-        DateFormat format  = getDateFormat(context, null,false);
+        DateFormat format  = getDateFormat(context, null,false, null);
         if ((format != null) && (format instanceof SimpleDateFormat))
         {
           datePattern = ((SimpleDateFormat)format).toPattern();
@@ -1434,7 +1445,7 @@
   
   private String _getExample(FacesContext context, String pattern)
   {
-    DateFormat format = _getDateFormat(context, pattern, false);
+    DateFormat format = _getDateFormat(context, pattern, false, _EXAMPLE_DATE);
     return format.format(_EXAMPLE_DATE);
   }
 
@@ -1675,7 +1686,8 @@
   private DateFormat _getDateFormat(
     FacesContext context,
     String pattern,
-    boolean forParsing
+    boolean forParsing,
+    Date    targetDate
     )
   {
     Locale locale = _extractConverterLocale(context);
@@ -1769,7 +1781,7 @@
       // include timezone in date format
       if (tZone != null)
       {
-        TimeZone formatTZone = getFormattingTimeZone(tZone);
+        TimeZone formatTZone = getFormattingTimeZone(tZone, targetDate);
         format.setTimeZone(formatTZone);
       }
 

Modified: myfaces/trinidad/branches/1.2.11.4-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/DateTimeConverter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.11.4-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/DateTimeConverter.java?rev=798229&r1=798228&r2=798229&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.11.4-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/DateTimeConverter.java (original)
+++ myfaces/trinidad/branches/1.2.11.4-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/DateTimeConverter.java Mon Jul 27 17:35:16 2009
@@ -374,7 +374,7 @@
       {
         FacesContext context = FacesContext.getCurrentInstance();
         // this the pattern obtained by applying the styles
-        Object format = getDateFormat(context, null, false);
+        Object format = getDateFormat(context, null, false, null);
         if (format instanceof SimpleDateFormat)
         {
           applyPattern = ((SimpleDateFormat) format).toPattern();
@@ -436,25 +436,29 @@
    * these names are not available in client side JavaScript.
    */
   @Override
-  protected TimeZone getFormattingTimeZone(TimeZone tZone)
+  protected TimeZone getFormattingTimeZone(TimeZone tZone, Date targetDate)
   {
     TimeZone zone = (TimeZone) tZone.clone();
 
     // set the id as "GMT Sign Hours : Minutes"
     StringBuilder zoneId = new StringBuilder(9);
-    int rawOffset = zone.getRawOffset();
+    int offset; 
+    if (targetDate != null)
+      offset = zone.getOffset (targetDate.getTime());
+    else
+      offset = zone.getRawOffset();
 
-    if (rawOffset < 0)
+    if (offset < 0)
     {
       zoneId.append(_GMT_MINUS);
       // abs value
-      rawOffset = -rawOffset;
+      offset = -offset;
     } else
     {
       zoneId.append(_GMT_PLUS);
     }
 
-    int hours = rawOffset / _MILLIS_PER_HOUR;
+    int hours = offset / _MILLIS_PER_HOUR;
     if (hours < 10)
     {
       zoneId.append('0');
@@ -463,7 +467,7 @@
 
     zoneId.append(':');
 
-    int minutes = (rawOffset % _MILLIS_PER_HOUR) / _MILLIS_PER_MINUTE;
+    int minutes = (offset % _MILLIS_PER_HOUR) / _MILLIS_PER_MINUTE;
     if (minutes < 10)
     {
       zoneId.append('0');
@@ -484,7 +488,7 @@
     {
       try
       {
-        DateFormat format = getDateFormat(context, null, false);
+        DateFormat format = getDateFormat(context, null, false, null);
         if ((format != null) && (format instanceof SimpleDateFormat))
         {
           datePattern = ((SimpleDateFormat) format).toPattern();