From fe398bdc80b7c5dc789008e99cee1a0814297e01 Mon Sep 17 00:00:00 2001 From: travis4all Date: Thu, 23 Aug 2012 06:18:44 +0000 Subject: [PATCH] :gem: Added travis.yml file :gem: --- .travis.yml | 4 + example/example.js | 24 ++--- index.js | 246 ++++++++++++++++++++++----------------------- 3 files changed, 139 insertions(+), 135 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8111245 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - 0.6 + - 0.8 \ No newline at end of file diff --git a/example/example.js b/example/example.js index ebf3352..a7addf7 100644 --- a/example/example.js +++ b/example/example.js @@ -1,12 +1,12 @@ -var http = require('http'); -var Jalali = require('../index.js'); - -http.createServer(function (req, res) { - res.writeHead(200, {'Content-Type': 'text/plain'}); - var today = Jalali.today('alphabetic'); - var str = 'امروز ' + Jalali.persianDay() + '، ' + today.d + ' ' + today.m + ' ' + today.y; - res.end(str); -}).listen(9999); - -console.log('now : go to http://localhost:9999'); - +var http = require('http'); +var Jalali = require('../index.js'); + +http.createServer(function (req, res) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + var today = Jalali.today('alphabetic'); + var str = 'امروز ' + Jalali.persianDay() + '، ' + today.d + ' ' + today.m + ' ' + today.y; + res.end(str); +}).listen(9999); + +console.log('now : go to http://localhost:9999'); + diff --git a/index.js b/index.js index 1f64765..95df2e4 100644 --- a/index.js +++ b/index.js @@ -1,127 +1,127 @@ -/* - * Jalali - Nodejs Jalali Calendar - * By : Alireza Ahmadi | http://alireza.es - * Special thanks to Ali Farhadi | http://farhadi.ir - */ -var JalaliDate = require('./lib/jalaliDate.js'); // By Ali Farhadi - -var Jalali = { - jmonths : ['فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند'], - - jdays : ['دوشنبه','سه شنبه','چهارشنبه','پنجشنبه','جمعه','شنبه','یکشنبه'], - - alphabetic : function(month){ - return this.jmonths[month - 1]; - }, - - persianDay : function(get){ - if(!get){ - var d = new Date(); - get = d.getDay(); - } - return this.jdays[get - 1]; - }, - - yesterday : function(style){ - var date = new Date(); - var jdate = { - year : parseInt(date.getFullYear()), - month : parseInt(date.getMonth() + 1), - day : parseInt(date.getDate()) - } - if(jdate.day == 1){ - if(jdate.month == 1){ - jdate.month = 12; - jdate.year = jdate.year - 1; - jdate.day = 29; - } - else{ - jdate.month = jdate.month - 1; - jdate.day = JalaliDate.j_days_in_month[jdate.month - 2]; - } - } - else{ - jdate.day = jdate.day - 1; - } - - jdate.result = JalaliDate.gregorianToJalali(jdate.year, jdate.month, jdate.day); - if(style){ - jdate.result[1] = this.alphabetic(jdate.result[1]); - } - return this.list(jdate.result); - }, - - today : function(style){ - var date = new Date(); - var jdate = { - year : parseInt(date.getFullYear()), - month : parseInt(date.getMonth() + 1), - day : parseInt(date.getDate()) - } - jdate.result = JalaliDate.gregorianToJalali(jdate.year, jdate.month, jdate.day); - if(style){ - jdate.result[1] = this.alphabetic(jdate.result[1]); - } - return this.list(jdate.result); - }, - - tomorrow : function(style){ - var date = new Date(); - var jdate = { - year : parseInt(date.getFullYear()), - month : parseInt(date.getMonth() + 1), - day : parseInt(date.getDate()) - } - if(jdate.day == JalaliDate.j_days_in_month[jdate.month - 1]){ - if(jdate.month == 12){ - jdate.month = 1; - jdate.year = jdate.year + 1; - jdate.day = 1; - } - else{ - jdate.month = jdate.month + 1; - jdate.day = 1; - } - } - else{ - jdate.day = jdate.day + 1; - } - - jdate.result = JalaliDate.gregorianToJalali(jdate.year, jdate.month, jdate.day); - if(style){ - jdate.result[1] = this.alphabetic(jdate.result[1]); - } - return this.list(jdate.result); - }, - +/* + * Jalali - Nodejs Jalali Calendar + * By : Alireza Ahmadi | http://alireza.es + * Special thanks to Ali Farhadi | http://farhadi.ir + */ +var JalaliDate = require('./lib/jalaliDate.js'); // By Ali Farhadi + +var Jalali = { + jmonths : ['فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند'], + + jdays : ['دوشنبه','سه شنبه','چهارشنبه','پنجشنبه','جمعه','شنبه','یکشنبه'], + + alphabetic : function(month){ + return this.jmonths[month - 1]; + }, + + persianDay : function(get){ + if(!get){ + var d = new Date(); + get = d.getDay(); + } + return this.jdays[get - 1]; + }, + + yesterday : function(style){ + var date = new Date(); + var jdate = { + year : parseInt(date.getFullYear()), + month : parseInt(date.getMonth() + 1), + day : parseInt(date.getDate()) + } + if(jdate.day == 1){ + if(jdate.month == 1){ + jdate.month = 12; + jdate.year = jdate.year - 1; + jdate.day = 29; + } + else{ + jdate.month = jdate.month - 1; + jdate.day = JalaliDate.j_days_in_month[jdate.month - 2]; + } + } + else{ + jdate.day = jdate.day - 1; + } + + jdate.result = JalaliDate.gregorianToJalali(jdate.year, jdate.month, jdate.day); + if(style){ + jdate.result[1] = this.alphabetic(jdate.result[1]); + } + return this.list(jdate.result); + }, + + today : function(style){ + var date = new Date(); + var jdate = { + year : parseInt(date.getFullYear()), + month : parseInt(date.getMonth() + 1), + day : parseInt(date.getDate()) + } + jdate.result = JalaliDate.gregorianToJalali(jdate.year, jdate.month, jdate.day); + if(style){ + jdate.result[1] = this.alphabetic(jdate.result[1]); + } + return this.list(jdate.result); + }, + + tomorrow : function(style){ + var date = new Date(); + var jdate = { + year : parseInt(date.getFullYear()), + month : parseInt(date.getMonth() + 1), + day : parseInt(date.getDate()) + } + if(jdate.day == JalaliDate.j_days_in_month[jdate.month - 1]){ + if(jdate.month == 12){ + jdate.month = 1; + jdate.year = jdate.year + 1; + jdate.day = 1; + } + else{ + jdate.month = jdate.month + 1; + jdate.day = 1; + } + } + else{ + jdate.day = jdate.day + 1; + } + + jdate.result = JalaliDate.gregorianToJalali(jdate.year, jdate.month, jdate.day); + if(style){ + jdate.result[1] = this.alphabetic(jdate.result[1]); + } + return this.list(jdate.result); + }, + convert : function(fyear,fmonth,fday,format,style){ - var jdate = { - year : fyear, - month : fmonth, - day : fday - } - var type = format || 'gj' ; - if(type == 'gj'){ - jdate.result = JalaliDate.gregorianToJalali(jdate.year, jdate.month, jdate.day); - if(style){ - jdate.result[1] = this.alphabetic(jdate.result[1]); - } - } - else if(type == 'jg'){ - jdate.result = JalaliDate.jalaliToGregorian(jdate.year, jdate.month, jdate.day); - } + var jdate = { + year : fyear, + month : fmonth, + day : fday + } + var type = format || 'gj' ; + if(type == 'gj'){ + jdate.result = JalaliDate.gregorianToJalali(jdate.year, jdate.month, jdate.day); + if(style){ + jdate.result[1] = this.alphabetic(jdate.result[1]); + } + } + else if(type == 'jg'){ + jdate.result = JalaliDate.jalaliToGregorian(jdate.year, jdate.month, jdate.day); + } return this.list(jdate.result); - }, - - list : function(get){ - var answer = { - y : get[0], - m : get[1], - d : get[2] - } - return answer; - } + }, + + list : function(get){ + var answer = { + y : get[0], + m : get[1], + d : get[2] + } + return answer; + } } - -module.exports = Jalali; + +module.exports = Jalali; \ No newline at end of file