PS: Using a little bit of math the timeAsText can be further reduced
Main Topics
Browse All TopicsHi,
Im looking to cut down this javascript file a lot but im not quite sure how to go about it? there are a lot of repeating features in the code so im assuming its possible..... any ideas on how i could do this? as much help as possible would be appreciated as im new to the javascript game :)
var monthAbbreviations = new Array("January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ", "September ", "October ", "November ", "December ");
var daysOfTheWeek = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
//TIME In milliseconds:
//MINUTES
ONEMINUTEAGO = -60000;
TWOMINUTESAGO = -120000;
THREEMINUTESAGO = -180000;
FOURMINUTESAGO = -240000;
FIVEMINUTESAGO = -300000;
SIXMINUTESAGO = -360000;
SEVENMINUTESAGO = -420000;
EIGHTMINUTESAGO = -480000;
NINEMINUTESAGO = -540000;
TENMINUTESAGO = -600000;
ELEVENMINUTESAGO = -660000;
TWELVEMINUTESAGO = -720000;
THIRTEENMINUTESAGO = -780000;
FOURTEENMINUTESAGO = -840000;
FIFTEENMINUTESAGO = -900000;
SIXTEENMINUTESAGO = -960000;
SEVENTEENMINUTESAGO = -1020000;
EIGHTEENMINUTESAGO = -1080000;
NINETEENMINUTESAGO = -1140000;
TWENTYMINUTESAGO = -1200000;
TWENTYONEMINUTESAGO = -1260000;
TWENTYTWOMINUTESAGO = -1320000;
TWENTYTHREEMINUTESAGO = -1380000;
TWENTYFOURMINUTESAGO = -1440000;
TWENTYFIVEMINUTESAGO = -1500000;
TWENTYSIXMINUTESAGO = -1560000;
TWENTYSEVENMINUTESAGO = -1620000;
TWENTYEIGHTMINUTESAGO = -1680000;
TWENTYNINEMINUTESAGO = -1740000;
THIRTYMINUTESAGO = -1800000;
THIRTYONEMINUTESAGO = -1860000;
THIRTYTWOMINUTESAGO = -1920000;
THIRTYTHREEMINUTESAGO = -1980000;
THIRTYFOURMINUTESAGO = -2040000;
THIRTYFIVEMINUTESAGO = -2100000;
THIRTYSIXMINUTESAGO = -2160000;
THIRTYSEVENMINUTESAGO = -2220000;
THIRTYEIGHTMINUTESAGO = -2280000;
THIRTYNINEMINUTESAGO = -2340000;
FOURTYMINUTESAGO = -2400000;
FOURTYONEMINUTESAGO = -2460000;
FOURTYTWOMINUTESAGO = -2520000;
FOURTYTHREEMINUTESAGO = -2580000;
FOURTYFOURMINUTESAGO = -2640000;
FOURTYFIVEMINUTESAGO = -2700000;
FOURTYSIXMINUTESAGO = -2760000;
FOURTYSEVENMINUTESAGO = -2820000;
FOURTYEIGHTMINUTESAGO = -2880000;
FOURTYNINEMINUTESAGO = -2940000;
FIFTYMINUTESAGO = -3000000;
FIFTYONEMINUTESAGO = -3060000;
FIFTYTWOMINUTESAGO = -3120000;
FIFTYTHREEMINUTESAGO = -3180000;
FIFTYFOURMINUTESAGO = -3240000;
FIFTYFIVEMINUTESAGO = -3300000;
FIFTYSIXMINUTESAGO = -3360000;
FIFTYSEVENMINUTESAGO = -3420000;
FIFTYEIGHTMINUTESAGO = -3480000;
FIFTYNINEMINUTESAGO = -3540000;
SIXTYMINUTESAGO = -3600000;
//HOURS
ONEHOURAGO = -3599999;
TWOHOURSAGO = -7200000;
THREEHOURSAGO = -10800000;
FOURHOURSAGO = -14400000;
FIVEHOURSAGO = -18000000;
SIXHOURSAGO = -21600000;
SEVENHOURSAGO = -25200000;
EIGHTHOURSAGO = -28800000;
NINEHOURSAGO = -32400000;
TENHOURSAGO = -36000000;
ELEVENHOURSAGO = -39600000;
TWELVEHOURSAGO = -43200000;
THIRTEENHOURSAGO = -46800000;
FOURTEENHOURSAGO = -46860000;
FIFTEENHOURSAGO = -46920000;
SIXTEENHOURSAGO = -46980000;
SEVENTEENHOURSAGO = -47040000;
EIGHTEENHOURSAGO = -47100000;
NINETEENHOURSAGO = -47160000;
TWENTYHOURSAGO = -47160000;
TWENTYONEHOURSAGO = -47220000;
TWENTYTWOHOURSAGO = -47280000;
TWENTYTHREEHOURSAGO = -47340000;
TWENTYFOURHOURSAGO = -47400000;
//DAYS
ONEDAYAGO = -86400000;
TWODAYSAGO = -172800000;
THREEDAYSAGO = -259200000;
FOURDAYSAGO = -345600000;
function dateReference(dateString) {
var relative = relativeDate(dateString);
var explicit = explicitDate(dateString, true);
if (relative != explicit) {
document.write("<acronym title=\"" + explicit + "\">" + relative + "</acronym>");
} else {
document.write(explicit);
}
}
function relativeDate(dateString) {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var reference = new Date(dateString);
if (isNaN(reference)) return dateString;
// Calculate time offset between the two dates
var offset = reference.getTime() - now.getTime();
// TIME AGO
//MINUTES
if ((offset > TWOMINUTESAGO) && (offset <= ONEMINUTEAGO)) return "1 Minute Ago";
if ((offset > THREEMINUTESAGO) && (offset <= TWOMINUTESAGO)) return "2 MinuteS Ago";
if ((offset > FOURMINUTESAGO) && (offset <= THREEMINUTESAGO)) return "3 Minute Ago";
if ((offset > FIVEMINUTESAGO) && (offset <= FOURMINUTESAGO)) return "4 Minutes Ago";
if ((offset > SIXMINUTESAGO) && (offset <= FIVEMINUTESAGO)) return "5 Minutes Ago";
if ((offset > SEVENMINUTESAGO) && (offset <= SIXMINUTESAGO)) return "6 Minutes Ago";
if ((offset > EIGHTMINUTESAGO) && (offset <= SEVENMINUTESAGO)) return "7 Minutes Ago";
if ((offset > NINEMINUTESAGO) && (offset <= EIGHTMINUTESAGO)) return "8 Minutes Ago";
if ((offset > TENMINUTESAGO) && (offset <= NINEMINUTESAGO)) return "9 Minutes Ago";
if ((offset > ELEVENMINUTESAGO) && (offset <= TENMINUTESAGO)) return "10 Minutes Ago";
if ((offset > TWELVEMINUTESAGO) && (offset <= ELEVENMINUTESAGO)) return "11 Minutes Ago";
if ((offset > THIRTEENMINUTESAGO) && (offset <= TWELVEMINUTESAGO)) return "12 Minutes Ago";
if ((offset > FOURTEENMINUTESAGO) && (offset <= THIRTEENMINUTESAGO)) return "13 Minutes Ago";
if ((offset > FIFTEENMINUTESAGO) && (offset <= FOURTEENMINUTESAGO)) return "14 Minutes Ago";
if ((offset > SIXTEENMINUTESAGO) && (offset <= FIFTEENMINUTESAGO)) return "15 Minutes Ago";
if ((offset > SEVENTEENMINUTESAGO) && (offset <= SIXTEENMINUTESAGO)) return "16 Minutes Ago";
if ((offset > EIGHTEENMINUTESAGO) && (offset <= SEVENTEENMINUTESAGO)) return "17 Minutes Ago";
if ((offset > NINETEENMINUTESAGO) && (offset <= EIGHTEENMINUTESAGO)) return "18 Minutes Ago";
if ((offset > TWENTYMINUTESAGO) && (offset <= NINETEENMINUTESAGO)) return "19 Minutes Ago";
if ((offset > TWENTYONEMINUTESAGO) && (offset <= TWENTYMINUTESAGO)) return "20 Minutes Ago";
if ((offset > TWENTYTWOMINUTESAGO) && (offset <= TWENTYONEMINUTESAGO)) return "21 Minutes Ago";
if ((offset > TWENTYTHREEMINUTESAGO) && (offset <= TWENTYTWOMINUTESAGO)) return "22 Minutes Ago";
if ((offset > TWENTYFOURMINUTESAGO) && (offset <= TWENTYTHREEMINUTESAGO)) return "23 Minutes Ago";
if ((offset > TWENTYFIVEMINUTESAGO) && (offset <= TWENTYFOURMINUTESAGO)) return "24 Minutes Ago";
if ((offset > TWENTYSIXMINUTESAGO) && (offset <= TWENTYFIVEMINUTESAGO)) return "25 Minutes Ago";
if ((offset > TWENTYSEVENMINUTESAGO) && (offset <= TWENTYSIXMINUTESAGO)) return "26 Minutes Ago";
if ((offset > TWENTYEIGHTMINUTESAGO) && (offset <= TWENTYSEVENMINUTESAGO)) return "27 Minutes Ago";
if ((offset > TWENTYNINEMINUTESAGO) && (offset <= TWENTYEIGHTMINUTESAGO)) return "28 Minutes Ago";
if ((offset > THIRTYMINUTESAGO) && (offset <= TWENTYNINEMINUTESAGO)) return "29 Minutes Ago";
if ((offset > THIRTYONEMINUTESAGO) && (offset <= THIRTYMINUTESAGO)) return "30 Minutes Ago";
if ((offset > THIRTYTWOMINUTESAGO) && (offset <= THIRTYONEMINUTESAGO)) return '31 Minutes Ago' ;
if ((offset > THIRTYTHREEMINUTESAGO) && (offset <= THIRTYTWOMINUTESAGO)) return '32 Minutes Ago' ;
if ((offset > THIRTYFOURMINUTESAGO) && (offset <= THIRTYTHREEMINUTESAGO)) return '33 Minutes Ago' ;
if ((offset > THIRTYFIVEMINUTESAGO) && (offset <= THIRTYFOURMINUTESAGO)) return '34 Minutes Ago' ;
if ((offset > THIRTYSIXMINUTESAGO) && (offset <= THIRTYFIVEMINUTESAGO)) return '35 Minutes Ago' ;
if ((offset > THIRTYSEVENMINUTESAGO) && (offset <= THIRTYSIXMINUTESAGO)) return '36 Minutes Ago ';
if ((offset > THIRTYEIGHTMINUTESAGO) && (offset <= THIRTYSEVENMINUTESAGO)) return '37 Minutes Ago ';
if ((offset > THIRTYNINEMINUTESAGO) && (offset <= THIRTYEIGHTMINUTESAGO)) return '38 Minutes Ago ';
if ((offset > FOURTYMINUTESAGO) && (offset <= THIRTYNINEMINUTESAGO)) return '39 Minutes Ago ';
if ((offset > FOURTYONEMINUTESAGO) && (offset <= FOURTYMINUTESAGO)) return '40 Minutes Ago ';
if ((offset > FOURTYTWOMINUTESAGO) && (offset <= FOURTYONEMINUTESAGO)) return '41 Minutes Ago ';
if ((offset > FOURTYTHREEMINUTESAGO) && (offset <= FOURTYTWOMINUTESAGO)) return '42 Minutes Ago' ;
if ((offset > FOURTYFOURMINUTESAGO) && (offset <= FOURTYTHREEMINUTESAGO)) return '43 Minutes Ago';
if ((offset > FOURTYFIVEMINUTESAGO) && (offset <= FOURTYFOURMINUTESAGO)) return '44 Minutes Ago ';
if ((offset > FOURTYSIXMINUTESAGO) && (offset <= FOURTYFIVEMINUTESAGO)) return '45 Minutes Ago' ;
if ((offset > FOURTYSEVENMINUTESAGO) && (offset <= FOURTYSIXMINUTESAGO)) return '46 Minutes Ago' ;
if ((offset > FOURTYEIGHTMINUTESAGO) && (offset <= FOURTYSEVENMINUTESAGO)) return '47 Minutes Ago ';
if ((offset > FOURTYNINEMINUTESAGO) && (offset <= FOURTYEIGHTMINUTESAGO)) return '48 Minutes Ago ';
if ((offset > FIFTYMINUTESAGO) && (offset <= FOURTYNINEMINUTESAGO)) return '49 Minutes Ago';
if ((offset > FIFTYONEMINUTESAGO) && (offset <= FIFTYMINUTESAGO)) return '50 Minutes Ago' ;
if ((offset > FIFTYTWOMINUTESAGO) && (offset <= FIFTYONEMINUTESAGO)) return '51 Minutes Ago ' ;
if ((offset > FIFTYTHREEMINUTESAGO) && (offset <= FIFTYTWOMINUTESAGO)) return '52 Minutes Ago' ;
if ((offset > FIFTYFOURMINUTESAGO) && (offset <= FIFTYTHREEMINUTESAGO)) return '53 Minutes Ago ';
if ((offset > FIFTYFIVEMINUTESAGO) && (offset <= FIFTYFOURMINUTESAGO)) return '54 Minutes Ago ';
if ((offset > FIFTYSIXMINUTESAGO) && (offset <= FIFTYFIVEMINUTESAGO)) return '55 Minutes Ago ' ;
if ((offset > FIFTYSEVENMINUTESAGO) && (offset <= FIFTYSIXMINUTESAGO)) return '56 Minutes Ago ';
if ((offset > FIFTYEIGHTMINUTESAGO) && (offset <= FIFTYSEVENMINUTESAGO)) return '57 Minutes Ago';
if ((offset > FIFTYNINEMINUTESAGO) && (offset <= FIFTYEIGHTMINUTESAGO)) return '58 Minutes Ago ';
if ((offset > SIXTYMINUTESAGO) && (offset <= FIFTYNINEMINUTESAGO)) return '59 Minutes Ago';
//HOURS
if ((offset > TWOHOURSAGO) && (offset <= ONEHOURAGO))
{
var minsOffset = Math.round(Math.abs(offset
return ('One hour and '+ minsOffset + ' Minutes ago.');
}
if ((offset > THREEHOURSAGO) && (offset <= TWOHOURSAGO))
{
var minsOffset = Math.round(Math.abs(offset
return ('Two hours and '+ minsOffset + ' Minutes ago.');
}
if ((offset > FOURHOURSAGO) && (offset <= THREEHOURSAGO))
{
var minsOffset = Math.round(Math.abs(offset
return ('Three hours and '+ minsOffset + ' Minutes ago.');
}
if ((offset > FIVEHOURSAGO) && (offset <= FOURHOURSAGO))
{
var minsOffset = Math.round(Math.abs(offset
return ('Four hours and '+ minsOffset + ' Minutes ago.');
}
if ((offset > SIXHOURSAGO) && (offset <= FIVEHOURSAGO))
{
var minsOffset = Math.round(Math.abs(offset
return ('Five hours and '+ minsOffset + ' Minutes ago.');
}
if ((offset > SEVENHOURSAGO) && (offset <= SIXHOURSAGO))
{
var minsOffset = Math.round(Math.abs(offset
return ('Six hours and '+ minsOffset + ' Minutes ago.');
}
if ((offset > EIGHTHOURSAGO) && (offset <= SEVENHOURSAGO))
{
var minsOffset = Math.round(Math.abs(offset
return ('Seven hours and '+ minsOffset + ' Minutes ago.');
}
if ((offset > NINEHOURSAGO) && (offset <= EIGHTHOURSAGO))
{
var minsOffset = Math.round(Math.abs(offset
return ('Eight hours and '+ minsOffset + ' Minutes ago.');
}
if ((offset > TENHOURSAGO) && (offset <= NINEHOURSAGO))
{
var minsOffset = Math.round(Math.abs(offset
return ('Nine hours and '+ minsOffset + ' Minutes ago.');
}
if ((offset > ELEVENHOURSAGO) && (offset <= TENHOURSAGO))
{
var minsOffset = Math.round(Math.abs(offset
return ('Ten hours and '+ minsOffset + ' Minutes ago.');
}
if ((offset > TWELVEHOURSAGO) && (offset <= ELEVENHOURSAGO))
{
var minsOffset = Math.round(Math.abs(offset
return ('Eleven hours and '+ minsOffset + ' Minutes ago.');
}
if ((offset > THIRTEENHOURSAGO) && (offset <= TWELVEHOURSAGO)) return 'today at: '+reference;
if ((offset > FOURTEENHOURSAGO) && (offset <= THIRTEENHOURSAGO)) return 'today at:' + reference ;
if ((offset > FIFTEENHOURSAGO) && (offset <= FOURTEENHOURSAGO)) return 'today at:' + reference ;
if ((offset > SIXTEENHOURSAGO) && (offset <= FIFTEENHOURSAGO)) return 'today at:' + reference ;
if ((offset > SEVENTEENHOURSAGO) && (offset <= SIXTEENHOURSAGO)) return 'today at:' + reference ;
if ((offset > EIGHTEENHOURSAGO) && (offset <= SEVENTEENHOURSAGO)) return 'today at:' + reference ;
if ((offset > NINETEENHOURSAGO) && (offset <= EIGHTEENHOURSAGO)) return 'today at:' + reference ;
if ((offset > TWENTYHOURSAGO) && (offset <= NINETEENHOURSAGO)) return 'today at:' + reference ;
if ((offset > TWENTYONEHOURSAGO) && (offset <= TWENTYHOURSAGO)) return 'today at:' + reference ;
if ((offset > TWENTYTWOHOURSAGO) && (offset <= TWENTYONEHOURSAGO)) return 'today at:' + reference ;
if ((offset > TWENTYTHREEHOURSAGO) && (offset <= TWENTYTWOHOURSAGO)) return 'today at:' + reference ;
if ((offset > TWENTYFOURHOURSAGO) && (offset <= TWENTYTHREEHOURSAGO)) return 'today at:' + reference ;
//Days
if ((offset > TWODAYSAGO) && (offset <= ONEDAYAGO)) return "1 Day Ago";
if ((offset > THREEDAYSAGO) && (offset <= TWODAYSAGO)) return "2 Days Ago";
if ((offset > FOURDAYSAGO) && (offset <=THREEDAYSAGO)) return "3 Days Ago";
// None of the above
return explicitDate(dateString, false);
}
function explicitDate(dateString, includeYearRegardless) {
var now = new Date();
var reference = new Date(dateString);
if (isNaN(reference)) return dateString;
var date = reference.getDate();
var month = monthAbbreviations[referen
var hours = reference.getHours();
var minutes = reference.getMinutes();
var seconds = reference.getSeconds();
var year = reference.getFullYear();
// Only show the year if out of current year!!!!
/* if ((reference.getFullYear() != now.getFullYear()) || includeYearRegardless) {
var year = ", " + reference.getFullYear();
} else {
var year = "";
}*/
return(month + date + ', ' + year + ' at ' + hours +':'+ minutes);
}
thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I built a JS Object called js_SuperDate which is totally compatible with the standard Date() object, but with extended features, such as complete date-to-string manipulation, plus an offset date function which allows you to do the stuff you were doing, and a very rudimentary date command parser (it's crap, but works). I have been meaning to add DatePart and DateAdd functions, but haven't got round to it...
It is long, but just put it in it's own js file and include it...
Anyway, here you go:
/*
* Super date function!!!
*/
function js_SuperDate()
{
if (arguments.length > 0)
this.dt = new Date(arguments[0] + '');
else
this.dt = new Date();
}
// mirror the same interface as the Date() object:
js_SuperDate.prototype.Mon
js_SuperDate.prototype.Day
js_SuperDate.prototype.AMP
js_SuperDate.prototype.get
{
return this.dt.getDate();
}
js_SuperDate.prototype.get
{
return this.dt.getDay();
}
js_SuperDate.prototype.get
{
return this.dt.getFullYear();
}
js_SuperDate.prototype.get
{
return this.dt.getHours();
}
js_SuperDate.prototype.get
{
return this.dt.getMilliseconds();
}
js_SuperDate.prototype.get
{
return this.dt.getMinutes();
}
js_SuperDate.prototype.get
{
return this.dt.getMonth();
}
js_SuperDate.prototype.get
{
return this.dt.getSeconds();
}
js_SuperDate.prototype.get
{
return this.dt.getTime();
}
js_SuperDate.prototype.get
{
return this.dt.getTimezoneOffset(
}
js_SuperDate.prototype.get
{
return this.dt.getUTCDate();
}
js_SuperDate.prototype.get
{
return this.dt.getUTCDay();
}
js_SuperDate.prototype.get
{
return this.dt.getUTCFullYear();
}
js_SuperDate.prototype.get
{
return this.dt.getUTCHours();
}
js_SuperDate.prototype.get
{
return this.dt.getUTCMinutes();
}
js_SuperDate.prototype.get
{
return this.dt.getUTCMonth();
}
js_SuperDate.prototype.get
{
return this.dt.getUTCSeconds();
}
js_SuperDate.prototype.get
{
return this.dt.getYear();
}
js_SuperDate.prototype.par
{
return this.dt.parse(_in);
}
js_SuperDate.prototype.set
{
return this.dt.setDate(_in);
}
js_SuperDate.prototype.set
{
return this.dt.setFullYear(_in);
}
js_SuperDate.prototype.set
{
return this.dt.setHours(_in);
}
js_SuperDate.prototype.set
{
return this.dt.setMilliseconds(_i
}
js_SuperDate.prototype.set
{
return this.dt.setMinutes(_in);
}
js_SuperDate.prototype.set
{
return this.dt.setMonth(_in);
}
js_SuperDate.prototype.set
{
return this.dt.setSeconds(_in);
}
js_SuperDate.prototype.set
{
return this.dt.setTime(_in);
}
js_SuperDate.prototype.set
{
return this.dt.setUTCDate(_in);
}
js_SuperDate.prototype.set
{
return this.dt.setUTCFullYear(_in
}
js_SuperDate.prototype.set
{
return this.dt.setUTCHours(_in);
}
js_SuperDate.prototype.set
{
return this.dt.setUTCMilliseconds
}
js_SuperDate.prototype.set
{
return this.dt.setUTCMinutes(_in)
}
js_SuperDate.prototype.set
{
return this.dt.setUTCMonth(_in);
}
js_SuperDate.prototype.set
{
return this.dt.setUTCSeconds(_in)
}
js_SuperDate.prototype.set
{
return this.dt.setYear(_in);
}
js_SuperDate.prototype.toG
{
return this.dt.toGMTString();
}
js_SuperDate.prototype.toL
{
return this.dt.toLocaleString();
}
js_SuperDate.prototype.toS
{
return this.dt.toString();
}
js_SuperDate.prototype.toU
{
return this.dt.toUTCString();
}
js_SuperDate.prototype.UTC
{
return this.dt.UTC();
}
js_SuperDate.prototype.val
{
return this.dt.valueOf();
}
// GMT-named versions of UTC
js_SuperDate.prototype.get
{
return this.getUTCDate();
}
js_SuperDate.prototype.get
{
return this.getUTCDay();
}
js_SuperDate.prototype.get
{
return this.getUTCFullYear();
}
js_SuperDate.prototype.get
{
return this.getUTCHours();
}
js_SuperDate.prototype.get
{
return this.getUTCMinutes();
}
js_SuperDate.prototype.get
{
return this.getUTCMonth();
}
js_SuperDate.prototype.get
{
return this.getUTCSeconds();
}
js_SuperDate.prototype.set
{
return this.setUTCDate(_in);
}
js_SuperDate.prototype.set
{
return this.setUTCFullYear(_in);
}
js_SuperDate.prototype.set
{
return this.setUTCHours(_in);
}
js_SuperDate.prototype.set
{
return this.setUTCMilliseconds(_i
}
js_SuperDate.prototype.set
{
return this.setUTCMinutes(_in);
}
js_SuperDate.prototype.set
{
return this.setUTCMonth(_in);
}
js_SuperDate.prototype.set
{
return this.setUTCSeconds(_in);
}
js_SuperDate.prototype.GMT
{
return this.UTC();
}
// Strings
js_SuperDate.prototype.get
{
var ret = this.getDate()+'';
return ret;
}
js_SuperDate.prototype.get
{
var ret = this.getDate()+'';
if (ret.length < 2)
ret = '0' + ret;
return ret;
}
js_SuperDate.prototype.get
{
var ret = (this.getMonth()+1)+'';
return ret;
}
js_SuperDate.prototype.get
{
var ret = (this.getMonth()+1)+'';
if (ret.length < 2)
ret = '0' + ret;
return ret;
}
js_SuperDate.prototype.get
{
return this.Months[this.getMonth(
}
js_SuperDate.prototype.get
{
return this.Months[this.getMonth(
}
js_SuperDate.prototype.get
{
return this.getStrMMM();
}
js_SuperDate.prototype.get
{
return this.getStrMMMM();
}
js_SuperDate.prototype.get
{
return this.Days[this.getDay()].s
}
js_SuperDate.prototype.get
{
return this.Days[this.getDay()].s
}
js_SuperDate.prototype.get
{
return this.Days[this.getDay()].s
}
js_SuperDate.prototype.get
{
return this.Days[this.getDay()]+'
}
js_SuperDate.prototype.get
{
return (this.getFullYear()+'').su
}
js_SuperDate.prototype.get
{
return (this.getFullYear()+'').su
}
js_SuperDate.prototype.get
{
return this.getFullYear()+'';
}
js_SuperDate.prototype.get
{
return this.getStrY();
}
js_SuperDate.prototype.get
{
return this.getStrYY();
}
js_SuperDate.prototype.get
{
return this.getStrYYYY();
}
js_SuperDate.prototype.get
{
var ret = this.getHours()+'';
return ret;
}
js_SuperDate.prototype.get
{
var ret = this.getHours()+'';
if (ret.length < 2)
ret = '0' + ret;
return ret;
}
js_SuperDate.prototype.get
{
var ret = '';
if (this.getHours() < 13)
ret = this.getHours()+'';
else
ret = (this.getHours() - 12) +'';
return ret;
}
js_SuperDate.prototype.get
{
var ret = '';;
if (this.getHours() < 13)
ret = this.getHours()+'';
else
ret = (this.getHours() - 12)+'';
if (ret.length < 2)
ret = '0' + ret;
return ret;
}
js_SuperDate.prototype.get
{
var ret = this.getMinutes()+'';
return ret;
}
js_SuperDate.prototype.get
{
var ret = this.getMinutes()+'';
if (ret.length < 2)
ret = '0' + ret;
return ret;
}
js_SuperDate.prototype.get
{
var ret = this.getSeconds()+'';
return ret;
}
js_SuperDate.prototype.get
{
var ret = this.getSeconds()+'';
if (ret.length < 2)
ret = '0' + ret;
return ret;
}
js_SuperDate.prototype.get
{
return this.getStrS();
}
js_SuperDate.prototype.get
{
return this.getStrSS();
}
js_SuperDate.prototype.get
{
var ret = this.getMilliseconds()+'';
if (ret.length < 3)
ret = '0' + ret;
else if (ret.length < 2)
ret = '00' + ret;
return ret;
}
js_SuperDate.prototype.get
{
return this.getMilliseconds()+'';
}
js_SuperDate.prototype.get
{
var ret = '';;
if (this.getHours() < 13)
ret = this.AMPM[0].toUpperCase()
else
ret = this.AMPM[1].toUpperCase()
return ret;
}
js_SuperDate.prototype.get
{
var ret = '';;
if (this.getHours() < 13)
ret = this.AMPM[0].toLowerCase()
else
ret = this.AMPM[1].toLowerCase()
return ret;
}
// Date Command Parser
js_SuperDate.prototype.get
{
var delim = ' ';
if (arguments.length > 1)
delim = arguments[1];
var illegalChars = [' ','!','"','£','$','%','^',
var cmd = _cmd + '';
var cmd_clean = '';
for (i = 0; i < cmd.length; ++i)
{
var charOK = true;
var tChar = cmd.charAt(i);
for (j = 0; j < illegalChars.length; ++j)
{
if (tChar == illegalChars[j] && tChar != delim)
charOK = false;
}
if (charOK)
cmd_clean += tChar;
}
var cmds = cmd_clean.split(delim);
var legalEntities = ['d','dd','D','DD','DDD','
var ret = '';
for (i = 0; i < cmds.length; ++i)
{
var cmdOK = false
for (j = 0; j < legalEntities.length; j++)
{
if (cmds[i] == legalEntities[j])
cmdOK = true;
}
if (cmdOK)
{
if (i > 0)
ret += delim;
ret += eval('this.getStr' + cmds[i] + '()');
}
}
return ret;
}
// DB-usable date string
js_SuperDate.prototype.get
{
// dd-MMM-yyyy
return this.getStrdd() + '-' + this.getStrMMM() + '-' + this.getFullYear();
}
js_SuperDate.prototype.get
{
// dd-MMM-yyyy
return this.getStrd() + ' ' + this.getStrMMM() + ' ' + this.getFullYear();
}
// RFC-1123 dateformat
js_SuperDate.prototype.get
{
// dd-MMM-yyyy
return this.getStrMMM() + ' ' + this.getStrdd() + ', ' + this.getFullYear() + ' ' + this.getStrHH() + ':' + this.getStrmm() + ':' + this.getStrSS();
}
var now = new js_SuperDate();
function js_OffsetDate(_period,_tim
{
var td = new js_SuperDate();
var n = td.getTime();
switch(_timeunit)
{
case 'Y' :
// year
td.setTime(n + (_period * 31557600000));
break;
case 'M' :
// month
td.setTime(n + (_period * 2629800000));
break;
case 'd' :
// day
td.setTime(n + (_period * 86400000));
break;
case 'D' :
// day
td.setTime(n + (_period * 86400000));
break;
case 'H' :
// hour
td.setTime(n + (_period * 3600000));
break;
case 'm' :
// minute
td.setTime(n + (_period * 60000));
break;
case 'S' :
// seconds
td.setTime(n + (_period * 1000));
break;
case '0' :
// milliseconds
td.setTime(n + _period);
break;
}
return td.toGMTString();
}
Business Accounts
Answer for Membership
by: mplungjanPosted on 2006-08-17 at 04:44:49ID: 17333178
It should look something like this - not fully tested so please look at the math - there is an issue around 12 hours ril,May,Ju ne,July,Au gust,Septe mber,Octob er,Novembe r,December ".split(', '); nesday,Thu rsday,Frid ay,Saturda y".split(' ,'); IVE,SIX,SE VEN,EIGHT, NINE,TEN," + URTEEN,FIF TEEN,SIXTE EN,SEVENTE EN,EIGHTEE N,NINETEEN ,TWENTY,"+ YTHREE,TWE NTYFOUR,TW ENTYFIVE,T WENTYSIX,T WENTYSEVEN ,TWENTYEIG HT,TWENTYN INE,THIRTY ,"+ YTHREE,THI RTYFOUR,TH IRTYFIVE,T HIRTYSIX,T HIRTYSEVEN ,THIRTYEIG HT,THIRTYN INE,FOURTY ,"+ YTHREE,FOU RTYFOUR,FO URTYFIVE,F OURTYSIX,F OURTYSEVEN ,FOURTYEIG HT,FOURTYN INE,"+ IFTYTHREE, FIFTYFOUR, FIFTYFIVE, FIFTYSIX,F IFTYSEVEN, FIFTYEIGHT ,FIFTYNINE ,SIXTY"
m title=\"" + explicit + "\">" + relative + "</acronym>"); () - now.getTime()); ur)); ; ;
secs '+offsetInSeconds+'\nmin '+offsetInMinutes+'\nhours '+offsetInHours+'\ndays '+offsetInDays) ] +" Minute"+plurMin+" Ago"; rs+':'+tim eAsText[of fsetInHour s])
' hour'+plurHour; ] + ' Minute'+plurMin; ' ' + offsetInMinutes +':'+timeAsText[offsetInMi nutes])
Day'+plurDay+' Ago';
ce.getMont h()];
<script>
var monthAbbreviations = "January,February,March,Ap
var daysOfTheWeek = "Sunday,Monday,Tuesday,Wed
var timeString = "ZERO,ONE,TWO,THREE,FOUR,F
"ELEVEN,TWELVE,THIRTEEN,FO
"TWENTYONE,TWENTYTWO,TWENT
"THIRTYONE,THIRTYTWO,THIRT
"FOURTYONE,FOURTYTWO,FOURT
"FIFTY,FIFTYONE,FIFTYTWO,F
var timeAsText = timeString.split(',');
function dateReference(dateString) {
var relative = relativeDate(dateString);
alert(relative)
var explicit = explicitDate(dateString, true);
alert(explicit)
if (relative != explicit) {
document.write("<acrony
} else {
document.write(explicit);
}
}
var aSecond = 1000;
var aMinute = 60*aSecond;
var anHour = 60*aMinute;
var aDay = 24*anHour;
function relativeDate(dateString) {
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var reference = new Date(dateString);
if (isNaN(reference)) return dateString;
// Calculate time offset between the two dates
var offset = Math.abs(reference.getTime
var offsetInDays = Math.round(offset/(24*anHo
var showDays = offsetInDays > 0;
offset -= offsetInDays*aDay
var offsetInHours = Math.round(offset/anHour);
var showHours = !showDays && (offsetInHours > 0);
offset -= offsetInHours*anHour;
alert(offset)
var offsetInMinutes = Math.round(offset/aMinute)
var showMinutes = !showDays && !showHours && (offsetInMinutes >0)
offset -= offsetInMinutes*aMinute;
alert(offset)
var offsetInSeconds = Math.round(offset/aSecond)
alert('offset:'+offset+'\n
// TIME AGO
//MINUTES
if (showMinutes) {
var plurMin = (offsetInMinutes==1) ? '':'s';
return timeAsText[offsetInMinutes
}
//HOURS
if (showHours) {
alert('hours:'+offsetInHou
offsetInMinutes -= (offsetInHours *60);
if (offsetInHours < 12) return 'today at: '+reference;
var plurHour = (offsetInHours==1) ? '':'s';
var plurMin = (offsetInMinutes==1) ? '':'s';
hourText = timeAsText[offsetInHours]+
minuteText = ' and '+ timeAsText[offsetInMinutes
alert( offsetInHours+':'+ timeAsText[offsetInHours]+
return (hourText+minuteText+' ago.');
}
//Days
if (showDays && offsetInDays < 4) {
plurDay = (offsetInDays==1) ? '':'s';
return timeAsText[offsetInDays]+'
}
// None of the above
return explicitDate(dateString, false);
}
function explicitDate(dateString, includeYearRegardless) {
var now = new Date();
var reference = new Date(dateString);
if (isNaN(reference)) return dateString;
var date = reference.getDate();
var month = monthAbbreviations[referen
var hours = reference.getHours();
var minutes = reference.getMinutes();
minutes = (minutes < 10)? "0"+minutes:minutes;
var seconds = reference.getSeconds();
seconds = (seconds < 10)? "0"+seconds:seconds;
var year = reference.getFullYear();
// Only show the year if out of current year!!!!
/* if ((reference.getFullYear() != now.getFullYear()) || includeYearRegardless) {
var year = ", " + reference.getFullYear();
} else {
var year = "";
}*/
return(month + ' ' +date + ', ' + year + ' at ' + hours +':'+ minutes);
}
dateReference("2006/08/17 03:00:00")
</script>