diff options
author | Chinaman <root@chinaman> | 2011-09-06 19:47:58 +0200 |
---|---|---|
committer | Chinaman <root@chinaman> | 2011-09-06 19:47:58 +0200 |
commit | 108f3616e3f4958752d881192ef29e5fc4c2b045 (patch) | |
tree | 3c67478c852265219b72e6e1b05467d7065b7ba8 /shack | |
parent | b2d65500160bcdf7abb2bf985f7da582b810e25c (diff) | |
parent | c3bc5a6d16868c121aca780f3109155797b51d76 (diff) |
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'shack')
-rw-r--r-- | shack/Eselkalk/index.js | 57 | ||||
-rwxr-xr-x | shack/meinsack/index | 8 |
2 files changed, 65 insertions, 0 deletions
diff --git a/shack/Eselkalk/index.js b/shack/Eselkalk/index.js new file mode 100644 index 00000000..f64e0605 --- /dev/null +++ b/shack/Eselkalk/index.js @@ -0,0 +1,57 @@ +// +// node //shack/Eselkalk DATE +// +// where DATE ∈ [YYYY[-MM]], defaulting to the current YYYY-MM +// + +range = process.argv[2] || + JSON.parse(JSON.stringify(new Date())).slice(0, '....-..'.length) + +function dates(date) { + var year = date.getFullYear() + var month = date.getMonth() + + var i = new Date([year, (month < 9 ? '0' : '') + (month + 1)].join('-')) + + var days = [] + var next_day = 4; + for ( + ; i.getMonth() === month + ; i = new Date(+i + 24 * 60 * 60 * 1000)) { + if (i.getDay() === next_day) { + next_day = next_day === 3 ? 4 : 3 + if (next_day === 3) { + var next_4day = new Date(+i + 7 * 24 * 60 * 60 * 1000) + if (next_4day.getMonth() !== month) { + i = new Date(+i - 24 * 60 * 60 * 1000) + next_4day = 4 + } + } + days.push(new Date(+i + (20 * 60 + i.getTimezoneOffset()) * 60 * 1000)) + while (i.getDay() !== 0) { + i = new Date(+i + 24 * 60 * 60 * 1000) + } + } + } + + return days +} + + +result = [] + +// TODO if (/^....-..-..$/.test(range)) { ... } +if (/^....-..$/.test(range)) { + result = dates(new Date(range)) +} +else if (/^....$/.test(range)) { + ['01','02','03','04','05','06','07','08','09','10','11','12' + ].forEach(function (i) { + result = result.concat(dates(new Date([range, i].join('-')))) + }) +} +else { + throw new Error('You are made of stupid! ' + range) +} + +console.log(JSON.stringify(result, null, 2)) diff --git a/shack/meinsack/index b/shack/meinsack/index new file mode 100755 index 00000000..7d7147b2 --- /dev/null +++ b/shack/meinsack/index @@ -0,0 +1,8 @@ +#! /bin/sh +set -euf +cd $(dirname $(readlink -f $0))/../.. # cd // + +export plz=70327 +export str=Ulmer +export ort=Wangen +exec meinsack/index |