Difference: DateFunctions (1 vs. 2)

Revision 22018-03-29 - JimSkon

Line: 1 to 1

 META TOPICPARENT name="Lab7Startup"

Date computations

Line: 4 to 4
%CODE{"c++"}%
Deleted:
<
<
/* Returns the day number of a date */
Changed:
<
<
int dayNumber(Date d) { d.month = (d.month + 9) % 12; d.year = d.year - d.month / 10; return 365 * d.year + d.year / 4 - d.year / 100 + d.year / 400 + (d.month * 306 + 5) / 10 + (d.day - 1);
>
>
int Date::dayNumber() { int m = (month + 9) % 12; int y = year - m / 10; return 365 * y + y / 4 - y / 100 + y / 400 + (m * 306 + 5) / 10 + (day - 1);
}

/* Returns the date of a day number (g) */

Changed:
<
<
Date dayFromNumber(int g) { Date d; d.year = (10000 * g + 14780) / 3652425; int ddd = g - (365 * d.year + d.year / 4 - d.year / 100 + d.year / 400);
>
>
void Date::dateFromNumber(int g) { year = (10000 * g + 14780) / 3652425; int ddd = g - (365 * year + year / 4 - year / 100 + year / 400);
if (ddd < 0) {
Changed:
<
<
d.year = d.year - 1; ddd = g - (365 * d.year + d.year / 4 - d.year / 100 + d.year / 400);
>
>
year = year - 1; ddd = g - (365 * year + year / 4 - year / 100 +year / 400);
} int mi = (100 * ddd + 52) / 3060;
Changed:
<
<
d.month = (mi + 2) % 12 + 1; d.year = d.year + (mi + 2) / 12; d.day = ddd - (mi * 306 + 5) / 10 + 1; return d;
>
>
month = (mi + 2) % 12 + 1; year = year + (mi + 2) / 12; day = ddd - (mi * 306 + 5) / 10 + 1;
}

Revision 12018-03-29 - JimSkon

Line: 1 to 1
>
>
 META TOPICPARENT name="Lab7Startup"

Date computations

`<-- SyntaxHighlightingPlugin -->`
```/* Returns the day number of a date */
int dayNumber(Date d) {
d.month = (d.month + 9) % 12;
d.year = d.year - d.month / 10;
return 365 * d.year + d.year / 4 - d.year / 100 + d.year / 400 + (d.month * 306 + 5) / 10 + (d.day - 1);
}

/* Returns the date of a day number (g) */
Date dayFromNumber(int g) {
Date d;
d.year = (10000 * g + 14780) / 3652425;
int ddd = g - (365 * d.year + d.year / 4 - d.year / 100 + d.year / 400);
if (ddd < 0) {
d.year = d.year - 1;
ddd = g - (365 * d.year + d.year / 4 - d.year / 100 + d.year / 400);
}
int mi = (100 * ddd + 52) / 3060;
d.month = (mi + 2) % 12 + 1;
d.year = d.year + (mi + 2) / 12;
d.day = ddd - (mi * 306 + 5) / 10 + 1;
return d;
}

```
`<-- end SyntaxHighlightingPlugin -->`

Copyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback