#ifndef __PTIME_H__
#define __PTIME_H__
#ifndef __PPORT_H__
#include "pport.h"
#endif
#ifndef __PTYPES_H__
#include "ptypes.h"
#endif
#include <time.h>
PTYPES_BEGIN
typedef large datetime;
#define invdatetime LLCONST(-1)
#define _msecsmax 86400000
#define _daysmax 3652059
#define _datetimemax LLCONST(315537897600000)
#define _unixepoch LLCONST(62135596800000)
inline int days(datetime d) { return int(d / _msecsmax); }
inline int msecs(datetime d) { return int(d % _msecsmax); }
ptpublic datetime mkdt(int days, int msecs);
ptpublic bool isvalid(datetime);
ptpublic datetime now(bool utc = true);
ptpublic void tzupdate();
ptpublic int tzoffset();
ptpublic string dttostring(datetime, const char* fmt);
ptpublic string nowstring(const char* fmt, bool utc = true);
ptpublic datetime utodatetime(time_t u);
ptpublic struct tm* dttotm(datetime dt, struct tm& t);
ptpublic bool isleapyear(int year);
ptpublic int daysinmonth(int year, int month);
ptpublic int daysinyear(int year, int month);
ptpublic int dayofweek(datetime);
ptpublic bool isdatevalid(int year, int month, int day);
ptpublic datetime encodedate(int year, int month, int day);
ptpublic bool decodedate(datetime, int& year, int& month, int& day);
ptpublic bool istimevalid(int hour, int min, int sec, int msec = 0);
ptpublic datetime encodetime(int hour, int min, int sec, int msec = 0);
ptpublic bool decodetime(datetime, int& hour, int& min, int& sec, int& msec);
ptpublic bool decodetime(datetime, int& hour, int& min, int& sec);
PTYPES_END
#endif