1
votes

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>
1
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
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
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 machiQaiser Abbas
You can copy XPages code from Source tab and post it here in your question.Knut Herrmann
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

1 Answers

0
votes

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)