Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
|||
function lastSundayOfEachMonths(year) {
|
||||
var lastDay = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
||||
var sundays = [];
|
||||
var date, month;
|
||||
if (year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)) {
|
||||
lastDay[2] = 29;
|
||||
}
|
||||
for (date = new Date(), month = 0; month < 12; month += 1) {
|
||||
date.setFullYear(year, month, lastDay[month]);
|
||||
date.setDate(date.getDate() - date.getDay());
|
||||
sundays.push(date.toISOString().substring(0, 10));
|
||||
}
|
||||
return sundays;
|
||||
}
|
||||
|
||||
console.log(lastSundayOfEachMonths(2013).join('\n'));
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
// lastSundaysOfYear :: Int -> [Date]
|
||||
function lastSundaysOfYear(y) {
|
||||
return lastWeekDaysOfYear(y, days.sunday);
|
||||
}
|
||||
|
||||
// lastWeekDaysOfYear :: Int -> Int -> [Date]
|
||||
function lastWeekDaysOfYear(y, iWeekDay) {
|
||||
return [
|
||||
31,
|
||||
0 === y % 4 && 0 !== y % 100 || 0 === y % 400 ? 29 : 28,
|
||||
31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
]
|
||||
.map(function (d, m) {
|
||||
var dte = new Date(Date.UTC(y, m, d));
|
||||
|
||||
return new Date(Date.UTC(
|
||||
y, m, d - (
|
||||
(dte.getDay() + (7 - iWeekDay)) % 7
|
||||
)
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
// isoDateString :: Date -> String
|
||||
function isoDateString(dte) {
|
||||
return dte.toISOString()
|
||||
.substr(0, 10);
|
||||
}
|
||||
|
||||
// range :: Int -> Int -> [Int]
|
||||
function range(m, n) {
|
||||
return Array.apply(null, Array(n - m + 1))
|
||||
.map(function (x, i) {
|
||||
return m + i;
|
||||
});
|
||||
}
|
||||
|
||||
// transpose :: [[a]] -> [[a]]
|
||||
function transpose(lst) {
|
||||
return lst[0].map(function (_, iCol) {
|
||||
return lst.map(function (row) {
|
||||
return row[iCol];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var days = {
|
||||
sunday: 0,
|
||||
monday: 1,
|
||||
tuesday: 2,
|
||||
wednesday: 3,
|
||||
thursday: 4,
|
||||
friday: 5,
|
||||
saturday: 6
|
||||
}
|
||||
|
||||
// TEST
|
||||
|
||||
return transpose(
|
||||
range(2012, 2016)
|
||||
.map(lastSundaysOfYear)
|
||||
)
|
||||
.map(function (row) {
|
||||
return row
|
||||
.map(isoDateString)
|
||||
.join('\t');
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
})();
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
(() => {
|
||||
'use strict'
|
||||
|
||||
// MAIN -----------------------------------------------
|
||||
// main :: IO ()
|
||||
const main = () =>
|
||||
console.log(unlines(
|
||||
map(
|
||||
compose(
|
||||
intercalate('\t'),
|
||||
map(isoDateString)
|
||||
)
|
||||
)(
|
||||
transpose(
|
||||
map(lastWeekDaysOfYear(days.sunday))(
|
||||
enumFromTo(2019)(2022)
|
||||
)
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
// WEEKDAYS -------------------------------------------
|
||||
|
||||
// lastWeekDaysOfYear :: Int -> Int -> [Date]
|
||||
const lastWeekDaysOfYear = iWeekDay =>
|
||||
y => map((d, m) =>
|
||||
new Date(Date.UTC(
|
||||
y, m, d - ((new Date(Date.UTC(y, m, d))
|
||||
.getDay() + (7 - iWeekDay)) % 7))))([
|
||||
31,
|
||||
0 === y % 4 && 0 !== y % 100 || 0 === y % 400 ? 29 : 28,
|
||||
31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
]);
|
||||
|
||||
const days = {
|
||||
sunday: 0,
|
||||
monday: 1,
|
||||
tuesday: 2,
|
||||
wednesday: 3,
|
||||
thursday: 4,
|
||||
friday: 5,
|
||||
saturday: 6
|
||||
};
|
||||
|
||||
// GENERIC FUNCTIONS-----------------------------------
|
||||
|
||||
// compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
|
||||
const compose = (...fs) =>
|
||||
x => fs.reduceRight((a, f) => f(a), x);
|
||||
|
||||
// enumFromTo :: Int -> Int -> [Int]
|
||||
const enumFromTo = m => n =>
|
||||
Array.from({
|
||||
length: 1 + n - m
|
||||
}, (_, i) => m + i);
|
||||
|
||||
// intercalate :: String -> [String] -> String
|
||||
const intercalate = s => xs =>
|
||||
xs.join(s);
|
||||
|
||||
// isoDateString :: Date -> String
|
||||
const isoDateString = dte =>
|
||||
dte.toISOString()
|
||||
.substr(0, 10);
|
||||
|
||||
// map :: (a -> b) -> [a] -> [b]
|
||||
const map = f => xs =>
|
||||
(Array.isArray(xs) ? (
|
||||
xs
|
||||
) : xs.split('')).map(f);
|
||||
|
||||
// If some of the rows are shorter than the following rows,
|
||||
// their elements are skipped:
|
||||
// > transpose [[10,11],[20],[],[30,31,32]] == [[10,20,30],[11,31],[32]]
|
||||
|
||||
// transpose :: [[a]] -> [[a]]
|
||||
const transpose = xss => {
|
||||
const go = xss =>
|
||||
0 < xss.length ? (() => {
|
||||
const
|
||||
h = xss[0],
|
||||
t = xss.slice(1);
|
||||
return 0 < h.length ? (
|
||||
[
|
||||
[h[0]].concat(t.reduce(
|
||||
(a, xs) => a.concat(
|
||||
0 < xs.length ? (
|
||||
[xs[0]]
|
||||
) : []
|
||||
),
|
||||
[]
|
||||
))
|
||||
].concat(go([h.slice(1)].concat(
|
||||
t.map(xs => xs.slice(1))
|
||||
)))
|
||||
) : go(t);
|
||||
})() : [];
|
||||
return go(xss);
|
||||
};
|
||||
|
||||
// unlines :: [String] -> String
|
||||
const unlines = xs => xs.join('\n');
|
||||
|
||||
// MAIN ---
|
||||
return main();
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue