#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); }
datetime mkdt(int days, int msecs);
bool isvalid(datetime);
datetime now(bool utc = true);
void tzupdate();
int tzoffset();
string dttostring(datetime, const char* fmt);
string nowstring(const char* fmt, bool utc = true);
datetime utodatetime(time_t u);
struct tm* dttotm(datetime dt, struct tm& t);
bool isleapyear(int year);
int daysinmonth(int year, int month);
int daysinyear(int year, int month);
int dayofweek(datetime);
bool isdatevalid(int year, int month, int day);
datetime encodedate(int year, int month, int day);
bool decodedate(datetime, int& year, int& month, int& day);
bool istimevalid(int hour, int min, int sec, int msec = 0);
datetime encodetime(int hour, int min, int sec, int msec = 0);
bool decodetime(datetime, int& hour, int& min, int& sec, int& msec);
bool decodetime(datetime, int& hour, int& min, int& sec);
PTYPES_END
#endif