PDA

View Full Version : Time Picker Zone



aliabdulla
Jan 12, 2021, 7:25 AM
Hello,

I'm using "TimeField" as per below window, the system/server time zone is GMT+3 but the posted time comes in different time zone.

Consider this scenario:

1. I try to add information and I input the followings:

Open Date: 13-Jan-2021
Open Time: 08:00:00
Close Date: 13-Jan-2021
Close Time: 09:00:00

Look for screenshot:

25493

2. After adding, the time posted to adding function is as following:

25494

HTML Code:



<ext:Window
ID="AddBidInfoWindow"
runat="server"
Icon="Box"
Hidden="true"
Closable="true"
Title="Add new bid"
AutoScroll="true"
Scroll="Both"
Width="600"
Height="460"
PaddingSpec="0 0 0 0"
MarginSpec="0 0 0 0"
ClientIDMode="Static"
Resizable="true"
BodyStyle="background-color:#fff;"
BodyPadding="5"
Layout="Form">
<Listeners>
<Show Handler="positionWindow(this);"/>
</Listeners>
<Items>
<ext:FormPanel
runat="server"
ID="AddBidInfoWindowPnl"
PaddingSpec="0 0 0 0"
MarginSpec="0 0 0 0"
MaxWidth="550"
MaxHeight="380"
Hidden="false"
Header="false"
ClientIDMode="Static"
Layout="FormLayout"
ButtonAlign="Right"
Frame="false" >
<Items>
<ext:TextField
runat="server"
AllowBlank="false"
ClientIDMode="Static"
ID="txtTitle"
FieldLabel="Title"
BlankText="Title is Required"
LabelAlign="Right" >
</ext:TextField>
<ext:TextArea
runat="server"
AllowBlank="false"
ClientIDMode="Static"
ID="txtDescription"
FieldLabel="Description"
BlankText="Description is Required"
LabelAlign="Right" >
</ext:TextArea>
<ext:DateField
ID="OpenDate"
MinWidth="110"
ReadOnly="false"
FieldLabel="Open Date"
runat="server"
ClientIDMode="Static"
Format="dd-MM-yyyy"
BlankText="Open Date is Required"
AllowBlank="false"
EnableKeyEvents="true">
</ext:DateField>
<ext:TimeField
ID="OpenTime"
MinWidth="110"
FieldLabel="Open Time"
ReadOnly="false"
runat="server"
ClientIDMode="Static"
Increment="30"
Format="HH:mm:ss"
BlankText="Open Time is Required"
AllowBlank="false"
EnableKeyEvents="true">
</ext:TimeField>
<ext:DateField
ID="CloseDate"
MinWidth="110"
FieldLabel="Close Date"
ReadOnly="false"
runat="server"
ClientIDMode="Static"
Format="dd-MM-yyyy"
BlankText="Close Date is Required"
AllowBlank="false"
EnableKeyEvents="true">
</ext:DateField>
<ext:TimeField
ID="CloseTime"
MinWidth="110"
ReadOnly="false"
FieldLabel="Close Time"
runat="server"
ClientIDMode="Static"
Increment="30"
Format="HH:mm:ss"
BlankText="Close Time is Required"
AllowBlank="false"
EnableKeyEvents="true">
</ext:TimeField>
</Items>
<Buttons>
<ext:Button runat="server" Icon="Key" Text="Add" >
<DirectEvents>
<Click OnEvent="addNewBidInfo" IsUpload="true" Before="if (#{AddBidInfoWindowPnl}.getForm().isValid()) {return true;} else {return false;}">
<EventMask ShowMask="true" Msg="Adding..." Target="CustomTarget" CustomTarget="={#{AddBidInfoWindowPnl}.body}" />
<ExtraParams>
<ext:Parameter
Name="mytxtTitle"
Value="#{txtTitle}.getValue()"
Mode="Raw"
Encode="false" />
<ext:Parameter
Name="mytxtDescription"
Value="#{txtDescription}.getValue()"
Mode="Raw"
Encode="false" />
<ext:Parameter
Name="myOpenDate"
Value="#{OpenDate}.getValue()"
Mode="Raw"
Encode="false" />
<ext:Parameter
Name="myOpenTime"
Value="#{OpenTime}.getValue()"
Mode="Raw"
Encode="false" />
<ext:Parameter
Name="myCloseDate"
Value="#{CloseDate}.getValue()"
Mode="Raw"
Encode="false" />
<ext:Parameter
Name="myCloseTime"
Value="#{CloseTime}.getValue()"
Mode="Raw"
Encode="false" />
</ExtraParams>
</Click>
</DirectEvents>
</ext:Button>
<ext:Button runat="server" Icon="Decline" Text="Cancel" >
<Listeners>
<Click Fn="closeAddBidInfoWindow" />
</Listeners>
</ext:Button>
</Buttons>
</ext:FormPanel>
</Items>
</ext:Window>


VB Code:



<DirectMethod>
Function addNewBidInfo(sender As Object, e As DirectEventArgs) As Boolean

Dim Title As String = e.ExtraParams("mytxtTitle").Trim
Dim Description As String = e.ExtraParams("mytxtDescription").Trim

