no, non ho l'abitudine di spannarmi, mi sembrava solo comodo e veloce come riferimento, c'è un minimo di casistica.Ianero ha scritto:Avanti Walter ora ammettilo (...)
Saluti
Moderatori:
Paolino,
fairyvilje
WALTERmwp ha scritto:Io indento così.
Ognuno ha le proprie abitudini e quando si legge un listato impostato diversamente si ha la sensazione di perdere immediatezza; almeno a me da quell'impressione.
Saluti
#include <time.h>
#include <string.h>
// ...
#define NOERROR 0
#define ERROR_ILLEGAL_FORMAT -1
#define ERROR_ILLEGAL_DATE -2
// ...
/*******************************************************************************
Function:
int millenniumDays(char *yyyymmdd, long *days)
Parameters:
char *yyyymmdd : date in yyyymmdd format
long *days : to return elapsed days
Description:
returns the number of elapsed days from January 1st, 2000 to the specified date
(not included), or until today (not included) if the yyyymmdd string is NULL.
Return values:
NOERROR : correct execution
ERROR_ILLEGAL_FORMAT : the input string has an illegal format
ERROR_ILLEGAL_DATE : the input date is out of bounds or incorrect
Notes:
works from 1900-03-01 to 2100-02-28.
Returns negative values for dates before 2000-01-01.
*******************************************************************************/
int millenniumDays(char *yyyymmdd, long *days)
{
int bError = NOERROR;
if (yyyymmdd == NULL)
{
// Calculate elapsed days from 2000-01-01 until today (not included):
const int secondsInADay = 86400;
const int daysFrom1970_01_01To2000_01_01 = 10957;
// Works only for system dates from 1970 onward
//(otherwise truncation toward 0 instead of floor in C99 integer division must be taken into account):
*days = (time(NULL) / secondsInADay - daysFrom1970_01_01To2000_01_01);
}
else
{
// Calculate elapsed days from 2000-01-01 until yyyymmdd date (not included):
const int monthDays [12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int sumOfPreviousMonthsDays[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
int year, month, day;
if ((strspn(yyyymmdd, "0123456789") == 8)
&&
(yyyymmdd[8] == '\0'))
{
year = (yyyymmdd[0] - '0') * 1000 + (yyyymmdd[1] - '0') * 100 + (yyyymmdd[2] - '0') * 10 + (yyyymmdd[3] - '0');
month = (yyyymmdd[4] - '0') * 10 + (yyyymmdd[5] - '0');
day = (yyyymmdd[6] - '0') * 10 + (yyyymmdd[7] - '0');
// If it is an acceptable date:
if ((((year > 1900) && (year < 2100)) || ((year == 1900) && (month >= 3)) || ((year == 2100) && (month <= 2)))
&&
((month >= 1) && (month <= 12))
&&
((day >= 1) && ((day <= monthDays[month - 1]) || ((day == 29) && ((year % 4) == 0) && (year != 2100)))))
{
// Calculate year and month days, withouth adjusting for leap years for the moment:
*days = (year - 2000) * 365 + sumOfPreviousMonthsDays[month - 1];
// Adjust for leap years and add day-of-month days:
// (*days - 32..58) / (365 * 4): anything works between 32 and 58 to distinguish between February and March,
// to add one day every 4 years, but only from March onward.
// - (*days < 32..58): is needed because C99 integer division does not floor the result, but truncates it toward 0.
*days += (*days - 32) / (365 * 4) - (*days < 32) + day;
}
else
{
bError = ERROR_ILLEGAL_DATE;
}
}
else
{
bError = ERROR_ILLEGAL_FORMAT;
}
}
return bError;
}
// ...


echo $var==TRUE ? 'TRUE' : 'FALSE';
Però sembra apprezzare lo stesso, sarà abituato a peggio






Visitano il forum: Nessuno e 10 ospiti