LocaleHelper.LocalNow Issue
- William_firefold
- Commander (CMDR)
- Posts: 186
- Joined: Fri Aug 01, 2008 8:38 am
LocaleHelper.LocalNow Issue
DateTime localNow = LocaleHelper.LocalNow;
I am using the LocaleHelper to get the local time and date for a timer that goes on onepagecheckout. I have seen that every once in a while, my timer will display the wrong message, and will do so until I break the control, and then fix it. The only way for my control to display the incorrect message that it does, is if the LocaleHelper feeds it the wrong hour.
Is it possible for this to happen?
I thought Localehelper was an ASP function(I learned ASP from you guys) but when I looked it up I saw it was made by Able, so I have nowhere else to turn.
I am using the LocaleHelper to get the local time and date for a timer that goes on onepagecheckout. I have seen that every once in a while, my timer will display the wrong message, and will do so until I break the control, and then fix it. The only way for my control to display the incorrect message that it does, is if the LocaleHelper feeds it the wrong hour.
Is it possible for this to happen?
I thought Localehelper was an ASP function(I learned ASP from you guys) but when I looked it up I saw it was made by Able, so I have nowhere else to turn.
Re: LocaleHelper.LocalNow Issue
The reason to put the ability to get local date time means LocaleHelper.LocalNow is to ensure that TimeZone Offset will be considered. Make sure that if you are using LocaleHelper.LocalNow for customization then there must be no call to DateTime.Now other wise the time would be different.
- William_firefold
- Commander (CMDR)
- Posts: 186
- Joined: Fri Aug 01, 2008 8:38 am
Re: LocaleHelper.LocalNow Issue
I did use DateTime.Now, but only for the day of the week, which is not related to the time error. Complete source code below,commented at the problem site:
Code: Select all
<%@ Control Language="C#" ClassName="serverDay" %>
<script runat="server">
protected void Page_Init(object sender, EventArgs e)
{
ShippingScript();
}
private void ShippingScript(){
StringBuilder script = new StringBuilder();
DateTime localNow = LocaleHelper.LocalNow;
//complete time
String timeHold=localNow.ToString("hhmmss"),
hourHold=localNow.ToString("hh"),
minHold=localNow.ToString("mm"),
secHold=localNow.ToString("ss"),
tHold=localNow.ToString("tt"), //AM/PM
finalHold="", //string to hold data
weekDay= System.DateTime.Now.DayOfWeek.ToString();
int hourHoldInt=System.Convert.ToInt32(hourHold, 10);
//converts to 24 hour time by adding 12 to PM hours
if(tHold=="PM"){
hourHold=(hourHoldInt+12).ToString();
hourHoldInt=System.Convert.ToInt32(hourHold, 10);
}
///////////////////////////////////////V This is the message that shows up when it shouldn't
if(hourHoldInt>16){
weekDay="All orders placed by 5PM EST Monday-Friday will ship same day.<br />";
///////////////////////////////////////
}else if(hourHoldInt<8){
weekDay="Your order will ship today.<br />";
}else{
if((16-hourHoldInt)!=0)
finalHold+=(16-hourHoldInt)+" Hours ";
finalHold+=(60-System.Convert.ToInt32(minHold, 10))+" Minutes ";
finalHold=" Same day shipping on orders placed in the next "+ finalHold+"<br />";
}
switch (weekDay)
{
case "Monday":
weekDay=finalHold;
break;
case "Tuesday":
weekDay=finalHold;
break;
case "Wednesday":
weekDay=finalHold;
break;
case "Thursday":
weekDay=finalHold;
break;
case "Friday":
weekDay=finalHold;
break;
case "Saturday":
weekDay="Your order will ship on Monday<br />";
break;
case "Sunday":
weekDay="Your order will ship on Monday<br />";
break;
default:
break;
}
ServerDay.Text = weekDay;
}
</script>
<asp:Label ID="ServerDay" runat="server"></asp:Label>
Re: LocaleHelper.LocalNow Issue
I think it may it may return different day in some situations, Instead of
use
Code: Select all
weekDay = DateTime.Now.DayOfWeek.ToString();
Code: Select all
weekDay = LocaleHelper.LocalNow.DayOfWeek.ToString();
- William_firefold
- Commander (CMDR)
- Posts: 186
- Joined: Fri Aug 01, 2008 8:38 am
Re: LocaleHelper.LocalNow Issue
That makes my code better, but how would it be able to reach the message in question (inside the if(hourHoldInt>16) ) at hours that are not greater than 16?
Re: LocaleHelper.LocalNow Issue
One more thing if you are using LocalHelper.Now make sure that you have provided your Time Zone offset properly.
LocaleHelper.Now = current date and time on server computer, expressed as the Coordinated Universal Time + TimeZone offset hours
DateTime.Now = current date and time on server computer, expressed as the local time
DateTime.UtcNow = current date and time on server computer, expressed as the Coordinated Universal Time (UTC).
You can check behavior of all these three by following code
LocaleHelper.Now = current date and time on server computer, expressed as the Coordinated Universal Time + TimeZone offset hours
DateTime.Now = current date and time on server computer, expressed as the local time
DateTime.UtcNow = current date and time on server computer, expressed as the Coordinated Universal Time (UTC).
You can check behavior of all these three by following code
Code: Select all
Response.Write("Local Helper: " + LocaleHelper.LocalNow.ToString() + "<br />");
Response.Write("Local Now: " + DateTime.Now.ToString()+"<br />");
Response.Write("Local UTC: " + DateTime.UtcNow.ToString());
- William_firefold
- Commander (CMDR)
- Posts: 186
- Joined: Fri Aug 01, 2008 8:38 am
Re: LocaleHelper.LocalNow Issue
This helped me figure out that our development server was off by an hour but it still doesn't explain my problem.
Could someone point me to the LocaleHelper code so I can take a look and see what is going on?
I have no idea how to get to it.
Could someone point me to the LocaleHelper code so I can take a look and see what is going on?
I have no idea how to get to it.
Re: LocaleHelper.LocalNow Issue
I don't see what would cause that section of code to be executed inappropriately.
Does the problem always occur during some range of real times?
Does the problem always occur during some range of real times?
Re: LocaleHelper.LocalNow Issue
This what actually LocaleHelper.Now is doing behind the scene.
Just takes the universal time add the time zone offset hours to it and returns the adjusted now.
Code: Select all
DateTime dateTime = DateTime.SpecifyKind(DateTime.UtcNow.AddHours(Token.Instance.Store.TimeZoneOffset), DateTimeKind.Local);
- William_firefold
- Commander (CMDR)
- Posts: 186
- Joined: Fri Aug 01, 2008 8:38 am
Re: LocaleHelper.LocalNow Issue
It hasn't happened enough times to be able to diagnose a specific time or event that causes it. It has happened 3 times so far though. I think my best estimate would be that it happens over night.afm wrote:I don't see what would cause that section of code to be executed inappropriately.
Does the problem always occur during some range of real times?
Could the problem occur if the site re-compiles itself at night or randomly?
- William_firefold
- Commander (CMDR)
- Posts: 186
- Joined: Fri Aug 01, 2008 8:38 am
Re: LocaleHelper.LocalNow Issue
It happened again, even more randomly than last time.
The program hit the >16:00 section at 12:51 PM Thu Jan 8 2009
Nobody was changing anything, and anyone who could wasn't even here.
The system automatically did something which caused it to go down for about 10 minutes before it came back on its own.
The program hit the >16:00 section at 12:51 PM Thu Jan 8 2009
Nobody was changing anything, and anyone who could wasn't even here.
The system automatically did something which caused it to go down for about 10 minutes before it came back on its own.