2014-12-01 23:55:08 +01:00
|
|
|
|
// swad_date.h: dates
|
|
|
|
|
|
|
|
|
|
#ifndef _SWAD_DAT
|
|
|
|
|
#define _SWAD_DAT
|
|
|
|
|
/*
|
|
|
|
|
SWAD (Shared Workspace At a Distance in Spanish),
|
|
|
|
|
is a web platform developed at the University of Granada (Spain),
|
|
|
|
|
and used to support university teaching.
|
|
|
|
|
|
|
|
|
|
This file is part of SWAD core.
|
2016-01-01 20:19:43 +01:00
|
|
|
|
Copyright (C) 1999-2016 Antonio Ca<EFBFBD>as Vargas
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************************* Headers ***********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-10-16 02:24:29 +02:00
|
|
|
|
#include <stdbool.h> // For boolean type
|
|
|
|
|
#include <stdio.h> // For FILE *
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Public constants ******************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#define Dat_SECONDS_IN_ONE_MONTH (30UL*24UL*60UL*60UL)
|
|
|
|
|
|
2015-10-28 21:47:42 +01:00
|
|
|
|
#define Dat_MAX_BYTES_TIME_ZONE 256
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************* Public types ********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
struct Date
|
|
|
|
|
{
|
2016-06-01 19:34:44 +02:00
|
|
|
|
unsigned Day;
|
|
|
|
|
unsigned Month;
|
|
|
|
|
unsigned Year;
|
|
|
|
|
unsigned Week;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
char YYYYMMDD[4+2+2+1];
|
|
|
|
|
};
|
|
|
|
|
struct Time
|
|
|
|
|
{
|
2016-06-01 19:34:44 +02:00
|
|
|
|
unsigned Hour;
|
|
|
|
|
unsigned Minute;
|
|
|
|
|
unsigned Second;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
};
|
|
|
|
|
struct Hour
|
|
|
|
|
{
|
2016-06-01 19:34:44 +02:00
|
|
|
|
unsigned Hour;
|
|
|
|
|
unsigned Minute;
|
2014-12-01 23:55:08 +01:00
|
|
|
|
};
|
|
|
|
|
struct DateTime
|
|
|
|
|
{
|
|
|
|
|
struct Date Date;
|
|
|
|
|
struct Time Time;
|
|
|
|
|
char YYYYMMDDHHMMSS[4+2+2+2+2+2+1];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Public prototypes *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-10-27 19:00:21 +01:00
|
|
|
|
void Dat_GetStartExecutionTimeUTC (void);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
void Dat_GetAndConvertCurrentDateTime (void);
|
|
|
|
|
|
2015-10-22 01:24:43 +02:00
|
|
|
|
time_t Dat_GetUNIXTimeFromStr (const char *Str);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
bool Dat_GetDateFromYYYYMMDD (struct Date *Date,const char *YYYYMMDDString);
|
|
|
|
|
|
2015-10-22 01:24:43 +02:00
|
|
|
|
void Dat_ShowClientLocalTime (void);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
|
|
|
|
void Dat_GetLocalTimeFromClock (const time_t *clock);
|
|
|
|
|
void Dat_ConvDateToDateStr (struct Date *Date,char *DateStr);
|
|
|
|
|
|
2015-10-25 00:23:22 +02:00
|
|
|
|
void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (void);
|
2015-10-24 21:41:41 +02:00
|
|
|
|
void Dat_PutFormStartEndClientLocalDateTimes (time_t TimeUTC[2]);
|
2015-10-22 01:24:43 +02:00
|
|
|
|
|
2015-10-26 20:02:07 +01:00
|
|
|
|
void Dat_WriteFormClientLocalDateTimeFromTimeUTC (const char *Id,
|
|
|
|
|
const char *ParamName,
|
|
|
|
|
time_t TimeUTC,
|
|
|
|
|
unsigned FirstYear,unsigned LastYear,
|
2015-10-26 20:13:09 +01:00
|
|
|
|
bool SubmitFormOnChange);
|
2015-10-22 10:55:59 +02:00
|
|
|
|
time_t Dat_GetTimeUTCFromForm (const char *ParamName);
|
2015-10-22 01:24:43 +02:00
|
|
|
|
|
2015-10-28 21:47:42 +01:00
|
|
|
|
void Dat_PutHiddenParBrowserTZDiff (void);
|
|
|
|
|
void Dat_GetBrowserTimeZone (char BrowserTimeZone[Dat_MAX_BYTES_TIME_ZONE+1]);
|
2015-10-27 22:59:49 +01:00
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
void Dat_WriteFormDate (unsigned FirstYear,unsigned LastYear,
|
2015-10-23 01:06:32 +02:00
|
|
|
|
const char *Id,
|
2014-12-01 23:55:08 +01:00
|
|
|
|
struct Date *DateSelected,
|
|
|
|
|
bool SubmitFormOnChange,bool Disabled);
|
2015-10-22 10:55:59 +02:00
|
|
|
|
void Dat_GetDateFromForm (const char *ParamNameDay,const char *ParamNameMonth,const char *ParamNameYear,
|
2014-12-01 23:55:08 +01:00
|
|
|
|
unsigned *Day,unsigned *Month,unsigned *Year);
|
|
|
|
|
|
|
|
|
|
void Dat_GetIniEndDatesFromForm (void);
|
|
|
|
|
|
|
|
|
|
void Dat_WriteRFC822DateFromTM (FILE *File,struct tm *tm);
|
|
|
|
|
|
|
|
|
|
void Dat_GetDateBefore (struct Date *Date,struct Date *PrecedingDate);
|
|
|
|
|
void Dat_GetDateAfter (struct Date *Date,struct Date *SubsequentDate);
|
|
|
|
|
void Dat_GetWeekBefore (struct Date *Date,struct Date *PrecedingDate);
|
|
|
|
|
void Dat_GetMonthBefore (struct Date *Date,struct Date *PrecedingDate);
|
|
|
|
|
unsigned Dat_GetNumDaysBetweenDates (struct Date *DateIni,struct Date *DateEnd);
|
|
|
|
|
unsigned Dat_GetNumWeeksBetweenDates (struct Date *DateIni,struct Date *DateEnd);
|
|
|
|
|
unsigned Dat_GetNumMonthsBetweenDates (struct Date *DateIni,struct Date *DateEnd);
|
|
|
|
|
unsigned Dat_GetNumDaysInYear (unsigned Year);
|
|
|
|
|
unsigned Dat_GetNumDaysFebruary (unsigned Year);
|
|
|
|
|
bool Dat_GetIfLeapYear (unsigned Year);
|
|
|
|
|
unsigned Dat_GetNumWeeksInYear (unsigned Year);
|
|
|
|
|
unsigned Dat_GetDayOfWeek (unsigned Year,unsigned Month,unsigned Day);
|
|
|
|
|
unsigned Dat_GetDayOfYear (struct Date *Date);
|
|
|
|
|
void Dat_CalculateWeekOfYear (struct Date *Date);
|
|
|
|
|
void Dat_AssignDate (struct Date *DateDst,struct Date *DateSrc);
|
|
|
|
|
|
2015-10-27 19:44:31 +01:00
|
|
|
|
void Dat_WriteScriptMonths (void);
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#endif
|