datecalc.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. datecalc.c
  3. Written 1996/96 by Oliver Kraus
  4. Published by Heinz Heise Verlag 1997 (c't 15/97)
  5. Completly rewritten and put under GPL 2011 by Oliver Kraus
  6. (c) 2011 by Oliver Kraus (olikraus@gmail.com)
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation, either version 3 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. Development goals:
  18. - English version
  19. - Optimized for 8 bit microcontroller
  20. Definitions:
  21. Short Name: y
  22. Long Name: year
  23. Range: 2000...
  24. Short Name: ydn
  25. Long Name: year day number
  26. Range: 1..366
  27. Short Name: cdn
  28. Long Name: century day number
  29. Range: 1...65535
  30. Short Name: ymd
  31. Long Name: Year, Month, Day
  32. Range: 2000...65535, 1..12, 1..31
  33. Conversions
  34. ymd --> y, ydn
  35. get_year_day_number()
  36. y, ydn --> ymd
  37. get_month_by_year_day_number()
  38. get_day_by_year_day_number()
  39. y, ydn --> cdn
  40. to_century_day_number();
  41. cdn --> y, ydn
  42. from_century_day_number();
  43. */
  44. #ifndef _DATECALC_H
  45. #define _DATECALC_H
  46. #include <stdint.h>
  47. uint16_t get_year_day_number(uint16_t y, uint8_t m, uint8_t d);
  48. uint8_t get_month_by_year_day_number(uint16_t y, uint16_t ydn);
  49. uint8_t get_day_by_year_day_number(uint16_t y, uint16_t ydn);
  50. uint8_t get_weekday_by_year_day_number(uint16_t y, uint16_t ydn);
  51. uint16_t to_century_day_number(uint16_t y, uint16_t ydn);
  52. void from_century_day_number(uint16_t cdn, uint16_t *year, uint16_t *ydn);
  53. uint32_t to_time(uint16_t cdn, uint8_t h, uint8_t m, uint8_t s);
  54. void from_time(uint32_t t, uint16_t *cdn, uint8_t *h, uint8_t *m, uint8_t *s);
  55. uint32_t to_sec_since_2000(uint16_t y, uint8_t mo, uint8_t d, uint8_t h, uint8_t mi, uint8_t s);
  56. uint32_t to_minutes(uint16_t cdn, uint8_t h, uint8_t m);
  57. void from_minutes(uint32_t t, uint16_t *cdn, uint8_t *h, uint8_t *m);
  58. uint32_t to_minutes_since_2000(uint16_t y, uint8_t mo, uint8_t d, uint8_t h, uint8_t mi);
  59. #endif