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.
|
2019-01-07 21:52:19 +01:00
|
|
|
|
Copyright (C) 1999-2019 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>
|
|
|
|
|
|
2017-05-05 02:03:28 +02:00
|
|
|
|
#include "swad_constant.h"
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Public constants ******************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-01-28 15:58:46 +01:00
|
|
|
|
#define Dat_SECONDS_IN_ONE_MONTH (30UL * 24UL * 60UL * 60UL)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2015-10-28 21:47:42 +01:00
|
|
|
|
#define Dat_MAX_BYTES_TIME_ZONE 256
|
|
|
|
|
|
2018-10-18 02:02:32 +02:00
|
|
|
|
#define Dat_MAX_BYTES_TIME (128 - 1)
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************************* Public types ********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-01-13 01:51:23 +01:00
|
|
|
|
#define Dat_LENGTH_YYYYMMDD (4 + 2 + 2)
|
2014-12-01 23:55:08 +01:00
|
|
|
|
struct Date
|
|
|
|
|
{
|
2016-06-01 19:34:44 +02:00
|
|
|
|
unsigned Day;
|
|
|
|
|
unsigned Month;
|
|
|
|
|
unsigned Year;
|
|
|
|
|
unsigned Week;
|
2017-01-13 01:51:23 +01:00
|
|
|
|
char YYYYMMDD[Dat_LENGTH_YYYYMMDD + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
};
|
|
|
|
|
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;
|
2017-01-28 15:58:46 +01:00
|
|
|
|
char YYYYMMDDHHMMSS[4 + 2 + 2 + 2 + 2 + 2 + 1];
|
2014-12-01 23:55:08 +01:00
|
|
|
|
};
|
|
|
|
|
|
2016-12-02 10:45:53 +01:00
|
|
|
|
#define Dat_NUM_TIME_STATUS 3
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
Dat_PAST = 0,
|
|
|
|
|
Dat_PRESENT = 1,
|
|
|
|
|
Dat_FUTURE = 2,
|
|
|
|
|
} Dat_TimeStatus_t;
|
|
|
|
|
|
2016-12-15 00:39:52 +01:00
|
|
|
|
#define Dat_NUM_START_END_TIME 2
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
Dat_START_TIME = 0,
|
|
|
|
|
Dat_END_TIME = 1,
|
|
|
|
|
} Dat_StartEndTime_t;
|
|
|
|
|
|
|
|
|
|
#define Dat_NUM_FORM_SECONDS 2
|
2016-12-03 20:08:01 +01:00
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
Dat_FORM_SECONDS_OFF,
|
|
|
|
|
Dat_FORM_SECONDS_ON,
|
|
|
|
|
} Dat_FormSeconds;
|
|
|
|
|
|
2017-02-26 20:09:21 +01:00
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
Dat_HMS_DO_NOT_SET = 0,
|
|
|
|
|
Dat_HMS_TO_000000 = 1,
|
|
|
|
|
Dat_HMS_TO_235959 = 2,
|
|
|
|
|
} Dat_SetHMS;
|
|
|
|
|
|
2017-05-04 02:19:23 +02:00
|
|
|
|
/***** Date format *****/
|
|
|
|
|
#define Dat_NUM_OPTIONS_FORMAT 3
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
Dat_FORMAT_YYYY_MM_DD = 0, // ISO 8601, default
|
|
|
|
|
Dat_FORMAT_DD_MONTH_YYYY = 1,
|
|
|
|
|
Dat_FORMAT_MONTH_DD_YYYY = 2,
|
2017-05-04 11:03:44 +02:00
|
|
|
|
} Dat_Format_t; // Do not change these numbers because they are used in database
|
2017-05-04 02:19:23 +02:00
|
|
|
|
#define Dat_FORMAT_DEFAULT Dat_FORMAT_YYYY_MM_DD
|
|
|
|
|
|
2019-11-02 12:10:58 +01:00
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
Dat_SEPARATOR_NONE, // No separator
|
|
|
|
|
Dat_SEPARATOR_COMMA, // Comma + space
|
|
|
|
|
Dat_SEPARATOR_BREAK, // Line break
|
|
|
|
|
} Dat_Separator_t;
|
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/***************************** Public prototypes *****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-05-07 18:06:34 +02:00
|
|
|
|
void Dat_PutBoxToSelectDateFormat (void);
|
2017-05-04 23:27:51 +02:00
|
|
|
|
|
|
|
|
|
void Dat_PutSpanDateFormat (Dat_Format_t Format);
|
|
|
|
|
void Dat_PutScriptDateFormat (Dat_Format_t Format);
|
|
|
|
|
|
2017-05-04 02:19:23 +02:00
|
|
|
|
void Dat_ChangeDateFormat (void);
|
2017-05-04 11:03:44 +02:00
|
|
|
|
Dat_Format_t Dat_GetDateFormatFromStr (const char *Str);
|
2017-05-04 02:19:23 +02:00
|
|
|
|
|
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
|
|
|
|
|
2016-12-11 19:30:42 +01:00
|
|
|
|
struct tm *Dat_GetLocalTimeFromClock (const time_t *timep);
|
2017-05-05 02:03:28 +02:00
|
|
|
|
void Dat_ConvDateToDateStr (struct Date *Date,char StrDate[Cns_MAX_BYTES_DATE + 1]);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
|
2017-02-26 20:09:21 +01:00
|
|
|
|
void Dat_PutFormStartEndClientLocalDateTimesWithYesterdayToday (bool SetHMS000000To235959);
|
2016-12-03 20:08:01 +01:00
|
|
|
|
void Dat_PutFormStartEndClientLocalDateTimes (time_t TimeUTC[2],
|
|
|
|
|
Dat_FormSeconds FormSeconds);
|
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,
|
2016-12-03 20:08:01 +01:00
|
|
|
|
unsigned FirstYear,
|
|
|
|
|
unsigned LastYear,
|
|
|
|
|
Dat_FormSeconds FormSeconds,
|
2017-02-26 20:09:21 +01:00
|
|
|
|
Dat_SetHMS SetHMS,
|
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);
|
2017-01-28 15:58:46 +01:00
|
|
|
|
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);
|
|
|
|
|
|
2019-02-11 22:15:18 +01:00
|
|
|
|
void Dat_SetIniEndDates (void);
|
|
|
|
|
void Dat_WriteParamsIniEndDates (void);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
void Dat_GetIniEndDatesFromForm (void);
|
|
|
|
|
|
|
|
|
|
void Dat_WriteRFC822DateFromTM (FILE *File,struct tm *tm);
|
|
|
|
|
|
2018-10-07 14:01:25 +02:00
|
|
|
|
void Dat_GetDateAfter (struct Date *Date,struct Date *SubsequentDate);
|
|
|
|
|
void Dat_GetDateBefore (struct Date *Date,struct Date *PrecedingDate );
|
|
|
|
|
void Dat_GetWeekBefore (struct Date *Date,struct Date *PrecedingDate );
|
|
|
|
|
void Dat_GetMonthBefore (struct Date *Date,struct Date *PrecedingDate );
|
|
|
|
|
void Dat_GetYearBefore (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_GetNumYearsBetweenDates (struct Date *DateIni,
|
|
|
|
|
struct Date *DateEnd);
|
2014-12-01 23:55:08 +01:00
|
|
|
|
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);
|
|
|
|
|
|
2019-01-11 12:32:41 +01:00
|
|
|
|
void Dat_WriteHoursMinutesSecondsFromSeconds (time_t Seconds);
|
2019-09-09 21:37:29 +02:00
|
|
|
|
void Dat_WriteHoursMinutesSeconds (struct Time *Time);
|
2019-01-11 12:32:41 +01:00
|
|
|
|
|
2019-11-01 23:35:55 +01:00
|
|
|
|
void Dat_WriteLocalDateHMSFromUTC (const char *Id,time_t TimeUTC,
|
2019-11-02 12:10:58 +01:00
|
|
|
|
Dat_Format_t DateFormat,Dat_Separator_t Separator,
|
2019-11-02 11:45:41 +01:00
|
|
|
|
bool WriteToday,bool WriteDateOnSameDay,
|
|
|
|
|
bool WriteWeekDay,unsigned WriteHMS);
|
2019-11-01 17:35:26 +01:00
|
|
|
|
|
2014-12-01 23:55:08 +01:00
|
|
|
|
#endif
|