Select to view content in your preferred language

Bug - One day Earlier

3312
7
02-21-2014 06:43 AM
ionarawilson1
Deactivated User
I am having that bug where the attribute table and the attribute inspector show the dates as one day earlier. I found a possible solution on the web but there is an error in the following line because the attribute inspector has no "form" property. Is there any way to get around this? Thanks

error in this line

    var formItems:* = editor.attributeInspector.form.getChildren();

/ Place the following code below the function populateEditor
private var dateFormatter:DateFormatter = new DateFormatter();

private const newDateFormat:String = �??DD/MM/YYYY�?�;

private function attributeInspector_showFeatureHandler(event:AttributeInspectorEvent):void
{
   formatDateFieldDisplay(event);
}
private function attributeInspector_updateFeatureHandler(event:AttributeInspectorEvent):void
{
   formatDateFieldDisplay(event);
}
private function formatDateFieldDisplay(event:AttributeInspectorEvent):void
{
   if(!(event.featureLayer && event.feature && event.feature.attributes))
      return;
   // This ensures that we only validate when we are working at a field level
   (not an AttributeInspector level)
   if(event.field)
   {
      if(event.field.type == Field.TYPE_DATE)
      {
         if(event.newValue) // If it comes exclusively from an update �?� format the display
         {
            // Change the date format as desired
            event.target.formatString = newDateFormat;
         }
      }
   }
   else if(event.type.toLowerCase() == �??showfeature�?�)
   {
      var formItems:* = editor.attributeInspector.form.getChildren();
     
      // Loop items and trigger update event
      for (var i:Number = 0; i < formItems.length; i++)
      {
         if(formItems.data && formItems.data is Field)
         {
            var field:Field = formItems.data;
            if(field.type == Field.TYPE_DATE &&
               field.name in event.feature.attributes &&    
               event.feature.attributes[field.name])
            {
               var event:AttributeInspectorEvent = new AttributeInspectorEvent(�??updateFeature�?�,
                                                                 true,
                                                                 event.featureLayer,
                                                                 event.feature,
                                                                 field,
                                                                 event.feature.attributes[field.name],
                                                                 event.feature.attributes[field.name]);
               var formItem:* = formItems.getChildren();
               if(formItem && formItem.length > 0)
                  formItem[0].dispatchEvent(event);
            }
         }
      }
   }
}

// This function should be in a separate util file to be reused if necessary by other classes.
// This function comes with the ArcGIS Viewer for Flex 2.4.
// If Esri updates this function so should the developer.
private function msToDate(ms:Number, dateFormat:String, useUTC:Boolean):String
{
   var date:Date = new Date(ms);
   if (date.milliseconds == 999) // Workaround for REST bug
      date.milliseconds++;

   if (useUTC)
      date.minutes += date.timezoneOffset;
   if (dateFormat)
   {
      dateFormatter.formatString = dateFormat;
      var result:String = dateFormatter.format(date);
     
      if (result)
         return result;
      else
         return dateFormatter.error;
   }
   else
   {
      return date.toLocaleString();
   }
}




Source:
http://pm4gis.wordpress.com/2011/09/15/change-the-date-format-of-the-attributeinspector-editwidget-m...
Tags (2)
0 Kudos
7 Replies
BjornSvensson
Esri Regular Contributor
That code is quite old.  In fact, the blog post mentions that it's for 2.4.

Since then we added support in the API, Viewer and AppBuilder to allow you to specify useUTC and setting the date format.  So you should not need to do what that code was meant for.

What version are you using?
Have you tried those options?

http://resources.arcgis.com/en/help/flex-viewer/concepts/index.html#/Attribute_Table_widget_tags/01m...
0 Kudos
ionarawilson1
Deactivated User
Hi Bjorn,

Thank you for replying. I am using 3.5. How can I specify useUTC in the code? Also, can you please take a look at this thread on the link below?
I think only people that work for ESRI probably know what the problem is:

http://forums.arcgis.com/threads/102778-Attribute-Table-does-not-honor-subtypes

P.S. I am going to the Summit, hope to attend one of your sessions. Thanks
0 Kudos
BjornSvensson
Esri Regular Contributor
If you're not working with the Viewer, take a look in the skins\AttributeInspectorSkin.mxml
<fx:Component id="dateField">
    <!--
    Display dates in local time, using a localized short date format. eg: for en_US: MM/DD/YYYY
    See PopUpFieldFormat date formats or provide a custom one.
    -->
    <fieldClasses:CalendarField dateFormat="shortDate" useUTC="false"/>
</fx:Component>


The documentation for PopUpFieldFormat is at https://developers.arcgis.com/flex/api-reference/com/esri/ags/portal/supportClasses/PopUpFieldFormat...

There is also a vaguely related sample at https://developers.arcgis.com/flex/sample-code/attribute-inspector-edit.htm
0 Kudos
ionarawilson1
Deactivated User
Thank you Bjorn. When I use UseUTC= "true", it works! The attribute inspector now shows the correct date. I will try to change the skin for the attribute table also. Thank you so much!!!
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Ionara,

   In the AttributeTableSkin.mxml

    <fx:Declarations>
        <supportClasses:AttributeTableOptionsMenu id="optionsMenu"
                                                  addedToStage="optionsMenu_addedToStageHandler(event)"
                                                  dataGrid="{dataGrid}"
                                                  removedFromStage="optionsMenu_removedFromStageHandler(event)"
                                                  rollOut="{optionsMenu.remove()}"/>
        <fx:Component id="codedValueDomainField">
            <fieldClasses:CodedValueDomainField/>
        </fx:Component>
        <fx:Component id="dateField">
            <fieldClasses:CalendarField useUTC="true"/>
        </fx:Component>
        <fx:Component id="doubleField">
            <fieldClasses:DoubleField/>
        </fx:Component>
        <fx:Component id="integerField">
            <fieldClasses:IntegerField/>
        </fx:Component>
        <fx:Component id="labelField">
            <fieldClasses:LabelField/>
        </fx:Component>
        <fx:Component id="memoField">
            <fieldClasses:MemoField/>
        </fx:Component>
        <fx:Component id="rangeDomainField">
            <fieldClasses:RangeDomainField/>
        </fx:Component>
        <fx:Component id="singleField">
            <fieldClasses:DoubleField/>
        </fx:Component>
        <fx:Component id="smallIntegerField">
            <fieldClasses:IntegerField/>
        </fx:Component>
        <fx:Component id="stringField">
            <fieldClasses:StringField/>
        </fx:Component>
        <fx:Component id="typeField">
            <fieldClasses:TypeField/>
        </fx:Component>
    </fx:Declarations>
0 Kudos
ionarawilson1
Deactivated User
Yes, Robert! Thank you!!!
0 Kudos
ionarawilson1
Deactivated User
Thank you Bjorn and Robert. Both attribute inspector and attribute table are showing the correct dates now thanks to your help!!!
0 Kudos