LocaleHelper.LocalNow Issue

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
William_firefold
Commander (CMDR)
Commander (CMDR)
Posts: 186
Joined: Fri Aug 01, 2008 8:38 am

LocaleHelper.LocalNow Issue

Post by William_firefold » Thu Dec 18, 2008 9:09 am

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.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: LocaleHelper.LocalNow Issue

Post by mazhar » Thu Dec 18, 2008 9:35 am

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.

User avatar
William_firefold
Commander (CMDR)
Commander (CMDR)
Posts: 186
Joined: Fri Aug 01, 2008 8:38 am

Re: LocaleHelper.LocalNow Issue

Post by William_firefold » Thu Dec 18, 2008 9:48 am

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>

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: LocaleHelper.LocalNow Issue

Post by mazhar » Thu Dec 18, 2008 10:19 am

I think it may it may return different day in some situations, Instead of

Code: Select all

weekDay = DateTime.Now.DayOfWeek.ToString();
use

Code: Select all

weekDay = LocaleHelper.LocalNow.DayOfWeek.ToString();

User avatar
William_firefold
Commander (CMDR)
Commander (CMDR)
Posts: 186
Joined: Fri Aug 01, 2008 8:38 am

Re: LocaleHelper.LocalNow Issue

Post by William_firefold » Thu Dec 18, 2008 10:26 am

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?

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: LocaleHelper.LocalNow Issue

Post by mazhar » Thu Dec 18, 2008 10:37 am

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

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());

User avatar
William_firefold
Commander (CMDR)
Commander (CMDR)
Posts: 186
Joined: Fri Aug 01, 2008 8:38 am

Re: LocaleHelper.LocalNow Issue

Post by William_firefold » Thu Dec 18, 2008 3:12 pm

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.

afm
Captain (CAPT)
Captain (CAPT)
Posts: 339
Joined: Thu Nov 03, 2005 11:52 pm
Location: Portland, OR
Contact:

Re: LocaleHelper.LocalNow Issue

Post by afm » Thu Dec 18, 2008 4:36 pm

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?
Andy Miller
Structured Solutions

Shipper 3 - High Velocity Shipment Processing

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: LocaleHelper.LocalNow Issue

Post by mazhar » Fri Dec 19, 2008 6:50 am

This what actually LocaleHelper.Now is doing behind the scene.

Code: Select all

DateTime dateTime = DateTime.SpecifyKind(DateTime.UtcNow.AddHours(Token.Instance.Store.TimeZoneOffset), DateTimeKind.Local);
Just takes the universal time add the time zone offset hours to it and returns the adjusted now.

User avatar
William_firefold
Commander (CMDR)
Commander (CMDR)
Posts: 186
Joined: Fri Aug 01, 2008 8:38 am

Re: LocaleHelper.LocalNow Issue

Post by William_firefold » Mon Dec 22, 2008 7:51 am

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?
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.

Could the problem occur if the site re-compiles itself at night or randomly?

User avatar
William_firefold
Commander (CMDR)
Commander (CMDR)
Posts: 186
Joined: Fri Aug 01, 2008 8:38 am

Re: LocaleHelper.LocalNow Issue

Post by William_firefold » Thu Jan 08, 2009 1:36 pm

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.

Post Reply