View Single Post
  #9  
Old 02-17-2007, 01:17 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Ok, this is very barebone, but maybe you can make use of it. All of the hard math stuff has been done already.

PHP Code:
enum {
  
SEC,   //Seconds
  
MIN,   //Minutes
  
HOUR,  //Hours
  
WDAY,  //Day of the week (0:Sunday to 6:Saturday)
  
YEAR,  //Year
  
YDAY,  //Day of the year (starts at 0)
  
MON,   //Month (0:January to 11:December)
  
MDAY   //Day of the Month
}
const 
EPOCH_YR 1970;          //Epoch Year
const SECS_DAY 24 60 60;  //Seconds in a day

/**
  gmtime():
    Returns array (see enum)
 */
function gmtime(tvar) {
  
temp.result;
  
temp.dayclocktemp.dayno;
  
temp.year;
  
  
result = new[8];
  
year EPOCH_YR;
  
dayclock tvar SECS_DAY;
  
dayno tvar SECS_DAY;

  
result[SEC] = dayclock 60;
  
result[MIN] = (dayclock 3600) / 60;
  
result[HOUR] = dayclock 3600;
  
result[WDAY] = (dayno 4) % 7;  //Epoch starts on a Thurs.
  
  
while (dayno >= YEARSIZE(year)) {
    
dayno -= YEARSIZE(year);
    
year++;
  }
  
  
result[YEAR] = year;
  
result[YDAY] = dayno;
  
result[MON] = 0;
  while (
dayno >= this._ytab[LEAPYEAR(year)][result[MON]]) {
    
dayno -= this._ytab[LEAPYEAR(year)][result[MON]];
    
result[MON]++;
  }
  
result[MDAY] = dayno 1;
  
  return 
result;
}

function 
LEAPYEAR(year) {
  return (!((
year) % 4) && (((year) % 100) || !((year) % 400)));
}

function 
YEARSIZE(year) {
  return (
LEAPYEAR(year) ? 366 365)

Here is code that initializes some pseudo-const arrays and a little bit of sample code that will make use of the array that gmtime returns:
PHP Code:
//Pseudo-constarrays
function constArrays() {
  
//I WANT CONST ARRAYS!
  
this._ytab = {
    {
312831303130313130313031},
    {
312931303130313130313031}
  };
  
this._days = {
    
"Sunday""Monday""Tuesday""Wednesday",
    
"Thursday""Friday""Saturday"
  
};
  
this._months = {
    
"January""February""March",
    
"April""May""June",
    
"July""August""September",
    
"October""November""December"
  
};
  
//STILL WANT CONST ARRAYS!
}
function 
onCreated() {
  
constArrays();

  
//Sample Code
  
temp.result;
  
result gmtime(timevar2 60*60*8);  //GMT - 8
  
printf("Time (Pacific): %d:%d:%d"result[HOUR], result[MIN], result[SEC]);
  
printf("Date (Pacific): %s, %s %d, %d"this._days[result[WDAY]], this._months[result[MON]], result[MDAY], result[YEAR]);

Again, this is just all the math stuff done for you. If I get around to making functions that will return a date/time based on a format string (like PHP's time() function), I will release it in the code gallery, but maybe this can get you started with whatever you need to do.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.

Last edited by napo_p2p; 02-17-2007 at 01:52 AM..
Reply With Quote