Skip to content

Commit

Permalink
jalaali time / fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
imans777 committed Aug 7, 2017
1 parent 9ad0a82 commit 4843f87
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 185 deletions.
374 changes: 193 additions & 181 deletions .idea/workspace.xml

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ module.exports = function(bot/*, botad*/) {
console.log(now);
console.log(now.format('ddd'));
console.log(now.format('YYYY/M/D'));

var meme = require('moment-jalaali');
var n = meme();
console.log(n);
console.log(n.format('ddd'));
console.log(meme(now).format('jYYYY/jM/jD k:m:s'));
});

bot.on('/test', function(msg) {
Expand Down Expand Up @@ -898,7 +904,7 @@ module.exports = function(bot/*, botad*/) {

var reserved_day = moment(now); //chosen day
var last_hour_of_now = moment(get_now()).hour(info.times[info.times.length - 1].hour).minute(30).second(0).millisecond(0);
if(last_hour_of_now.isSameOrBefore(reserved_day)) {
if(last_hour_of_now.isSameOrBefore(reserved_day) && last_hour_of_now.format('ddd') == day) {
reserved_day.add(6, 'd');
}
while (reserved_day.format('ddd') != day) {
Expand Down Expand Up @@ -926,6 +932,7 @@ module.exports = function(bot/*, botad*/) {

// console.log("This is the doc");
// console.log(doc);
//check Existence
if (doc) {
callback();
} else {
Expand Down Expand Up @@ -1094,7 +1101,7 @@ module.exports = function(bot/*, botad*/) {
var statement = encodeURI(messages.normal.res.intro + "\n");
statement += String("نام: ") + doc.name + encodeURI("\n");
statement += String("شماره تلفن: ") + doc.phone + encodeURI("\n");
statement += String("روز: ") + info.days[moment(doc.date).format('ddd')].label + String(" " + doc.short_date) + encodeURI("\n");
statement += String("روز: ") + info.days[moment(doc.date).format('ddd')].label + String(" " + doc.short_date_jalaali) + encodeURI("\n");
var hour = Number(moment(doc.date).format('k'));
statement += String("ساعت: ") + String(hour) + String(":30 - ") + String(hour + 1) + encodeURI("\n\n");
return statement;
Expand Down
2 changes: 1 addition & 1 deletion dict/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const info = {
time_reservation: 'تعیین وقت شوروم',
short_break_between_in_hour: 1,
delta_date_from_server: {
hour: 0, //7,
hour: 0, //8,
minute: 0, //30,
},
times: [
Expand Down
42 changes: 42 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"gravatar": "^1.6.0",
"hbs": "~4.0.1",
"moment": "^2.18.1",
"moment-jalaali": "^0.7.0",
"mongoose": "^4.9.3",
"morgan": "~1.8.1",
"passport": "^0.3.2",
Expand Down
7 changes: 7 additions & 0 deletions schema/reservation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var mongoose = require('mongoose');
var moment = require('moment');
var momentJ = require('moment-jalaali');
// momentJ.loadPersian({usePersianDigits: true});
var Schema = mongoose.Schema;
var info = require('../dict/info');

Expand Down Expand Up @@ -32,4 +34,9 @@ schema.virtual('short_date').get(function() {
return date;
});

schema.virtual('short_date_jalaali').get(function() {
var date = momentJ(this.date).format('jYYYY/jM/jD');
return date;
});

module.exports = mongoose.model('Reservation', schema);
2 changes: 1 addition & 1 deletion views/collections.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</td>
{{/unless}}
<td>{{this.hour}}</td>
<td>{{this.day}} - {{this.short_date}}</td>
<td>{{this.day}} - {{this.short_date_jalaali}}</td>
<td>{{this.phone}}</td>
<td>{{this.name}}</td>
</tr>
Expand Down

0 comments on commit 4843f87

Please sign in to comment.