Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Firefox Javascript Date object issue

  • 29-03-2006 3:22pm
    #1
    Closed Accounts Posts: 169 ✭✭


    I'm having a bit of trouble with a date copying function I've tried implimenting. What it does is takes a string in the format "HH:MM" to represent the time and returns a date object with the same date but a specific time.

    The code responsible for this is
    Date.prototype.copy=function(time){
    	copy = new Date();
    	copy.setDate(this.getDate());
    	copy.setMonth(this.getMonth());
    	copy.setYear(this.getYear());
    	bits=time.split(/:/);
    	copy.setHours(bits[0]);
    	copy.setMinutes(bits[1]);
    	// Debugging info
    	document.getElementById("testDiv").innerHTML+="Turning "+bits[0]+" section of time string "+time+" into an hour value of "+copy.getHours()+"<br/>Created date object with value "+copy+"<br/><br/>";
    	return copy;
    }
    

    But it's producing the following date values
    Turning 00 section of time string 00:00 into an hour value of 0
    Created date object with value Sun Mar 28 0106 00:00:44 GMT+0000 (GMT Standard Time)
    
    Turning 00 section of time string 00:59 into an hour value of 0
    Created date object with value Sun Mar 28 0106 00:59:44 GMT+0000 (GMT Standard Time)
    
    Turning 01 section of time string 01:00 into an hour value of 0
    Created date object with value Sun Mar 28 0106 00:00:44 GMT+0000 (GMT Standard Time)
    
    Turning 01 section of time string 01:59 into an hour value of 0
    Created date object with value Sun Mar 28 0106 00:59:44 GMT+0000 (GMT Standard Time)
    
    Turning 02 section of time string 02:00 into an hour value of 2
    Created date object with value Sun Mar 28 0106 02:00:44 GMT+0100 (GMT Daylight Time)
    
    Turning 02 section of time string 02:59 into an hour value of 2
    Created date object with value Sun Mar 28 0106 02:59:44 GMT+0100 (GMT Daylight Time)
    
    Turning 03 section of time string 03:00 into an hour value of 3
    Created date object with value Sun Mar 28 0106 03:00:44 GMT+0100 (GMT Daylight Time)
    
    Turning 03 section of time string 03:59 into an hour value of 3
    Created date object with value Sun Mar 28 0106 03:59:44 GMT+0100 (GMT Daylight Time)
    

    It's only the value for 01:00 that's off in all 24 hours of the day, and it changes the GMT.

    The code runs perfectly in internet explorer.

    Any help on this front would be appreciated.


Comments

  • Closed Accounts Posts: 169 ✭✭akari no ryu


    This situation has been resolved. I'd love to know what I did wrong, if anyone can tell me, but I'll post the workaround:
    Date.prototype.copy=function(time){
    	copy = new Date();
    	copy.setUTCDate(this.getDate());
    	copy.setUTCMonth(this.getMonth());
    	copy.setUTCFullYear(this.getFullYear());
    	bits=time.split(/:/);
    	copy.setUTCHours(bits[0]);
    	copy.setUTCMinutes(bits[1]);
    	return copy;
    }
    


Advertisement