forked from haraldwolff/avr-fw-modules
65 lines
1.0 KiB
C
Executable File
65 lines
1.0 KiB
C
Executable File
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
typedef int32_t time_t;
|
|
|
|
struct datetime {
|
|
uint16_t year;
|
|
uint8_t month; // 0..11
|
|
uint8_t day; // 0..30
|
|
uint8_t hour; // 0..23
|
|
uint8_t minute; // 0..59
|
|
uint8_t second; // 0..59
|
|
};
|
|
|
|
typedef struct datetime datetime_t;
|
|
|
|
#define UTCH_CHECK 0
|
|
#define UTCH_CHANGING 1
|
|
#define UTCH_CHANGED 2
|
|
|
|
|
|
typedef int (*unix_time_changing_t)(int step,time_t oldtime,time_t newtime);
|
|
|
|
|
|
int unix2datetime(time_t unix,datetime_t* datetime);
|
|
time_t datetime2unix(datetime_t *datetime);
|
|
|
|
void unixtime_set(uint32_t _unixtime);
|
|
uint32_t unixtime(void);
|
|
|
|
uint32_t seconds_from_midnight(datetime_t *datetime);
|
|
|
|
static inline int daysfromyearstart(int month){
|
|
switch (month){
|
|
case 0:
|
|
return 0;
|
|
case 1:
|
|
return 31;
|
|
case 2:
|
|
return 59;
|
|
case 3:
|
|
return 90;
|
|
case 4:
|
|
return 120;
|
|
case 5:
|
|
return 151;
|
|
case 6:
|
|
return 181;
|
|
case 7:
|
|
return 212;
|
|
case 8:
|
|
return 243;
|
|
case 9:
|
|
return 273;
|
|
case 10:
|
|
return 304;
|
|
case 11:
|
|
return 334;
|
|
default:
|
|
return 0;
|
|
};
|
|
};
|
|
|