-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0148d32
commit 8792355
Showing
5 changed files
with
59 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
.idea/ | ||
.idea/ | ||
warning |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,59 @@ | ||
#!/usr/bin/env node | ||
var argv = require('minimist')(process.argv.slice(2)); | ||
var Cal = require('./'); | ||
var table = require('text-table'); | ||
var _ = require('underscore'); | ||
var cal = new Cal(); | ||
var fs = require('fs'); | ||
var colors = require('colors'); | ||
|
||
if (argv.m && typeof argv.m == 'number') { | ||
cal.setMonth(argv.m); | ||
} | ||
else if (argv.y && typeof argv.y == 'number') { | ||
cal.setYear(argv.y); | ||
} | ||
fs.exists('./warning', function(exists) { | ||
if (!exists && !argv.i) { | ||
console.log('======================================'.yellow); | ||
console.log('| This overwrote the existing cal |'.yellow); | ||
console.log('| command type npm uninstall -g |'.yellow); | ||
console.log('| to undo this change. |'.yellow); | ||
console.log('======================================'.yellow); | ||
fs.writeFile('./warning'); | ||
} | ||
if (argv.m && typeof argv.m == 'number') { | ||
cal.setMonth(argv.m); | ||
} | ||
else if (argv.y && typeof argv.y == 'number') { | ||
cal.setYear(argv.y); | ||
} | ||
|
||
var days = cal.daysOfWeek.map(function(day) { | ||
return day.substring(0, 2); | ||
}); | ||
var firstDay = cal.getFirstDayOfMonth().substring(0, 2); | ||
var days = cal.daysOfWeek.map(function(day) { | ||
return day.substring(0, 2); | ||
}); | ||
var firstDay = cal.getFirstDayOfMonth().substring(0, 2); | ||
|
||
var header = table([[' ', cal.getMonth() + ' ' + cal.getYear(), ' ']], { align: [ 'c' ] }); | ||
var c = function() { | ||
var startDay = 0; | ||
var arr = []; | ||
for (var day = 1; day <= cal.getDaysThisMonth(); day++) { | ||
arr.push(day); | ||
} | ||
_.filter(days, function(day, index) { | ||
if (day == firstDay) { | ||
startDay = index; | ||
var header = table([[ ' ', cal.getMonth() + ' ' + cal.getYear(), ' ']], { align: [ 'c', 'c', 'c'] }); | ||
var c = function() { | ||
var startDay = 0; | ||
var arr = []; | ||
for (var day = 1; day <= cal.getDaysThisMonth(); day++) { | ||
arr.push(day); | ||
} | ||
}); | ||
for(var i =0;i<startDay;i++) { | ||
arr.unshift(' '); | ||
_.filter(days, function(day, index) { | ||
if (day == firstDay) { | ||
startDay = index; | ||
} | ||
}); | ||
for(var i =0;i<startDay;i++) { | ||
arr.unshift(' '); | ||
} | ||
var lists = _.groupBy(arr, function(element, index){ | ||
return Math.floor(index/7); | ||
}); | ||
return _.toArray(lists); | ||
}(); | ||
var calendar = [days]; | ||
for (var i in c) { | ||
calendar.push(c[i]); | ||
} | ||
var lists = _.groupBy(arr, function(element, index){ | ||
return Math.floor(index/7); | ||
}); | ||
return _.toArray(lists); | ||
}(); | ||
var calendar = [days]; | ||
for (var i in c) { | ||
calendar.push(c[i]); | ||
} | ||
calendar = table(calendar, { hsep: ' ', align: ['r', 'r', 'r', 'r', 'r', 'r', 'r'] }); | ||
calendar = table(calendar, { hsep: ' ', align: ['r', 'r', 'r', 'r', 'r', 'r', 'r'] }); | ||
|
||
console.log(header); | ||
console.log(calendar) | ||
console.log(header); | ||
console.log(calendar); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters