[go: up one dir, main page]

Menu

[897c37]: / mlib / lib / date.lpc  Maximize  Restore  History

Download this file

78 lines (65 with data), 1.5 kB

/*
 * handy date manipulation efuns
 */

/*
string ctime(time)
int time;

Give a time returned from time or some other source, convert it to a
human readable string of the form:

	"Sun Sep 16 01:03:52 1973\n"
         012345678901234567890123
All fields are of fixed width.
*/

static array Months;
reset(arg) {
	if (!arg) {
		Months = [ "","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug",
			"Sep","Oct","Nov","Dec" ];
	}
}

query_Months() { return Months; }
	
packed(t) { /* returns date in the form "921004 01:03" */
	t = get_time(t);
	return yymmdd(t)+t[10..15];
} 

get_time(t) {
	if (!t) return ctime(time());
	if (intp(t)) return ctime(t);
	return t;
}

year(t) { return (get_time(t))[20..]; }
day(t) { return (get_time(t))[..2]; }
date(t) { return (get_time(t))[8..9]; }
month(t) { return (get_time(t))[4..6]; }
hours(t) { return (get_time(t))[11..12]; }
minutes(t) { return (get_time(t))[14..15]; }
seconds(t) { return (get_time(t))[17..18]; }

hhmm(t) { return (get_time(t))[11..15]; }
hhmmss(t) { return (get_time(t))[11..18]; }
mmddyyyy(t) { return get_time(t)[4..9]+", "+get_time(t)[20..];}
ddmmyyyy(t) {
string ret;
	t = get_time(t);
	ret = _month(t);
	return date(t)+"/"+ret+"/"+year(t);
}

_month(t)
{
    (int|string) ret; 
	t = get_time(t);
	ret = index(Months, month(t));
	if (ret < 10) ret = "0"+ret;
	return ret + "";
}

_date(t)
{
    (int|string) ret;
	t = date(t);
    ret = atoi(t);
	if (ret < 10) ret = "0"+ret;
	return ret+"";
}

yymmdd(t) {
	t = get_time(t);
	return ""+year(t)[2..]+_month(t)+_date(t);
}