06-05-2005, 05:16 PM
#121
Code:
String.prototype.stripHTML=function(){
return this.replace(/\&/g,"\&").replace(/\</g,"\<").replace(/\gt/g,"\>")
}
Converts "<b>hi</b>" into "<b>hi</b>"
06-05-2005, 06:28 PM
#122
Originally Posted by
Ultimater
BigMoosie, can you share the changes you made to it?
I t s n o t q u i t e e f f i c i e n t e n o u g h . B u t i l l s h a r e h o w i t s c r o l l s t h e c o l o r s :
#FF0000
#FF00FF
#0000FF
#00FFFF
#00FF00
#FFFF00
B u t i t a l s o h a s a v a r i a b l e t o c o n t r o l h o w l i g h t i t g e t s .
06-07-2005, 03:25 AM
#123
D a t e . p r o t o t y p e . N u m b e r O f D a y s ( ) ; Origional: A1ien51
I was modifying the old version to maintain the old date when I started from scratch. As much as I like the old one for its novel approach, I prefer this as it is 10 times faster.
Code:
Date.prototype.NumberOfDays=function(){
var a=this.getMonth();
if (a==1) {
var b=this.getFullYear();
return (b%4==0 && (b%100!=0 || b%400==0)) ? 29 : 28;
}
return (a==3 || a==5 || a==8 || a==10) ? 30 : 31;
}
Last edited by BigMoosie; 06-08-2005 at 02:58 AM .
06-08-2005, 01:46 AM
#124
Moosie, isn't the rule for leap years:
Code:
if(year%4==0 &&(!year%100==0 || year%400==0)) //then leap year
?
Source: http://www.timeanddate.com/date/leapyear.html
Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.
06-08-2005, 02:15 AM
#125
Good point HaganeNoKokoro!
I knew that they occasionally make exceptions for leapyears but I didnt know there was a rule for it, I thought that chaos didnt allow for those kind of accurate predictions, it seems I was wrong. You can make that adjustment if you want. But for most cases it will not matter as it wont be effective in roughly a hundred years in both directions.
EDIT: made the correction anyway.
Last edited by BigMoosie; 06-08-2005 at 02:38 AM .
06-08-2005, 02:50 AM
#126
B o o l e a n . i s T r u e ( ) ;
Code:
Boolean.prototype.isTrue=function(){return this;}
This may come in handy
Last edited by BigMoosie; 06-08-2005 at 03:01 AM .
06-08-2005, 11:28 AM
#127
Wow, I've needed a function like this for so long...
Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.
06-08-2005, 12:11 PM
#128
Originally Posted by
BigMoosie
B o o l e a n . i s T r u e ( ) ;
Code:
Boolean.prototype.isTrue=function(){return this;}
This may come in handy
I sure hope you are kidding!
06-08-2005, 01:32 PM
#129
Originally Posted by
HaganeNoKokoro
Wow, I've needed a function like this for so long...
I think he's being sarcastic
BigMoosie, as A1ien51 points-out, the function doesn't do anything and it's a wasted function call.
Code:
Boolean.prototype.isTrue=function(){return this;}
A boolean is either true or false, so your function call might look like this:
alert(true.isTrue())//true
alert(false.isTrue())//false
Maybe you meant something like this:
Code:
Boolean.prototype.ifElse=function(){if(this==true)return arguments[0];else return argument[1]}
Last edited by Ultimater; 06-08-2005 at 01:54 PM .
06-08-2005, 04:26 PM
#130
Originally Posted by
A1ien51
I sure hope you are kidding!
Definitely kidding, and I'm pretty sure Moosie is too
Kids, kids... you tried your best, and you failed miserably; the lesson is: never try.
06-08-2005, 11:06 PM
#131
Originally Posted by
Ultimater
Maybe you meant something like this:
Code:
Boolean.prototype.ifElse=function(){if(this==true)return arguments[0];else return argument[1]}
Of course I'm being sarcastic fool! and I meant exactly what I wrote, even yours is a ridiculous waste of a function because it is equivalent to:
Code:
(myBoolean) ? "arg0" : "arg1";
06-09-2005, 12:42 AM
#132
Any Boolean prototype-function is a joke! -- even mine
I'm stumped on why JavaScript even has Boolean prototypes in the first place.
06-09-2005, 08:02 AM
#133
cos that way no-one complains about them not being there.
and anyway booleans are great.
If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
The same applies to HTML and the forums [HTML][/HTML] tags.
06-10-2005, 09:00 AM
#134
here is two more date prototypes UK to US format and DaysBetween, I do not think I posted these.
Code:
<script type="text/javascript">
Date.prototype.DaysBetween = function(){
var intMilDay = 24 * 60 * 60 * 1000;
var intMilDif = arguments[0] - this;
var intDays = Math.floor(intMilDif/intMilDay);
return intDays;
}
String.prototype.UKtoUSDate = function(){
var arrDate = this.split("/");
return new Date(arrDate[1] + "/" + arrDate[0] + "/" + arrDate[2]);
}
var d1 = new Date("06/10/2005");
var d2 = new Date("06/13/2005");
alert(d1.DaysBetween(d2));
var dUK1 = ("10/06/2005").UKtoUSDate();
var dUK2 = ("13/06/2005").UKtoUSDate();
alert(dUK1.DaysBetween(dUK2));
</script>
06-10-2005, 10:39 AM
#135
Business Day Calcs, this method does not involve looping like I have seen people do.
Code:
Date.prototype.DaysBetweenBusiness = function(){
//Does not account for holidays! LOL
//return -1 if start or end date is not a business day
if(!this.IsWeekDay() || !arguments[0].IsWeekDay())return -1
var intMilDay = 24 * 60 * 60 * 1000;
var intMilWeek = intMilDay * 7;
var intSDay = this.getDay();
var intEDay = arguments[0].getDay();
this.setDate(this.getDate() + 7 - intSDay);
arguments[0].setDate(arguments[0].getDate() - intEDay);
var intMilDif = arguments[0] - this;
var intDaysTotal = Math.floor(intMilDif/intMilDay);
var intWeeks = Math.floor(intMilDif/intMilWeek);
return xD = 5 - intSDay + intEDay + intDaysTotal -(intWeeks*2)
}
Date.prototype.IsWeekDay = function(){
return this.getDay() > 0 && this.getDay() < 6
}
var d1 = new Date("06/6/2005");
var d2 = new Date("06/29/2005");
alert(d1.DaysBetweenBusiness(d2));
Eric
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks