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
travis4all
committed
Aug 23, 2012
1 parent
812cc4c
commit fe398bd
Showing
3 changed files
with
139 additions
and
135 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- 0.6 | ||
- 0.8 |
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,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'); | ||
|
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,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; | ||
|