Select to view content in your preferred language

Default date of 1970 for date field at 2.3

5326
15
06-09-2011 12:22 AM
MarkSmith
Occasional Contributor
Hello,

I have a date field in my layer with no default value defined in the database.  Users then use an API with the editor and attribute inspector to create features and populate the attributes - normal stuff.

At 2.2 when the user creates a shape, the attribute inspector pops up and the date field is empty.  If they click the field the date picker appears conveniently on today's date.  This is the behaviour I want and expect.

Now at 2.3 when the attribute inspector opens after adding a new shape, there is a date already in the date field of 01/01/1970.  It's not just me either, the Validate Attribute sample does the same thing: http://help.arcgis.com/en/webapi/javascript/arcgis/demos/ed/ed_attributeInspectorValidate.html

Can anyone please tell me how to fix this?
0 Kudos
15 Replies
TonyContreras
Deactivated User
Here is a site that explains the default date.

Javascript Epoch
0 Kudos
ReneeMaxwell
Regular Contributor
I have the same question. The link posted above is not helpful at all. How is it possible to override this default behavior with the attribute inspector?

I don't think it's reasonable to expect users to click 41 times from 1970 to 2011 just to set a date.
0 Kudos
HemingZhu
Frequent Contributor
I have the same question. The link posted above is not helpful at all. How is it possible to override this default behavior with the attribute inspector?

I don't think it's reasonable to expect users to click 41 times from 1970 to 2011 just to set a date.


I was also perplexed by why it is changed from 2.2 for no good reasons. I have tried to overwrit this by the following code without success. Can ESRI or anyone enlight me on this?

code added on http://help.arcgis.com/en/webapi/javascript/arcgis/demos/ed/ed_attributeInspectorValidate.html
....
var myDateDijit = new dijit.form.DateTextBox({
                //regExp: "/^(1[0-2]|0?[1-9])\/(3[01]|[12]\d|0?[1-9])\/(\d{2,4})$/",
                required: false,
                promptMessage: "Enter a date",
                invalidMessage: "Enter valid date",
                //constraints: { min: dojo.date.locale.format(new Date(), { datePattern: 'MM/dd/yyyy', selector: 'date' }) },
                value: "" //defalut value
            });
.....

var layerInfos = [{
                'featureLayer': featureLayer,
                'showAttachments': false,
                'showDeleteButton': false,
                'fieldInfos': [
            { 'fieldName': 'name', 'label': 'Name' },
            { 'fieldName': 'email', 'label': 'Email' },
            { 'fieldName': 'phone', 'label': 'Phone', 'customField': myDijit },
            { 'fieldName': 'note', 'label': 'Details', 'stringFieldOption': esri.dijit.AttributeInspector.STRING_FIELD_OPTION_TEXTAREA },
            { 'fieldName': 'notedate', 'label': 'Date', 'customField': myDateDijit }
          ]
}];
....
0 Kudos
KellyHutchins
Esri Frequent Contributor
The attribute inspector date calendar displays the date stored in the feature's date field. New fields don't have a value so the default date of January 1, 1970 is displayed. You can modify this by setting the date's value to the current date (or whatever value you'd like) when a new feature is created. To do this listen for the feature layer's 'onBeforeApplyEdits' event and update the date for the newly added feature(s). In the sample below 'pointsOfInterest' is the feature layer whose date field you want to update.

        dojo.connect(pointsOfInterest,"onBeforeApplyEdits",function(adds,updates,deletes){
          //update the date field for new features to be today's date.
            dojo.forEach(adds,function(add){
              add.attributes.notedate = new Date().getTime();
            });
        });

0 Kudos
HemingZhu
Frequent Contributor
The attribute inspector date calendar displays the date stored in the feature's date field. New fields don't have a value so the default date of January 1, 1970 is displayed. You can modify this by setting the date's value to the current date (or whatever value you'd like) when a new feature is created. To do this listen for the feature layer's 'onBeforeApplyEdits' event and update the date for the newly added feature(s). In the sample below 'pointsOfInterest' is the feature layer whose date field you want to update.

        dojo.connect(pointsOfInterest,"onBeforeApplyEdits",function(adds,updates,deletes){
          //update the date field for new features to be today's date.
            dojo.forEach(adds,function(add){
              add.attributes.notedate = new Date().getTime();
            });
        });



What a smart solution i miss! thanks Kelly!!
0 Kudos
ReneeMaxwell
Regular Contributor
Kelly, that solution may be fine for newly created features. However, it doesn't address the problem for existing features. The attribute inspector displays attributes for existing features as well, and now any date field that has not been populated displays as 1-1-1970, even if it is null. This is confusing and misleading to users who might not realize how databases operate, but are simply querying a feature.

Not all date fields require a value for every record, so it would be nice if we could solve this problem without having to force edits that are not relevant or accurate in every case.

As others have mentioned, the default behavior of this dijit changed after the release of 2.3. We clearly liked it better before.
0 Kudos
MarkSmith
Occasional Contributor
Thank you Renee, I'd like to echo your comments.  The date field worked just fine at 2.2, this is definitely a backwards step at 2.3.  If anyone has a code solution for this I'd be grateful to see it, but in the meantime we're sticking with 2.2 for our editing APIs.

Thanks,

Mark.
0 Kudos
HemingZhu
Frequent Contributor
Thank you Renee, I'd like to echo your comments.  The date field worked just fine at 2.2, this is definitely a backwards step at 2.3.  If anyone has a code solution for this I'd be grateful to see it, but in the meantime we're sticking with 2.2 for our editing APIs.

Thanks,

Mark.


I agree with Mark. ESRI should look into this issue. At the same time, Except for the Kelly's suggestion, i found a workaround for edit feature for my purpose. Here is the code:

dojo.connect(pointsOfInterest, "onSelectionComplete", function(features) {

                dojo.forEach(features, function(feature) {
                    if (feature.attributes.notedate==null)
                    {
                        feature.attributes.notedate = {};
                    }                
                });
            });
Hope it helps
0 Kudos
KellyHutchins
Esri Frequent Contributor
I thought you were trying to set a default value. If the behavior has changed between 2.2 and 2.3 that may be a bug. I'll take a closer look.
0 Kudos