summaryrefslogtreecommitdiffstats
path: root/god/Eselkalk/index.js
diff options
context:
space:
mode:
authoreuer <root@euer.krebsco.de>2012-12-23 00:32:03 +0100
committereuer <root@euer.krebsco.de>2012-12-23 00:32:03 +0100
commit8de83da090cb7e430658291f01bca171213982b9 (patch)
tree4a0e04850d0d2c7f0175161e620cc0aef17e7bac /god/Eselkalk/index.js
parent149989cc4f217ccc10a3237292537d7cb5021a6a (diff)
//shack is now part of //god
all modules operate with the outside world somehow and can be considered god mudules. sorry for your inconvenience
Diffstat (limited to 'god/Eselkalk/index.js')
-rw-r--r--god/Eselkalk/index.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/god/Eselkalk/index.js b/god/Eselkalk/index.js
new file mode 100644
index 00000000..f64e0605
--- /dev/null
+++ b/god/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))