* GetDayOfWeek(day, month, year); - Obtiene el nombre del dнa de la semana de la fecha indicada * GetDate(); - Obtiene la fecha en formato "Sбbado 23 de Agosto del 2014". * GetTime(); - Obtiene la hora del servidor en formato "08:47:56". * GetMonthName(month); - Obtiene el nombre del mes * IsLeapDay(year); - Comprueba si el aсo es bisiesto o no (Gracias a este algoritmo http://es.wikipedia.org/wiki/A%C3%B1..._computacional)
* Aсadida la funciуn getTotalDaysInMonth(_month, year) para obtener el total de dнas de un mes. * Agregada GetSpecificDate(day = -1, month = -1, year = -1); para obtener la fecha en formato: "Lunes 21 de Marzo del 2016", sin embargo esta funciуn es para cuando se necesite especificar una fecha, y no sуlo obtener la actual. Al dejar todos los parбmetros en su opcional actuarб como GetDate() nada mбs que sin la hora. * Fue agregada GetTotalDaysFromYear(year) que permite obtener el total de dias que tiene un aсo, es una funcion simple nada mas por el tema de los aсos biciestos. * Agregado GetLeftDaysFromYear(day, _month, year) que permite obtener la cantidad de dias que faltan para que termine el aсo. * Agregada CountDaysSpentInYear(day, _month, Year) que permite obtener la cantidad de dias que han pasado ya en el aсo. * Agregada GetDateDateAddingDays(days, months, _day, _month, _year, &dia, &mes, &year) que permite obtener la fecha en variables, cuando se agreguen dias o meses. Si a 22-03-2016 le agregamos +15 dias, comunmente llegaria a 36-03-2016, sin embargo esta funcion permite aplicar las normas. Haciendo que aumente el mes, o incluso si estuvieramos en 29-12-2016 aumentaria el aсo. Evitando que se pierda la linea de la fecha conocida. * Agregada GetCurrentDateAddingDays(days, &dia, &mes, &year), actuando como GetDateDateAddingDays, solamente que en esta funcion no se especifica la fecha a la que se le adicionaran dias, y no permite adicionar meses, unicamente dias. Util para sistemas VIP. * Agregada GetCurrentDateAddingMonths(months, &dia, &mes, &year), que actua como GetDateDateAddingDays, pero aqui son meses. * Agregada PrintDate() que obtiene la fecha actual en YYYY-MM-DD, HH:MM * Agregada DateToUnix(day, month, year) que permite pasar de tiempo real DIA-MES-AСO a tiempo UNIX. * Agregada UnixToDate(x, &_day, &_month, &_year) que permite pasar de tiempo UNIX a DIA-MES-AСO * Funciones de tiempo a string. * Agregada GetDateFromStr_YYYYMMDDHHMM(str[], &day, &month, &year, &hour, &minute) que permite pasar una fecha al formato YYYY-MM-DD HH:MM * Agregada GetDateFromStr_DDMMYYYYHHMM(str[], &day, &month, &year, &hour, &minute) que permite pasar una fecha de variables al formato DD-MM-YYYY HH:MM Las funciones de tiempo especificadas anteriormente, no estan completas. Pronto se permitira pasar los datos al formato que se quiera evitando la limitacion por funcion. * Agregada FixFormatHour(hour, minute) que permite pasar horas de 3:2 a 03:02. No se ha utilizado %02d porque no cumplia con lo que se queria para la funcion.. * Agregada convert24HoursTo12Hours(time[]) que permite pasar de 24 horas: 13:00, a 12 Horas: 01:00 PM.
main()
{
new dia,
mes,
anual,
fecha[3] = {19,3,2016};
for(new i = 1; i < GetLeftDaysFromYear(fecha[0], fecha[1], fecha[2])-1; i++)
{
GetCurrentDateAddingDays(i+1, dia, mes, anual);
printf("%i. %s", i, GetSpecificDate(dia, mes, anual));
//sleep(1000/4); En caso de que quieran leerlos.
}
}
/* zTime - _Zume */
#include <a_samp>
#if !defined gettime_ex
#define gettime_ex gettime
#endif
#define GetCurrentDate() GetSpecificDate(-1, -1, -1)
#define IsLeapYear(%1) ((%1 % 4 == 0 && %1 % 100 != 0) || %1 % 400 == 0)
stock GetDayOfWeek(day, month, year) // Basado en http://es.wikipedia.org/wiki/Congruencia_de_Zeller
{
static const DaysWeek[][24] = {
"Lunes", // 0
"Martes", // 1
"Miйrcoles", // 2
"Jueves", // 3
"Viernes", // 4
"Sбbado", // 5
"Domingo" // 6
};
new
d_[4],
m_[10]
;
d_[0] = (14-month) / 12, d_[2] = year - d_[0], d_[1] = month + (12*d_[0]) - 2;
d_[3] = (day + d_[2] + (d_[2]/4) - (d_[2]/100) + (d_[2]/400) + (31*d_[1]) / 12) % 7;
if(d_[3] == 0)
{
d_[3] = sizeof(DaysWeek) - 1;
}
else
{
d_[3] -= 1;
}
format(m_, sizeof(m_), "%s", DaysWeek[d_[3]]);
return m_;
}
stock GetDate()
{
new output[40];
new _dat[3];
gettime_ex(_dat[0], _dat[1], _dat[2]);
format(output, sizeof(output), "%i:%i", _dat[0], _dat[1]);
format(output, sizeof(output), "%s - %s", GetCurrentDate(), convert24HoursTo12Hours(output));
return output;
}
stock GetTime()
{
new
m_[34],
d_[3]
;
gettime_ex(d_[0], d_[1], d_[2]), format(m_, sizeof(m_), "%02d:%02d", d_[0], d_[1], d_[2]);
return m_;
}
stock GetMonthName(month)
{
static const MonhtsYears[12][] = {
"Enero", // 0
"Febrero", // 1
"Marzo", // 2
"Abril", // 3
"Mayo", // 4
"Junio", // 5
"Julio", // 6
"Agosto", // 7
"Septiembre", // 8
"Octubre", // 9
"Noviembre", // 10
"Diciembre" // 11
};
new
month_str[24]
;
if(month > 0 && month <= sizeof(MonhtsYears)) {
format(month_str, sizeof(month_str), "%s", MonhtsYears[month-1]);
}
else{
format(month_str, sizeof(month_str), "Unknown");
}
return month_str;
}
stock getTotalDaysInMonth(_month, year)
{
new dias[] = {
31, // Enero
28, // Febrero
31, // Marzo
30, // Abril
31, // Mayo
30, // Junio
31, // Julio
31, // Agosto
30, // Septiembre
31, // Octubre
30, // Noviembre
31 // Diciembre
};
return ((_month >= 1 && _month <= 12) ? (dias[_month-1] + (IsLeapYear(year) && _month == 2 ? 1 : 0)) : 0);
}
stock GetSpecificDate(day = -1, month = -1, year = -1)
{
new str[64];
if(day == -1 && month == -1 && year == -1)
{
new _year, _month, _day;
getdate(_year, _month, _day);
format(str, sizeof(str), "%s %i de %s del %i", GetDayOfWeek(_day, _month, _year), _day, GetMonthName(_month), _year);
}
else
{
format(str, sizeof(str), "%s %i de %s del %i", GetDayOfWeek(day, month, year), day, GetMonthName(month), year);
}
return str;
}
stock GetTotalDaysFromYear(year) return IsLeapYear(year) ? 366 : 365;
stock GetLeftDaysFromYear(day, _month, year) return GetTotalDaysFromYear(year) - CountDaysSpentInYear(day, _month, year);
stock CountDaysSpentInYear(day, _month, Year)
{
new SumaDeDias = day;
for(new i = 1; i <= _month-1; i++)
SumaDeDias += getTotalDaysInMonth(i, Year);
return SumaDeDias;
}
stock GetDateDateAddingDays(days, months, _day, _month, _year, &dia, &mes, &year)
{
return UnixToDate(DateToUnix(_day, _month, _year) + (days * (60 * 60 * 24) + months * (60 * 60 * 24 * 30)), dia, mes, year);
}
stock GetCurrentDateAddingDays(days, &dia, &mes, &year)
{
new _year, _month, _day;
getdate(_year, _month, _day);
GetDateDateAddingDays(days, 0, _day, _month, _year, dia, mes, year);
return 1;
}
stock GetCurrentDateAddingMonths(months, &dia, &mes, &year)
{
new _year, _month, _day;
getdate(_year, _month, _day);
GetDateDateAddingDays(0, months, _day, _month, _year, dia, mes, year);
return 1;
}
stock GetDateFromStr_YYYYMMDDHHMM(str[], &day, &month, &year, &hour, &minute)
{
// formato -> YYYY/mm/dd, hh:mm
new numberStr[12];
strmid(numberStr, str, 8, 10);
day = strval(numberStr);
strmid(numberStr, str, 5, 7);
month = strval(numberStr);
strmid(numberStr, str, 0, 4);
year = strval(numberStr);
strmid(numberStr, str, 12, 14);
hour = strval(numberStr);
strmid(numberStr, str, 15, strlen(str)-1);
minute = strval(numberStr);
return 1;
}
stock GetDateFromStr_DDMMYYYYHHMM(str[], &day, &month, &year, &hour, &minute)
{
// formato -> dd/mm/YYYY, hh:mm
new numberStr[12];
strmid(numberStr, str, 0, 2);
day = strval(numberStr);
strmid(numberStr, str, 3, 5);
month = strval(numberStr);
strmid(numberStr, str, 6, 10);
year = strval(numberStr);
strmid(numberStr, str, 12, 14);
hour = strval(numberStr);
strmid(numberStr, str, 15, strlen(str)-1);
minute = strval(numberStr);
return 1;
}
stock FixFormatHour(hour, minute)
{
// 6:3 convert to 06:03
new str[9];
new bool:fixedHour[2];
if(0 <= hour <= 9){
format(str, sizeof(str), "0%i", hour);
fixedHour[0] = true;
}
if(0 <= minute <= 9){
format(str, sizeof(str), "%s:0%i", str, minute);
fixedHour[1] = true;
}
if(fixedHour[0] == false){
format(str, sizeof(str), "%i", hour);
}
if(fixedHour[1] == false){
format(str, sizeof(str), "%s:%i", str, minute);
}
/* format(str, sizeof(str), "%02d:%02d", hour, minute); <-- This does not work, does not meet the need correctly. */
return str;
}
stock convert24HoursTo12Hours(time[])
{
// 13:00 -> 01:00 PM
new output[32];
new pos = strfind(time, ":");
strmid(output, time, 0, pos+1);
new hora = strval(output);
strmid(output, time, pos+1, strlen(time));
new minuto = strval(output);
new _formatTime[3];
if(hora >= 13 && hora <= 24){
format(_formatTime, sizeof(_formatTime), "PM");
hora = hora - 12;
}
else if(hora >= 0 && hora <= 12){
format(_formatTime, sizeof(_formatTime), "AM");
}
format(output, sizeof(output), "%s %s", FixFormatHour(hora, minuto), _formatTime);
return output;
}
stock PrintDate() // YYYYMMDDHHMM
{
new output[40],
_dat[6];
getdate(_dat[0], _dat[1], _dat[2]);
gettime_ex(_dat[3], _dat[4], _dat[5]);
format(output, sizeof(output), "%02d/%02d/%d, %02d:%02d", _dat[0], _dat[1], _dat[2], _dat[3], _dat[4]);
return output;
}
stock DateToUnix(day, month, year)
{
new x = 0;
for(new j = 1970; j < year; j++)
{
x += (60 * 60 * 24)* 365;
if(IsLeapYear(j)){
x += (60*60)*24;
}
}
month--;
for (new i = 0; i < month; i++){
x += getTotalDaysInMonth(month, year) * 86400;
}
x += day * 86400;
return x;
}
stock UnixToDate(x, &_day, &_month, &_year)
{
new year = 1970;
new dia = 1;
new mes = 1;
while(x >= 86400) {
x -= 86400;
dia ++;
if(dia > getTotalDaysInMonth(mes, year)) {
dia = 1;
mes ++;
if(mes > 12) {
year ++;
mes = 1;
}
}
}
_day = dia;
_month = mes;
_year = year;
return x;
}
Por que la funciуn esta en ingles y retorna valores en espaсol?
|
Por que la funciуn esta en ingles y retorna valores en espaсol?
|
stock GetDayOfWeek(){
new data[10];
switch(((gettime()+334800)/86400-(gettime()+334800)/86400/7*7)){
case 1: data = "Lunes";
case 2: data = "Martes";
case 3: data = "Miйrcoles";
case 4: data = "Jueves";
case 5: data = "Viernes";
case 6: data = "Sбbado";
case 7: data = "Domingo";
default: data = "ERROR!";
}return data;
}