1

I have small query in our office people are using two of regional settings on windows Operating System. Control Panel -> Regional and Languages Options 1) English(United States) 2) English ( United Kingdom)

As you are aware of the fact that this affect date and time formats, currency and number settings. My application developed in xpages creates conflicts where operating system regional settings is set to English(UK). On form submit button I get value from component and create date and time object as mentioned in below example where dateFrom is component name on xpage containing date&time control with validator and converter (dd.MM.yyyy).

When I run following code after submit button its works fine where operating systems settings are English(United States) but those clients who are using windows setting to English(United Kingdom) gets different results e.g. if one persons selects 08.09.2014 (September 08, 2014) in date from field when this code runs it creates object containing 09.08.2014 ( August 09, 2014)

    var dtFrom:NotesDateTime = session.createDateTime(getComponent("dateFrom").getValue()); 
    var weekDayStart = @Weekday(dtFrom.getDateOnly());
    var weekDayEnd = @Weekday(dtTo.getDateOnly());
    var warnMsg1 = viewScope.get("saturdayFlag");
    if ( weekDayStart == 7 && (warnMsg1 == null || warnMsg1 == "")) 
    { 
      getComponent("warningMessage").setValue("Warning: You are going start your leave on  SATURDAY. If you are OK with it than Press Submit Button."); 
      viewScope.put("saturdayFlag", "True"); 
      return "Warning1";
    }

I have lot of business rules dependent on this object. This thing is effecting my entire business logic and currently application is in production. Can you please look into it and let me know how handle this issue at configurations or code level. Your quick response in this regard will be highly appreciated.

