2022-01-07 13:02:28 -05:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "../uxn.h"
|
|
|
|
#include "datetime.h"
|
|
|
|
|
|
|
|
/*
|
2023-01-02 09:40:23 -05:00
|
|
|
Copyright (c) 2021-2023 Devine Lu Linvega, Andrew Alderwick
|
2022-01-07 13:02:28 -05:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
Uint8
|
2023-01-01 16:19:40 -05:00
|
|
|
datetime_dei(Uint8 *d, Uint8 port)
|
2022-01-07 13:02:28 -05:00
|
|
|
{
|
|
|
|
time_t seconds = time(NULL);
|
|
|
|
struct tm zt = {0};
|
|
|
|
struct tm *t = localtime(&seconds);
|
|
|
|
if(t == NULL)
|
|
|
|
t = &zt;
|
|
|
|
switch(port) {
|
|
|
|
case 0x0: return (t->tm_year + 1900) >> 8;
|
|
|
|
case 0x1: return (t->tm_year + 1900);
|
|
|
|
case 0x2: return t->tm_mon;
|
|
|
|
case 0x3: return t->tm_mday;
|
|
|
|
case 0x4: return t->tm_hour;
|
|
|
|
case 0x5: return t->tm_min;
|
|
|
|
case 0x6: return t->tm_sec;
|
|
|
|
case 0x7: return t->tm_wday;
|
|
|
|
case 0x8: return t->tm_yday >> 8;
|
|
|
|
case 0x9: return t->tm_yday;
|
|
|
|
case 0xa: return t->tm_isdst;
|
2023-01-01 16:19:40 -05:00
|
|
|
default: return d[port];
|
2022-01-07 13:02:28 -05:00
|
|
|
}
|
2022-01-07 17:46:39 -05:00
|
|
|
}
|