CetTime()

From Hack Wars Wiki

Jump to: navigation, search

This function returns the server time in CET (GMT+1) and the date, converts it to 24 hour system and checks whether it's a new day after the change.
Also if the month is February it will check whether there are 28 or 29 days in it.

The int arg in cetTime() is the argument for what it should return.
If arg is 1 it will return the time.
If arg is -1 it will return date and time
If arg is anything but 1 or -1 it will return the date.

string cetTime(int arg){
    string timeconv1[];
    string timeconv2[];
    string dateconv[];
    string iCET;
    string iDate;
    string dateTime;
    int hour;
    int day;
    int checkFeb;
    int year;
    boolean newDay = false;
 
    timeconv1 = split(getTime(), ":");
    timeconv2 = split(timeconv1[2], " ");
    timeconv1[2] = timeconv2[0];
    dateconv = split(getDate(), "-");
 
    hour = parseInt(timeconv1[0]) + 6;
    day = parseInt(dateconv[0]);
    year = parseInt(dateconv[2]);
 
    if(hour > 12 && timeconv2[1] == "PM"){
        iCET = "0" + (hour - 24) + ":" + timeconv1[1] + ":" + timeconv1[2];
        newDay = true;
    }
    else if(hour == 12 && timeconv2[1] == "PM"){
        iCET = "00:" + timeconv1[1] + ":" + timeconv1[2];
        newDay = true;
    }
    else{
        iCET = timeconv1[0] + ":" + timeconv1[1] + ":" + timeconv1[2];
    }
 
    if(newDay){
        if(dateconv[1] != "Feb"){
            if(timeconv[1] == "Jan"){
                if(day + 1 > 31){
                    iDate = "1-Feb-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Jan-" + year;
                }
            }
            else if(timeconv[1] == "Mar"){
                if(day + 1 > 31){
                    iDate = "1-Apr-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Mar-" + year;
                }
            }
            else if(timeconv[1] == "Apr"){
                if(day + 1 > 30){
                    iDate = "1-May-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Apr-" + year;
                }
            }
            else if(timeconv[1] == "May"){
                if(day + 1 > 31){
                    iDate = "1-Jun-" + year;
                }
                else{
                    day++;
                    iDate = day + "-May-" + year;
                }
            }
            else if(timeconv[1] == "Jun"){
                if(day + 1 > 30){
                    iDate = "1-Jul-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Jun-" + year;
                }
            }
            else if(timeconv[1] == "Jul"){
                if(day + 1 > 31){
                    iDate = "1-Aug-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Jul-" + year;
                }
            }
            else if(timeconv[1] == "Aug"){
                if(day + 1 > 31){
                    iDate = "1-Sep-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Aug-" + year;
                }
            }
            else if(timeconv[1] == "Sep"){
                if(day + 1 > 30){
                    iDate = "1-Oct-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Sep-" + year;
                }
            }
            else if(timeconv[1] == "Oct"){
                if(day + 1 > 31){
                    iDate = "1-Nov-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Oct-" + year;
                }
            }
            else if(timeconv[1] == "Nov"){
                if(day + 1 > 30){
                    iDate = "1-Dec-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Nov-" + year;
                }
            }
            else if(timeconv[1] == "Dec"){
                if(day + 1 > 31){
                    year++;
                    iDate = "1-Jan-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Dec-" + year;
                }
            }
        }
        else{
            checkFeb = year%4;
 
            if(checkFeb == 0){
                if(day + 1 > 29){
                    iDate = "1-Mar-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Feb-" + year;
                }
            }
            else{
                if(day + 1 > 28){
                    iDate = "1-Mar-" + year;
                }
                else{
                    day++;
                    iDate = day + "-Feb-" + year;
                }
            }
        }
    }
    else{
        iDate = date;
    }
 
    if(arg == 0){
        return iCET;
    }
    else if(arg == -1){
        dateTime = iDate + " " + iCET;
        return dateTime;
    }
    else{
        return iDate;
    }
}


arg == 1: 14:28:38
arg == -1: 17-May-2009 14:28:38
arg == 2(or anything else than 1 or -1): 17-May-2009

--Ridlr 11:02, 17 May 2009 (UTC)

Personal tools