Edited: Thanks for your time and efforts by understanding my pain related to this issue. Below xpage behave different on two workstations based on their regional settings because change in date format. How can I avoid Lotus Client should not take OS regional settings because this is working well on Browser.

   <?xml version="1.0" encoding="UTF-8"?>
    <xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:inputText id="dateFrom" style="width:%" required="true"
        disableClientSideValidation="true">
        <xp:this.validators>
            <xp:validateRequired message="Please select Date From">
            </xp:validateRequired>
        </xp:this.validators>
        <xp:this.converter>
            <xp:convertDateTime pattern="dd.MM.yyyy" type="date"
                ignoreUserTimeZone="true" dateStyle="default" locale="en_US"
                >
            </xp:convertDateTime>
        </xp:this.converter>
        <xp:dateTimeHelper></xp:dateTimeHelper>
    </xp:inputText>&#160;&#160;
    <xp:button value="Display DT Object" id="button1"><xp:eventHandler event="onclick" submit="true" refreshMode="complete">
    <xp:this.action>
        <xp:executeScript>
            <xp:this.script><![CDATA[#{javascript:var mDt:NotesDateTime =  session.createDateTime(getComponent("dateFrom").getValue());
var ni:NotesInternational = session.getInternational();

   if ( ni.isDateDMY())
   {    
    /// This Code is for English (United Kindom Settings)
    DATE_FORMAT = "dd/MM/yyyy"; 
        ///getComponent("inputText3").setValue(mDt.getDateOnly());//return; 
    ///var mDt3:Date = new  Date(mDt.toJavaDate());//I18n.parseDate(@Text(mDt.getDateOnly()), DATE_FORMAT,  I18n.getServerLocale() , I18n.getServerTimeZone());
    ///var mMonth = mDt3.getMonth() + 1;    
    //var mStr:string = @Text(mMonth)+"/"+mDt3.getDate()+"/"+mDt3.getFullYear();    
    //var mDt4:NotesDateTime =   session.createDateTime(mDt.toJavaDate().getMonth()+1+"/"+mDt.toJavaDate().getDate()+"/"+mDt.toJavaDate().getFullYear());   
/// var mDt4:NotesDateTime = session.createDateTime(@Text(mDt.toJavaDate()));
    ///getComponent("inputText5").setValue(    mDt.toJavaDate().getMonth()+1+"/"+mDt.toJavaDate().getDate()+"/"+mDt.toJavaDate().getFullYear());
        //mDt2:NotesDate
    //getComponent("inputText5").setValue(mDt9.toJavaDate() - mDt.toJavaDate());
    getComponent("inputText1").setValue(@Day(mDt.getDateOnly()));// Showing Day of Date Object; 
    getComponent("inputText2").setValue(@Month(mDt.getDateOnly())); // Showing Month of D ate Object    
    getComponent("inputText4").setValue(@Weekday(mDt.getDateOnly())); /// Showing Weekday of Date Object        
    }
   else
    {
   // This Code is for English ( United States) Regional Settings at OS LEVEL
      getComponent("inputText1").setValue(@Day(mDt.getDateOnly()));// Showing Day of Date Object;   
      getComponent("inputText2").setValue(@Month(mDt.getDateOnly())); // Showing Month of Date Object   
    getComponent("inputText4").setValue(@Weekday(mDt.getDateOnly())); //
}
}]]></xp:this.script>
        </xp:executeScript>
    </xp:this.action></xp:eventHandler></xp:button>


    <xp:br></xp:br>
    <xp:table>
        <xp:tr>
            <xp:td><xp:span style="font-weight:bold">Day is : </xp:span></xp:td>
            <xp:td><xp:inputText id="inputText1" style="font-weight:bold"></xp:inputText></xp:td>


        </xp:tr>
        <xp:tr>
            <xp:td><xp:span style="font-weight:bold">Month is :</xp:span></xp:td>
            <xp:td><xp:inputText id="inputText2" style="font-weight:bold"></xp:inputText></xp:td>


        </xp:tr>
        <xp:tr>
            <xp:td><xp:span style="font-weight:bold">weekDay  </xp:span></xp:td>
            <xp:td><xp:inputText id="inputText4" style="font-weight:bold"></xp:inputText></xp:td>


        </xp:tr>
        <xp:tr>
            <xp:td><xp:span style="font-weight:bold">Zone ID :</xp:span></xp:td>
            <xp:td><xp:inputText id="inputText5" style="font-weight:bold"></xp:inputText>  </xp:td>


        </xp:tr>
    </xp:table>
    </xp:view>
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
Qaiser Abbas
  • 113
  • 8
  • Please create and show us a complete simple XPage which shows what's going wrong. The code in your question doesn't reflect anything of your issue. – Knut Herrmann Sep 18 '14 at 13:24
  • I'd suggest going directly to the underlying datasource rather than using getComponent(). That will give you a DateTime value. At the moment you're crerating a DateTime using the server's regional settings, based on the value in the component, which I'm guessing is going to be a Java date. Going directly to the datasource may give a different result. – Paul Stephen Withers Sep 18 '14 at 13:35
  • Thanks guys for prompt response, I really appreciate your help. I am really sorry if I am able to explain my problem. I don't know how and where I can share a sample xPage? Now this above mentioned code behave differently on two workstations e.g. where OS regional settings are English (United States) its return right object with same day, month and year. where regional settings are Eng-UK it returns wrong values in date object as mentioned in my question. Please let me know to share db and for reproducing this issue you need to have two different machines or need to change settings your machi – Qaiser Abbas Sep 18 '14 at 14:42
  • You can copy XPages code from Source tab and post it here in your question. – Knut Herrmann Sep 18 '14 at 15:34
  • Thank @Knut I don't think so that will help because I am failed to explain my issue in details. Code is almost same and lot of other business logic but issue is windows operating system regional settings. When you have 2 settings on you windows clients where Lotus Rich Client is running this this object behave differently. – Qaiser Abbas Sep 19 '14 at 04:10
  • The issue appears in XPiNC only? Weird, on XPiNC I always get zeros pressing button in your sample XPage... – Knut Herrmann Sep 19 '14 at 07:02
  • Thanks for quick response. I appreciate your efforts to get me out from this difficult. Yes this issue only appear in XPiNC. Web somehow follow US settings. I have just copied the same code and pasted in xpages when run XPinNC its returning wrong day and month when I press this button. When I change regional settings to English US at OS level and restart my Lotus Client and gets accurate values. – Qaiser Abbas Sep 19 '14 at 07:48
  • Which Notes version you are on? – Knut Herrmann Sep 19 '14 at 08:01
  • @Knut Lotus Notes 8.5.2 Standard Configurations. I have also tried this on 8.5.3 but same results. – Qaiser Abbas Sep 19 '14 at 09:50

1 Answers1

0

I couldn't get to work your example code in my XPiNC. It set the values always to "0.0". But, the following code does work in my XPiNC:

var date:java.util.Date = getComponent("dateFrom").getValue();
var cal:java.util.Calendar = java.util.Calendar.getInstance();
cal.setTime(date);
getComponent("inputText1").setValue(cal.get(java.util.Calendar.DAY_OF_MONTH));  
getComponent("inputText2").setValue(cal.get(java.util.Calendar.MONTH) + 1);   
getComponent("inputText4").setValue(cal.get(java.util.Calendar.DAY_OF_WEEK));

