error in date items, daylight Saving

帅比萌擦擦* 提交于 2019-12-12 01:23:50

问题


Summer dates in an input control which are before 1981 are recalculated (I think with daylight saving time).

e.g. e.g. I enter 27.8.1960 - after a save I got 26.8.1960, (after the next save 25.8.1960 and so on) but 27.8.2010 - after a save it stayed the same: 27.8.2010

"Winter dates": 27.4.1960 - after a save it stayed the same: 27.4.1960

looks like an ugly bug. how can I supress this "calculation"?

(date format is Europeen, I live in Germany. 27.8.1960 is August 27, 1960)

thanks for any help, Uwe

<xp:inputText value="#{Auftrag.MF_GebDatum}" id="mF_GebDatum1" style="width:255px">
    <xp:this.converter>
        <xp:convertDateTime type="date"></xp:convertDateTime>
    </xp:this.converter>
</xp:inputText>

回答1:


The problem you are fighting with is that Domino stores a datetime value with the daylight saving information which does not exists for the dates you are entering. The information for the timezone to use comes from the current user locale and / or the server.

Your date is stored in a field with the timezone it was entered (+2h GMT)

26.08.1960 00:00:00 CEDT

Domino interprets the stored value as it is, without adjusting it

var ndt:NotesDateTime = session.createDateTime("26.08.1960 00:00:00 CEDT");
ndt.getGMTTime()

returns the correct datetime value, adjusted by 2 hours for GMT

25.08.60 22:00:00 GMT

While converted back to Java, it is interpreted "correctly" that there was never a daylight saving time in 1960, that's why it will be adjusted only by 1 hour:

var ndt:NotesDateTime = session.createDateTime("26.08.1960 00:00:00 CEDT");
ndt.toJavaDate().toLocaleString()

will result in "25.08.1960 23:00:00" if you are in the CEDT timezone.

Currently the only idea I have for an easy workaround is to kill the Timezone information in the DateTime field. To do this you can use this SSJS script:

<xp:this.querySaveDocument>
   <![CDATA[#{javascript:
      var doc:NotesDocument = document1.getDocument( true );
      var items:java.util.Vector = doc.getItems();
      var item:NotesItem;
      var ndt:NotesDateTime;
      var dt:java.util.Date;

      for( var i=0; i<items.size(); i++){
         item = items.get(i);
         if( item.getType() === 1024 ){
            ndt = item.getValueDateTimeArray().get(0);  
            ndt = session.createDateTime( ndt.getDateOnly());
            item.setDateTimeValue( ndt );
            ndt.recycle();
         }
         item.recycle();
      }
   }]]>
</xp:this.querySaveDocument>


来源:https://stackoverflow.com/questions/14275752/error-in-date-items-daylight-saving

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!