datetime.c (1002B)
1 #include <time.h> 2 3 #include "../uxn.h" 4 #include "datetime.h" 5 6 /* 7 Copyright (c) 2021-2023 Devine Lu Linvega, Andrew Alderwick 8 9 Permission to use, copy, modify, and distribute this software for any 10 purpose with or without fee is hereby granted, provided that the above 11 copyright notice and this permission notice appear in all copies. 12 13 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 14 WITH REGARD TO THIS SOFTWARE. 15 */ 16 17 Uint8 18 datetime_dei(Uxn *u, Uint8 addr) 19 { 20 time_t seconds = time(NULL); 21 struct tm zt = {0}, *t = localtime(&seconds); 22 if(t == NULL) t = &zt; 23 switch(addr) { 24 case 0xc0: return (t->tm_year + 1900) >> 8; 25 case 0xc1: return (t->tm_year + 1900); 26 case 0xc2: return t->tm_mon; 27 case 0xc3: return t->tm_mday; 28 case 0xc4: return t->tm_hour; 29 case 0xc5: return t->tm_min; 30 case 0xc6: return t->tm_sec; 31 case 0xc7: return t->tm_wday; 32 case 0xc8: return t->tm_yday >> 8; 33 case 0xc9: return t->tm_yday; 34 case 0xca: return t->tm_isdst; 35 default: return u->dev[addr]; 36 } 37 }