Just replace the code in action script and stay with the rest of your example XPage.

Update:

The issue in your code is caused by using @Day, @Month, @Weekday and similar functions with a NotesDateTime's parameter. It has to be a Date parameter. Here is the definition

@Day(time:Date) : int
@Month(time:Date) : int
@WeekDay(time:Date) : int

Surprisingly, it works with NotesDateTime parameter in browser but it fails in XPiNC. Look at last comment here for a similar case.

Recommendation:

If you want to make sure it works in all environments then go with java.util.Date instead of NotesDateTime.

You get the java.util.Date value of a document's DateTime item with

var dateDoc:java.util.Date = document1.getItemValueDateTime("DateItem").toJavaDate();

You can calculate the difference of two dates with help of .getTime() which returns the number of milliseconds since January 1, 1970, 00:00:00 GMT. You get for example the difference in days with:

(date.getTime() - dateDoc.getTime()) / (1000*60*60*24)
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • Thanks I really appreciate your time invested on this petite issue. Actually I need to notes date and time object. I was displaying Month and Day only to check whether my date and time object is containing accurate value or not. Although you have invested lot of time on my issue. Can you please help me creating notes date and time object. Actually you can get day, month and year by using .toJavaDate() function after getting value from component. I hope you understand my requirement. Thanks for everything. – Qaiser Abbas Sep 19 '14 at 11:17
  • I'd like to know first if my example does work in your XPiNC environment for both language setting. – Knut Herrmann Sep 19 '14 at 11:34
  • True - Your example works perfectly fine in XPiNC in both language settings. – Qaiser Abbas Sep 19 '14 at 11:59
  • Great. As you can see NotesDateTime doesn't work well in XPiNC but Java's Date and Calendar do. I couldn't get NotesDateTime to work with my German settings neither. So, my recommendation: work with Date and the other Java classes. You can do all things NotesDateTime can and even much more. – Knut Herrmann Sep 19 '14 at 12:15
  • thanks for your efforts. Actually I am badly stuck application has been developed on this thing and just came to know that dateandtime object is not working on XPiNC. This is great trouble for me frankly speaking. I need to find any solution keeping ground realities in mind. I am using date and time difference function in entire code. Kindly let me know should I explore Locale, I18n date_format functions or other things which might help? Because I personally think there should be some solution of this situation. Please guide – Qaiser Abbas Sep 20 '14 at 14:28
  • Don't be scared of java.util.Date. I added an example how to calculate the difference of two dates. Do you feel able to adapt your code or do you need to know something else? – Knut Herrmann Sep 21 '14 at 17:08
  • Thank you so much. Actually my 1st priority is to find some solution in notes date and time object because I need to do lot of changes in my existing code which is lengthy and time taking e.g. code changes, scenario testing etc otherwise if I am unable to find any solution than I need to go with this solution. – Qaiser Abbas Sep 22 '14 at 03:49
  • As I wrote in my answer: not NotesDateTime is the issue but calling @Day, @Month and similar functions with NotesDateTime as parameter. So, you should be fine with `@Day(mDt.toJavaDate())`. This way you can stay with NotesDateTime. I just recommended to use Java classes as you will switch sooner or later from SSJS to Java anyway :-) ... – Knut Herrmann Sep 22 '14 at 06:01
  • Thank you so much. I really appreciate your time, effort and help. You really made my day :) – Qaiser Abbas Sep 22 '14 at 07:40
  • How can I make date object with accurate day, month and year (in UK based regional settings) and save as notes record e.g. binding through script? because when replace item with mDt.toJavaDate() is throughing exception and mDt.getDateOnly() swaps day and month? – Qaiser Abbas Sep 22 '14 at 07:46
  • This worked for me: `document1.setValue("DateItemInDoc", session.createDateTime(date));` with date as a java.util.Date value. – Knut Herrmann Sep 22 '14 at 07:51
  • Thanks for your help and you are really detailed oriented person. I really appreciate and it was nice interaction with you and really happy to learn that people on stackoverflow are understanding the pain of others. Always be happy and keep other's happy. – Qaiser Abbas Sep 22 '14 at 08:37
  • I am happy I could help you :-) - Good luck with your project. – Knut Herrmann Sep 22 '14 at 08:42