-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
zellersCongruenceAlgorithm.sol
44 lines (41 loc) · 1.09 KB
/
zellersCongruenceAlgorithm.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title Zeller's Congruence Algorithm finds the day of the week from the Gregorian Date.
* @author [Perelyn](https://github.com/Perelyn-sama)
* @dev Wikipedia: https://en.wikipedia.org/wiki/Zeller%27s_congruence
*/
contract ZellersCongruenceAlgorithm {
string[] internal daysArr = [
"Saturday",
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday"
];
/// Get the median value of an array of numbers
function getzellersCongruenceAlgorithm(
uint256 day,
uint256 month,
uint256 year
) public view returns (string memory result) {
uint256 q = day;
uint256 m = month;
uint256 y = year;
if (month < 3) {
m += 12;
y -= 1;
}
day =
(q +
((26 * (m + 1)) / 10) +
(y % 100) +
((y % 100) / 4) +
((y / 100) / 4) +
(5 * (y / 100))) %
7;
return daysArr[day];
}
}