//Taken from: http://p...content-available-to-author-only...e.org/349916#57,61,162,175
//see also http://w...content-available-to-author-only...s.com/forums/showthread.php?t=38143
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
#include <stdio.h>
// Global Variables
//These macro define some default information of RTC
#define ORIGINYEAR 1980 // the begin year
#define MAXYEAR (ORIGINYEAR + 100) // the maxium year
//------------------------------------------------------------------------------
//
// Function: IsLeapYear
//
// Local helper function checks if the year is a leap year
//
// Parameters:
//
// Returns:
//
//
//------------------------------------------------------------------------------
static int IsLeapYear(int Year)
{
int Leap;
Leap = 0;
if ((Year % 4) == 0) {
Leap = 1;
if ((Year % 100) == 0) {
Leap = (Year%400) ? 0 : 1;
}
}
return (Leap);
}
int main(void) {
int days;
/*
Фрагмент кода для разбора даты:
вход: days - количество прошедших дней,
начиная с 1 января 1980
на выходе: year - год
days - количество прошедших дней,
начиная с начала года year
*/
int year;
//...
year = ORIGINYEAR;
while (days > 365)
{
if (IsLeapYear(year))
{
if (days > 366)
{
days -= 366;
year += 1;
}
}
else
{
days -= 365;
year += 1;
}
}
printf("Days from beginning of year: %d\n", days
);
return 0;
}
Ly9UYWtlbiBmcm9tOiBodHRwOi8vcC4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4uZS5vcmcvMzQ5OTE2IzU3LDYxLDE2MiwxNzUKLy9zZWUgYWxzbyBodHRwOi8vdy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4ucy5jb20vZm9ydW1zL3Nob3d0aHJlYWQucGhwP3Q9MzgxNDMKCi8vCi8vIENvcHlyaWdodCAoYykgTWljcm9zb2Z0IENvcnBvcmF0aW9uLiAgQWxsIHJpZ2h0cyByZXNlcnZlZC4KLy8KCiNpbmNsdWRlIDxzdGRpby5oPgoKLy8gR2xvYmFsIFZhcmlhYmxlcwovL1RoZXNlIG1hY3JvIGRlZmluZSBzb21lIGRlZmF1bHQgaW5mb3JtYXRpb24gb2YgUlRDCi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jQuNGFINC00L3QtdC5LCAKICAgICAgINC90LDRh9C40L3QsNGPINGBIDEg0Y/QvdCy0LDRgNGPIDE5ODAK0L3QsCDQstGL0YXQvtC00LU6IHllYXIgLSDQs9C+0LQKICAgICAgZGF5cyAtINC60L7Qu9C40YfQtdGB0YLQstC+INC/0YDQvtGI0LXQtNGI0LjRhSDQtNC90LXQuSwKICAgICAgINC90LDRh9C40L3QsNGPINGBINC90LDRh9Cw0LvQsCDQs9C+0LTQsCB5ZWFyCiAgICAqLwoJCgkKCWludCB5ZWFyOwoJCgkvLy4uLgoKICAgIHllYXIgPSBPUklHSU5ZRUFSOwoKICAgIHdoaWxlIChkYXlzID4gMzY1KQogICAgewogICAgICAgIGlmIChJc0xlYXBZZWFyKHllYXIpKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKGRheXMgPiAzNjYpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGRheXMgLT0gMzY2OwogICAgICAgICAgICAgICAgeWVhciArPSAxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGRheXMgLT0gMzY1OwogICAgICAgICAgICB5ZWFyICs9IDE7CiAgICAgICAgfQogICAgfQoKCiAgICAKICAgIAogICAgcHJpbnRmKCJZZWFyIGlzICU0ZFxuIix5ZWFyKTsKICAgIHByaW50ZigiRGF5cyBmcm9tIGJlZ2lubmluZyBvZiB5ZWFyOiAlZFxuIiwgZGF5cyk7CiAgICAKICAgIAogICAgCglyZXR1cm4gMDsKfQo=