Dim MyDateParts1() As String = e.ExtraParams("myOpenDate").ToString.Trim.Split("T")
Dim OpenDate As String = DateTime.Parse(MyDateParts1(0)).AddDays(1).ToStrin g("dd-MMM-yyyy")

Dim MyTimeParts1() As String = e.ExtraParams("myOpenTime").ToString.Trim.Split("T")
Dim OpenTime As String = DateTime.Parse(MyTimeParts1(1)).ToString("HH:mm:ss")

Dim MyDateParts2() As String = e.ExtraParams("myCloseDate").ToString.Trim.Split("T")
Dim CloseDate As String = DateTime.Parse(MyDateParts2(0)).AddDays(1).ToStrin g("dd-MMM-yyyy")

Dim MyTimeParts2() As String = e.ExtraParams("myCloseTime").ToString.Trim.Split("T")
Dim CloseTime As String = DateTime.Parse(MyTimeParts2(1)).ToString("HH:mm:ss")

Dim ValidationMSG As String = ""

If Title.Trim = "" Then
ValidationMSG &= "<br/>- Title is Required"
End If

If Description.Trim = "" Then
ValidationMSG &= "<br/>- Description is Required"
End If

If OpenDate.Trim = "" Then
ValidationMSG &= "<br/>- Open Date is Required"
End If

If OpenTime.Trim = "" Then
ValidationMSG &= "<br/>- Open Time is Required"
End If

If CloseDate.Trim = "" Then
ValidationMSG &= "<br/>- Close Date is Required"
End If

If CloseTime.Trim = "" Then
ValidationMSG &= "<br/>- Close Time is Required"
End If

If ValidationMSG <> "" Then
Ext.Net.X.Msg.Alert("Errors", ValidationMSG).Show()
Return False
Else

Dim CreationDate As String = clsGeneral.getCreationDate()
Dim CreationTime As String = clsGeneral.getCreationTime()

Dim strSQL As String = clsSQL.insertBidInfo(Title, Description, OpenDate,
OpenTime, CloseDate, CloseTime,
"1", CreationDate, CreationTime)

Dim suc As Integer = clsDB.ExecuteSQL(strSQL)

If suc > -1 Then
Ext.Net.X.Msg.Alert("Done", "Bid infomation has been added successfully").Show()
clsLog.logUserActions("Bid infomation has been added successfully [" & Title.Replace("'", "''").Trim & "]")
' Close popup
AddBidInfoWindow.Close()
clearAllFeilds()
loadBidList()
Return True
Else
clsLog.logErrors("addNewBidInfo: SQL Error: " & strSQL)
Ext.Net.X.Msg.Alert("Error", "Error occurred while adding information, please contact admin").Show()
Return False
End If

End If

Return True
End Function


Kindly, advice.

fabricio.murta
Jan 12, 2021, 12:22 PM
Hello @aliabdulla!

I am afraid at some point in your code you are treating dates as GMT and other points as local time. You should settle at one for consistency. You should check at which point the date is switching and decide on converting it back/forth as it fits.

In the code you shared I don't see where the date may be switching or being re-converted. You should step thru the actual program with a debugger and check the date values for signs when they are converted (where they show different values). The issue may be somewhere else.

Unfortunately date conversions to-from GMT are outside Ext.NET components' logic. In case you identify it is being converted at client-side or during submission we could provide guidance as how to avoid this -- or consistently convert it back.

Some key points you should look for:
- in the field right after filling (before submit)
- in the submitted form (or in the server's receive time)
- when you convert between string (e.ExtraParams("myOpenDate")) and DateTime (OpenTime and CloseTime)
- when you push the data to the database (the stored data in the database when you perform a select from)
- the DateTime value after you fetch back from the database
- the grid data at server-side
- the received request contents
- the grid value in store (App.GridPanel1.getStore().getAt(0).data.openTime)
- the displayed grid value

Notice this is not necessarily being converted just once, so an analysis should probably check over the date all the way. Fact is that at some point you are assuming the date is in GMT (even thought it is in local time) and re-converting it -- or you are converting the date to GMT to store it, then converting back to the browser which may be in another time zone (not GMT+3) thus you get that 2-hour shift instead of the expected 3-hour.

This is the best we can help with what provided. To further here, I'm afraid we'd need a runnable test case so we can actually debug the time data across the whole process, in case you find that Ext.NET is doing the conversion (during client-server communication, etc).

Hope this helps!

aliabdulla
Jan 13, 2021, 6:31 AM
Dear @fabricio.murta,

I'm taking care of this conversion through the website and also our server has been updated with GMT+3 setting to avoid this problem.

I can add the hours shift to posted time but this is not convenient solution.

The issue is little bit strange as I select specific value from time picker, but the value posted to server is something else.

fabricio.murta
Jan 13, 2021, 2:55 PM
Hello @aliabdulla!

In our tests here, if we provided a time to a field, the server would receive the time we filled in. In case you can draw a simplified and runnable test case reproducing the issue, rest assured we'd give you a solid solution for the issue, even if that's a defect with Ext.NET. We're simply unable to give you a specific answer when we cannot reproduce the scenario you are describing.

For what I seen in your test case I couldn't tell where the time is "switching", unfortunately. And it could be doing so not just once, but several times; from browser conversion down to database adjustments.