Giter Club home page Giter Club logo

persiandate's Introduction

Persian Date

Javascript date library for parsing, validating, manipulating, and formatting Persian dates System.

from 1.0.0 persian date support gregorian calendar.

Inspired by momentjs

More info at wikipedia

npm version Bower version Coverage Status Travis-ci

Star Issue Fork

Install

npm install persian-date --save-dev
bower install persian-date --save-dev

Browser

<script src="node_modules/persian-date/dist/persian-date.js" type="text/javascript"></script>
<script type="text/javascript">
    new persianDate().format(); // "۱۳۹۶-۰۱-۱۱ ۲۳:۳۳:۲۷ ب ظ" (when i run in my console)  
</script>

Webpack

require('persian-date');

Calendar and locale

toCalendar

default: persian

available option: persian gregorian

from version 1.0.* persianDate have an option that allows developers to set calendar type of Date object.

you can change calendar type globally or only in specific object

if you want change calendar type globally:

persianDate.toCalendar('gregorian');
new persianDate([2017]).year(); // 2017
new persianDate([2017]).format('MMM'); // "ژانویه"

or only on instance:

new persianDate([1396]).toCalendar('gregorian').year(); // 2017

toLeapYearMode

default: algorithmic

available option: algorithmic, astronomical

There is two popular way to determining leap years for the Persian calendar.

  • astronomical: occur whenever that number of days elapsed between equinoxes at the reference meridian.

  • algorithmic: based on Behrooz-Birashk proposed algorithm.

After version 1.0.* persianDate support both algorithms and you can choose which algorithm use in your project. currently, we have support 2 type of leap year mode algorithmic, astronomical.

you can change it globally like this example

persianDate.toLeapYearMode('algorithmic')

or change it in you instance

new persianDate().toLeapYearMode('algorithmic')

toLeapYearMode only work when calendar type is persian, and doesnt any effect on gregorian calendar

toLocale

default: fa

available option: fa en

if you want change locale globally:

persianDate.toLocale('fa');
new persianDate([1396,6,17]).format(); // "۱۳۹۶-۰۶-۱۷ ۰۰:۰۰:۰۰ ق ظ"
new persianDate([1396,6,17]).format('dddd'); // "جمعه"
new persianDate([1396,6,17]).format('MMMM'); // "شهریور"

persianDate.toLocale('en');
new persianDate([1396,6,17]).format(); // "1396-06-17 00:00:00 AM"
new persianDate([1396,6,17]).format('dddd'); // "Friday"
new persianDate([1396,6,17]).format('MMMM'); // "Shahrivar"

or only on instance:

new persianDate([1396,6,17]).toLocale('fa').format(); // "۱۳۹۶-۰۶-۱۷ ۰۰:۰۰:۰۰ ق ظ"
new persianDate([1396,6,17]).toLocale('fa').format('dddd'); // "جمعه"
new persianDate([1396,6,17]).toLocale('fa').format('MMMM'); // "شهریور"

persianDate.toCalendar('gregorian');
new persianDate([1396,6,17]).toLocale('en').format(); // "1397-07-07 00:00:00 AM"
new persianDate([1396,6,17]).toLocale('en').format('dddd'); // "Friday"
new persianDate([1396,6,17]).toLocale('en').format('MMMM'); // "June"

after version 1.0.*, you must use toLocale instead formatPersian, for show persian or english digit.

Parse

Instead of modifying the native Date.prototype , persianDate creates a wrapper for the Date object. To get this wrapper object, simply call persianDate() with one of the supported input types.

Now

new persianDate();

To get the current date and time, just call persianDate() with no parameters.

var now = new persianDate();

This is essentially the same as calling new persianDate(new Date()) .

Unix Offset (milliseconds)

new persianDate(/* Number */);

Similar to new Date(Number), you can create a persianDate by passing an integer value representing the number of milliseconds since the Unix Epoch (Jan 1 1970 12AM UTC).

var day = new persianDate(1318781876406); // "۱۳۹۰-۰۷-۲۴ ۱۹:۴۷:۵۶ ب ظ"

Unix Timestamp (seconds)

persianDate.unix(/* Number */);

To create a persianDate from a Unix timestamp (seconds since the Unix Epoch), use persianDate.unix(Number)

var day = new persianDate.unix(1318781876); // "۱۳۹۰-۰۷-۲۴ ۱۹:۴۷:۵۶ ب ظ"

This is implemented as persianDate(timestamp * 1000) , so partial seconds in the input timestamp are included.

Date

new persianDate(new Date());

You can create a persianDate with a pre-existing native Javascript Date object.

var day = new Date(2011, 9, 16);
var dayWrapper = new persianDate(day); // "۱۳۹۰-۰۷-۲۴ ۰۰:۰۰:۰۰ ق ظ"

This is the fastest way to get a persianDate.js wrapper.

Array

['year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond']

new persianDate([1391, 12, 29, 12, 25, 25, 900]);

You can create a persianDate with an array of numbers that mirror the parameters passed to new Date() But As Persian Date Number Like [1393,2,22,11,22,30]

new persianDate([1393, 1, 14, 15,25, 50,125]); // "۱۳۹۳-۰۱-۱۴ ۱۵:۲۵:۵۰ ب ظ"

Any value past the year is optional, and will default to the lowest possible number.

new persianDate([1392]); // Farvardin 1st
new persianDate([1392, 6]); // Shahrivar 1st
new persianDate([1392, 6, 10]); // Shahrivar 10th

Note: from 1.0.* you can pass gregorian date array to create gregorian date object. for this functionality you must change date object calendar type by toCalendar('gregorian')

example:

persianDate.toCalendar('gregorian');
new persianDate([2017,2,2]).format(); // "۲۰۱۷-۰۲-۰۲ ۰۰:۰۰:۰۰ ق ظ"

ASP.NET JSON Date

new persianDate(String);

ASP.NET returns dates in JSON as /Date(1198908717056)/ or /Date(1198908717056-0700)/

If a string that matches this format is passed in, it will be parsed correctly.

new persianDate("/Date(1198908717056-0700)/"); //"۱۳۸۶-۱۰-۰۸ ۰۹:۴۱:۵۷ ق ظ"

PesianDate Clone

new persianDate(persianDate);

All persianDate are mutable. If you want a clone of a persianDate, you can do so explicitly or implicitly. Calling persianDate() on a persianDate will clone it.

var a = new persianDate([1392]);
var b = new persianDate(a);
a.year(1300);
b.year(); // 1392
var a = new persianDate([1392]);
var b = a.clone();
a.year(1300);
b.year(); // 1392

Get + Set

persainDate.js uses overloaded getters and setters. You may be familiar with this pattern from it's use in jQuery.

Calling these methods without parameters acts as a getter, and calling them with a parameter acts as a setter.

These map to the corresponding function on the native Date object.

new persianDate().seconds(30).valueOf() === new Date().setSeconds(30); // true
new persianDate().seconds() === new Date().getSeconds(); // true

Millisecond

new persianDate().millisecond(100);
new persianDate().millisecond(); // 100
new persianDate().milliseconds(100);
new persianDate().milliseconds(); // 100

Gets or sets the milliseconds.

Accepts numbers from 0 to 999. If the range is exceeded, it will bubble up to the seconds.

Second

new persianDate().second(10);
new persianDate().second(); // 10
new persianDate().seconds(10);
new persianDate().seconds(); // 10

Gets or sets the seconds.

Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the minutes.

Minute

new persianDate().minute(20);
new persianDate().minute(); // 20
new persianDate().minutes(20);
new persianDate().minutes(); // 20

Gets or sets the minutes.

Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the hours.

Hour

new persianDate().hour(12);
new persianDate().hour(); // 12
new persianDate().hours(12);
new persianDate().hours(); // 12

Gets or sets the hour.

Accepts numbers from 0 to 23. If the range is exceeded, it will bubble up to the day.

Date of Month

new persianDate().date(23);
new persianDate().date(); // 23
new persianDate().dates(23);
new persianDate().dates(); // 23

Gets or sets the day of the month.

Accepts numbers from 1 to 31. If the range is exceeded, it will bubble up to the months.

Note: persianDate#date is for the date of the month, and persianDate#day is for the day of the week.

Year

new persianDate().year(1390);
new persianDate().year(); // 1390
new persianDate().years(1390);
new persianDate().years(); // 1390

Gets or sets the year.

Accepts numbers from -270,000 to 270,000.

Day of Week

new persianDate().day(); // Number
new persianDate().days(); // Number

Gets the day of the week.

Note: persianDate#date is for the date of the month, and persianDate#day is for the day of the week.

Manipulate

Once you have a PersianDate , you may want to manipulate it in some way. There are a number of methods to help with this.

persianDate.js uses the fluent interface pattern, also known as method chaining. This allows you to do crazy things like the following.

new persianDate().add('days', 7).subtract('months', 1).year(2009).hours(0).minutes(0).seconds(0);

Note: It should be noted that persianDates are mutable. Calling any of the manipulation methods will change the original persianDate.

If you want to create a copy and manipulate it, you should use persianDate#clone before manipulating the persianDate.

Add

new persianDate().add(String, Number);

Mutates the original persianDate by adding time.

This is a pretty robust function for adding time to an existing persianDate. To add time, pass the key of what time you want to add, and the amount you want to add.

new persianDate().add('days', 7);

There are some shorthand keys as well if you're into that whole brevity thing.

new persianDate().add('d', 7);
Key Alternate Shorthand
years year y
months month M
weeks week w
days day d
hours hour h
minutes minute m
seconds second s
milliseconds millisecond ms

If you want to add multiple different keys at the same time, you can pass them in as an object literal.

new persianDate().add('days', 7).add('months', 1); // with chaining

There are no upper limits for the amounts, so you can overload any of the parameters.

new persianDate().add('milliseconds', 1000000); // a million milliseconds
new persianDate().add('days', 360); // 360 days

Subtract

new persianDate().subtract(String, Number);

Mutates the original persianDate by subtracting time.

This is exactly the same as persianDate#add , only instead of adding time, it subtracts time.

new persianDate().subtract('days', 7);

Start of Time

new persianDate().startOf(String);

Mutates the original persianDate by setting it to the start of a unit of time.

new persianDate().startOf('year');   // set to Farvardin 1st, 12:00 am this year
new persianDate().startOf('month');  // set to the first of this month, 12:00 am
new persianDate().startOf('week');   // set to the first day of this week, 12:00 am
new persianDate().startOf('day');    // set to 12:00 am today
new persianDate().startOf('hour');   // set to now, but with 0 mins, 0 secs, and 0 ms
new persianDate().startOf('minute'); // set to now, but with 0 seconds and 0 milliseconds
new persianDate().startOf('second'); // same as persianDate().milliseconds(0);

These shortcuts are essentially the same as the following.

new persianDate().startOf('year');
new persianDate().month(1).date(1).hours(0).minutes(0).seconds(0).milliseconds(0);
new persianDate().startOf('hour');
new persianDate().minutes(0).seconds(0).milliseconds(0)

End of Time

new persianDate().endOf(String);

Mutates the original persianDate by setting it to the end of a unit of time.

This is the same as persianDate#startOf , only instead of setting to the start of a unit of time, it sets to the end of a unit of time.

new persianDate().endOf("year"); // set the persianDate to 12-31 11:59:59.999 pm this year

Display

Once parsing and manipulation are done, you need some way to display the persianDate.

Format

new persianDate().format();
new persianDate().format('string');

This is the most robust display option. It takes a string of tokens and replaces them with their corresponding values.

new persianDate().format("dddd, MMMM DD YYYY, h:mm:ss a"); // "شنبه, فروردین ۱۲ ۱۳۹۶, ۵:۵۴:۱۱ ب ظ"
new persianDate().format("dddd, ha"); // "شنبه, ۵ب ظ"

This is the most robust display option. It takes a string of tokens and replaces them with their corresponding values.

Type Tocken Output
Month M ۱ ۲ ... ۱۱ ۱۲
MM ۰۱ ۰۲ ... ۱۱ ۱۲
MMM فرو ارد ... اسف
MMMM فروردین اردیبهشت ... اسفند
Day of month D ۱ ۲ ... ۳۰ ۳۱
DD ۰۱ ۰۲ ... ۳۰ ۳۱
Day of year DDD ۱ ۲ ... ۳۶۴ ۳۶۵
d ۰ ۱ ... ۵ ۶
dd ش ی ... ج
ddd شنبه یکشنبه ... جمعه
dddd انارام مانتره سپند ... اشتاد
Week of Year w ۱ ۲ ... ۵۲ ۵۳
ww ۰۱ ۰۲ ... ۵۲ ۵۳
Year YY ۶۶ ۹۱ ... ۹۸ ۳۰
YYYY ۱۳۶۶ ۱۳۹۱ ... ۱۳۹۸ ۱۴۰۱
AM/PM a "ق ظ", "ب ظ"
Hour H ۰ ۱ ... ۲۲ ۲۳
HH ۰۰ ۰۱ ... ۲۲ ۲۳
h ۱ ۲ ... ۱۱ ۱۲
hh ۰۱ ۰۲ ... ۱۱ ۱۲
Minute m ۰ ۱ ... ۵۸ ۵۹
mm ۰۰ ۰۱ ... ۵۸ ۵۹
Second s ۰ ۱ ... ۵۸ ۵۹
ss ۰۰ ۰۱ ... ۵۸ ۵۹
Unix Timestamp X 1360013296
Timezone Z -۰۴:۳۰ -۰۵:۰۰ ... +۰۴:۳۰ +۰۵:۰۰
ZZ -۰۴۳۰ -۰۵:۰۰ ... +۰۴:۳۰ +۰۵:۰۰

Long Date formats

Type Tocken Output
Time LT "۴:۱۵ ب ظ"
Month numeral, day of month, year L ۱۳۹۲/۰۲/۲۰
l ۳۹۲/۲/۲۰
Month name, day of month, year LL اردیبهشت ۲۰ ۱۳۹۲
ll ارد ۲۰ ۱۳۹۲
Month name, day of month, year, time LLL اردیبهشت ۱۳۹۲ ۲۰ ۴:۲۳ ب ظ
lll ارد ۱۳۹۲ ۲۰ ۴:۲۳ ب ظ
Month name, day of month, day of week, year, time LLLL جمعه ۲۰ اردیبهشت ۱۳۹۲ ۴:۲۵ ب ظ
llll ج ۲۰ ارد ۱۳۹۲ ۴:۲۷ ب ظ

Default format

ISO8601 format YYYY-MM-DDTHH:mm:ssZ "۱۳۹۱-۱۰-۰۴ ۱۱:۲۷:۵۳ ق ظ"

Format To Persian digit

Deprecated as 1.0.* instead use toLocale

By Default persianDate format, use Persian Number System, for engilsh number Set formatPersian Option as false

var d = new persianDate([1391]);
d.format(); //"۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ"
window.formatPersian = false;
d.format(); //"1391-01-01 00:00:00 AM"

Also you can set golbal config like this

window.formatPersian  = false;

Note: After Set Global config you can set config for every instance

var d = new persianDate([1391]);
d.format(); //"۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ"
window.formatPersian = false;
d.format(); //"1391-01-01 00:00:00 AM"
d.formatPersian = true;
d.format(); //"۱۳۹۱-۰۱-۰۱ ۰۰:۰۰:۰۰ ق ظ"

Difference

new persianDate().diff(PersianDate|String|Boolean);

Accept 3 argument, (ccmparable persianDate object, difference key, boolean value that make returned output float)

To get the difference in milliseconds, use persianDate#diff.

var a = new persianDate([1392, 1, 29]);
var b = new persianDate([1392, 1, 28]);
a.diff(b) // 86400000

To get the difference in another unit of measurement, pass that measurement as the second argument.

var a = new persianDate([1392, 1, 29]);
var b = new persianDate([1392,1, 28]);
a.diff(b, 'days'); // 1

The supported measurements are years, months, weeks, days, hours, minutes, and seconds. For ease of development, the singular forms are supported .

var a = new persianDate([1391, 1]);
var b = new persianDate([1392, 5]);
a.diff(b, 'years');
a.diff(b, 'years', true);

If the persianDate is later than the persianDate you are passing to persianDate.fn.diff , the return value will be negative.

var a = new persianDate();
var b = new persianDate().add('seconds', 1);
a.diff(b); // -1000
b.diff(a); // 1000

A easy way to think of this is by replacing .diff( with a minus operator.

a.diff(b);
b.diff(a);

Unix Offset (milliseconds)

new persianDate().valueOf();

persianDate#valueOf simply outputs the number of milliseconds since the Unix Epoch, just like Date#valueOf .

new persianDate(1318874398806).valueOf(); // 1318874398806
new persianDate(1318874398806).format(); // "۱۳۹۰-۰۷-۲۵ ۲۱:۲۹:۵۸ ب ظ"

To get a Unix timestamp (the number of seconds since the epoch) from a persianDate , use persianDate#unix .

Unix Timestamp (seconds)

new persianDate().unix();

persianDate#unix outputs a Unix timestamp (the of seconds since the Unix Epoch).

new persianDate(1318874398806).unix(); // 1318874398

This value is floored to the nearest second, and does not include a milliseconds component.

Timezone Offset

new persianDate().zone();

Get the timezone offset in minutes.

new persianDate().zone(); // (60, 120, 240, -270, etc.)

Days in Month

new persianDate().daysInMonth();

Get the number of days in the current month.

new persianDate([1392,1]).daysInMonth(); // 31
new persianDate([1392,8]).daysInMonth(); // 30
new persianDate([1392,12]).daysInMonth(); // 29
new persianDate([1391,12]).daysInMonth(); // 30

As Javascript Date

new persianDate().toDate();

To get the native Date object that persianDate.js wraps, use persianDate#toDate .

This will return the Date that the persianDate uses.

As Array

new persianDate().toArray();

This returns an array that mirrors the parameters from new persianDate() .

new persianDate().toArray(); // [1391, 1, 4, 14, 40, 16, 154];

Range Name

Helper method that return date range name like week days name, month names, month days names (specially in persian calendar).

persianDate.toLocale('fa').toCalendar('persian');

persianDate.rangeName().weekdays;
// ["شنبه", "یکشنبه", "دوشنبه", "سه شنبه", "چهار شنبه", "پنج‌شنبه", "جمعه"]

persianDate.rangeName().weekdaysMin;
// ["ش", "ی", "د", "س", "چ", "پ", "ج"]

persianDate.rangeName().months;
// ["فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند"]

persianDate.rangeName().monthsShort; 
// ["فرو", "ارد", "خرد", "تیر", "مرد", "شهر", "مهر", "آبا", "آذر", "دی", "بهم", "اسف"]

persianDate.rangeName().persianDaysName[0]; 
// "اورمزد"

Persian month day name wiki

Also You can get Gregorian calendar range names

persianDate.toCalendar('gregorian').rangeName().months;
// ["ژانویه", "فوریه", "مارس", "آوریل", "مه", "ژوئن", "ژوئیه", "اوت", "سپتامبر", "اکتبر", "نوامبر", "دسامبر"]

persianDate.toCalendar('gregorian').toLocale('en').rangeName().months;
// ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]


persianDate.toCalendar('gregorian').toLocale('en').rangeName().weekDayes;
// ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']

persianDate.toCalendar('gregorian').toLocale('en').rangeName().weekDayesShort;
// ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']

persianDate.toCalendar('gregorian').toLocale('en').rangeName().weekDayesMin;
// ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']

Query

Is Leap Year

new persianDate().isLeapYear();

persianDate#isLeapYear returns true if that year is a leap year, and false if it is not. base on object calendarType.

new persianDate([1391]).isLeapYear(); // true
new persianDate([1392]).isLeapYear(); // false
new persianDate([1393]).isLeapYear(); // false
new persianDate([1394]).isLeapYear(); // false
new persianDate([1395]).isLeapYear(); // true
new persianDate([1396]).isLeapYear(); // false

Is Daylight Saving Time

new persianDate().isDST();

persianDate#isDST checks if the current persianDate is in daylight savings time.

new persianDate([1396, 1, 1]).isDST(); // false
new persianDate([1396, 1, 2]).isDST(); // true
new persianDate([1396, 6, 30]).isDST(); // true
new persianDate([1396, 6, 31]).isDST(); // false

Based on Persian DST wiki

Is a PersianDat

var obj = new persianDate();

// options 1
new persianDate().isPersianDate(obj); // true

//option 2
persianDate.isPersianDate(obj);

To check if a variable is a persianDate object, use persianDate().isPersianDate() .

new persianDate().isPersianDate(); // false
new persianDate().isPersianDate(new Date()); // false
new persianDate().isPersianDate(new persianDate()); // true

Is Same Month

Check date object with given date object month similarity

// options 1
var a = new persianDate([1396,1,1]);
var b = new persianDate([1396,1,12]);
b.isSameMonth(a); // true

var a = new persianDate([1396,1,1]);
var b = new persianDate([1397,1,12]);
b.isSameMonth(a); // false

// options 2
var a = new persianDate([1396,1,1]);
var b = new persianDate([1396,1,12]);
persianDate.isSameMonth(a,b); // true

var a = new persianDate([1396,1,1]);
var b = new persianDate([1397,1,12]);
persianDate.isSameMonth(a,b); // false

Is Same Day

Check date object with given date object day similarity

// options 1
var a = new persianDate([1396,1,1]);
var b = new persianDate([1396,1,1]);
b.isSameDay(a); // true

var a = new persianDate([1396,1,1]);
var b = new persianDate([1396,2,1]);
b.isSameDay(a); // false

// options 2
var a = new persianDate([1396,1,12]);
var b = new persianDate([1396,1,12]);
persianDate.isSameDay(a,b); // true

var a = new persianDate([1396,1,12]);
var b = new persianDate([1397,1,12]);
persianDate.isSameDay(a,b); // false

license

Freely distributable under the terms of the MIT license.

persiandate's People

Contributors

babakhani avatar mort3za avatar pylover avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

persiandate's Issues

مشکل با 2 فروردین 1396

وقتی سال و ماه و روز 2 فروردین 1396 رو به عنوان پارامتر میفرستین ، تاریخ 1 فروردین رو برمیگیردونه

add and subtract

trying to add or subtract
persianDate.toCalendar('gregorian');
(new persianDate([2018,9,21])).add('day', 1).format();
returning 2018-09-21

Cannot find module 'persian-date'

Hello, I installed persian-date with npm but when I wanna use your module I get this error:
Error: Cannot find module 'persian-date'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object. (/home/........./start.js:3:19)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3

thanks in advance

گزارش خطا - mindate

با سلام و عرض تشکر و خسته نباشید
در بخشی از کد ها با خطایی مواجه شدم که خواستم گزارش بدم
زمانی که مقدار mindate تعیین میشه ماهی که در اون هستید از لیست ماه ها قابل انتخاب نیست
فرضا ما مقدار mindate رو برابر با ۱۵ شهریور میزاریم و از طریق نوارابزار به لیست ماه ها میریم ماه شهریور قابل انتخاب نیست
من با تغییر بخشی از کد شما مشکل رو رفع کردم

_checkMonthAccess: function (month) {
if (this.datepicker.state._filetredDate) {
var y = this.datepicker.state.view.year;
var monthUnix = new pDate([y, month]).unix() * 1000;
if (monthUnix >= this.datepicker.state.filterDate.start.unixDate &&
monthUnix <= this.datepicker.state.filterDate.end.unixDate
) {
return true;
} else {
return false;
}
}
else {
return this.datepicker.checkMonth(month);
}
},

تبدیل شد به

_checkMonthAccess: function (month) {
if (this.datepicker.state._filetredDate) {

        var y = this.datepicker.state.view.year;
        var min_y = this.datepicker.state.filterDate.start.year;
        var min_m = this.datepicker.state.filterDate.start.month;
        var max_y = this.datepicker.state.filterDate.end.year;
        var max_m = this.datepicker.state.filterDate.end.month;

        if ((min_y > y) || ((min_y == y) && (min_m > month)) || (max_y < y) || ((max_y == y) && (max_m < month)))
        {
            return false;
        }
        else
        {
            return true;        
        }        
    }
    else {
        return this.datepicker.checkMonth(month);
    }
},

مشکل در نمایش ساعت 12 بعد از ظهر

با سلام
اگر ساعت نمایشی بصورت 12.15 بعد از ظهر باشد به این صورت با فرمت LT نمایش داده می شود : 00:15 ب.ظ
که باید به این صورت باشد 12.15 ب.ظ
فقط در بازه زمانی صبح است که 00:15 دقیقه معنی دارد و برای 12 ظهر بعد بعد تا 13 باید خود عدد 12 نمایش داده شود و نه اینکه صفر شود.

problem with time 12:** pm

I'm using persian-date ver 1.0.3
when I set date in this form :
new persianDate([1367, 10, 4, 12, 10]).format('LLLL');

I expect to get this :
چهار دی ۱۳۶۷ ساعت ۱۲:۱۰ ب‌ظ
but it returns:
چهار دی ۱۳۶۷ ساعت ۰۰:۱۰ب‌ظ

please fix it, bro.
Thanks.

اضافه کردن تگ های اچ تی ام ال به ازای هر بار نیو کردن

سلام
ممنون از کامپوننت خوبتون!
برادر دیت پیکر خارجی هر چند بار هم که ازش نیو کنی با تگ های اچ تی ام ال اضافه شده در بار اول کار می کنه!
ولی این کامپوننت به ازای هر بار که یک شی ازش میسازی ،کد اچ تی ام ال رو به صفحه اضافه می کنه!
pdate

واین در جاهایی که به صورت داینامیک میخوام ازش استفاده کنم مشکل ساز میشه

dataInit: function (elem)
                {
                    
                    var myval = elem.value;
                    $(elem).pDatepicker(
                    {
                        format: 'YYYY/MM/DD',
                        autoClose: true
                    }
                    );
                    if (myval != "") {
                        var datearray = myval.split('/').map(function (item) {
                            return parseInt(item, 10);
                        });
                        $(elem).pDatepicker('setDate', datearray);
                    }

                   
                }

اگر من استفاده ناصحیح می کنم بفرمایید

Mistype in readme

There is a mistype in readme.md file in the Display section > Format subsection > table OR something like:


Display

Format
(here is a table containing available formats AND the mistype)


In the table, row 16 (including header) says:
YYY | ۱۳۶۶ ۱۳۹۱ ... ۱۳۹۸ ۱۴۰۱

which should be changed to:
YYYY | ۱۳۶۶ ۱۳۹۱ ... ۱۳۹۸ ۱۴۰۱

Wrong IsLeapYear result?

I've tested the library,
isLeapYear returns false for 1403 whiles 1403 is a leap year !!!

persianDate([1403,1,1]).isLeapYear()

Also, it returns true for 1404, whiles 1404 is not a leap year !!!

What's wrong with it?

status of the days between start and end?

Hi.
I want to show the dates between the days of start and end in a list.
How can I get the status of the days between start and end?
For guidance you will do. Thank you

wrong date client

سلام
یه سوال
اگه تاریخ سیستم کاربرغلط باشه تاریخ ها کامل غلط میشین
برای تصحیح این کار چیکار باید کرد؟

Bug - set time array.

problem with pDate([1396,1,2,0,10])
This array return: Sat Mar 22 2017 01:10:00 GMT+0430 (IRDT)
Acceptable returned vlue is: Sat Mar 22 2017 01:10:00 GMT+0430 (IRDT)

بازه زمانی

سلام
آیا راهی برای انتخاب بازه زمانی وجود دارد؟

مشکل در اضافه کردن ماه

وقتی به ماه آخر سال یک ماه اضافه می‌کنیم بجای ۲۹ روز ۳۰ روز بعد محاسبه می‌شه. مثلا وقتی تاریخ ۱/۱۲/۱۳۹۶ ایجاد بشه و با تابع add یک ماه اضافه بشه تاریخ ۲/۱/۱۳۹۷ تولید می‌شه.
(new persianDate([1396, 12, 1])).add('months', 1).format() --> 1397-01-02

Incorrect time conversion

HI!
I tested a particular timestamp using minified persianDate version 0.1.8;

timestamp is : 1498208777214

I did this : persianDate(1498208777214).toArray()
and the result was this array : [1396, 4, 0, 13, 36, 17, 214]

the 'day' was 0.

in the screenshot below it is shown that the original time is correct;

thanks : )

image

استفاده به صورت import

سلام
من می‌خوام که از فایل ها به
import persianDate form 'persian-date'`;
استفاده کنم. چطور میتونم این کار رو بکنم؟
به نظر شبیه به سایر کتابخانه ها نیست.

disable some dates

سلام باباخانی عزیز و ممنون بابت پلاگینی که وقت گذاشتی و توسعش دادی، ممنونتم و من دارم از این پلاگین تو یه پروژه mvc code first استفاده میکنم.
اگه بتونی امکان غیر فعال کردن روزها رو بهش اضافه کنی ، مثله اون چیزی که تو تقویم بوت استرپ هست دیگه عالی میشه، یعنی مثلا روزهایه جمعه و یا روزهایه تعطیل رسمی رو غیر فعال کنه کاربر به انتخاب خودش، اگه بشه که عالی و کامل میشه این پلاگین.
بازم ممنونتم بابت کاره خوبت

Add weeks not working

when i try to add weeks to date it wont work

        let date = new persianDate();
        console.log(date.format('DD/MM/YY'));
        let dateAdded = date.add('weeks',1);
        console.log(dateAdded.format('DD/MM/YY'));

output

۱۲/۰۶/۹۷
۱۲/۰۶/۹۷

مشکل با سی و یکمین روز ماه های میلادی

سلام
من دیروز که 31 آگوست بود تقویم رو تست می کردم کلا به هم ریخته بود
داخل مثال های لینک http://babakhani.github.io/PersianWebToolkit/beta/datepicker/example/
هم تست می کردم همه اش به هم ریخته بود مثلا ماه مهر رو نشون نمیداد

برای تست و صحت این موضوع تاریخ ویندوز را روی 31 آگوست یا اکتبر تنظیم کنید متوجه عرایض بنده میشید
ممنون از پیگیریتون

Javascript native date object zero-based month numbering is not considered!

Creating a persianDate of a pre-existing native Javascript Date object does not give the expected result:

var day = new Date(2018, 4, 5);
var dayWrapper = new persianDate(day).format('YYYY/MM/DD');  // actual: ۱۳۹۷/۰۲/۱۵
                                                             // expected: ۱۳۹۷/۰۱/۱۶

If we simply subtract 1 from month(4 -> 3) then the result is true:

var day = new Date(2018, 3, 5);
var dayWrapper = new persianDate(day).format('YYYY/MM/DD');  // actual: ۱۳۹۷/۰۱/۱۶
                                                             // expected: ۱۳۹۷/۰۱/۱۶

As Javascript Date object month numbering is zero-based, I think you should consider this in your calculations.

Tanx in Advance

fixPosition : جهت نمایش صحیح بروز رسانی کنید

fixPosition: function (self) {
if (!self._inlineView) {
var inputX = self.inputElem.offset().top;
var inputY = self.inputElem.offset().left;
var mainHeight = self.fullHeight(self.element.main);
if (self.position === "auto") {
var inputHeight = self.fullHeight(self.inputElem);
if(inputX - $(window).scrollTop() > mainHeight){
self.element.main.css({
top: (inputX - mainHeight) + 'px',
left: inputY + 'px'
});
}else{
self.element.main.css({
top: (inputX + inputHeight) + 'px',
left: inputY + 'px'
});
}
} else {
self.element.main.css({
top: (inputX + self.position[0]) + 'px',
left: (inputY + self.position[1]) + 'px'
});
}
}
return this;
}

Validate Date

How check if a string date is valid persian date or not?

Problem with installing

Installing using with Bower with this syntax
bower install persian-date --save-dev
but faced with this mesage at the end
bower cached https://github.com/babakhani/PersianDate.git#1.0.1
bower validate 1.0.1 against https://github.com/babakhani/PersianDate.git#*
bower ENOTFOUND Package persian-daete not found

Exactly this word , persian-daete ,Not a missspelling

مشکل در نسخه های قدیمی فایرفاکس

سلام
تو نسخه 64 بیتی 56.0.2 وقتی تاریخ 2 فروردین رو میدم معادل تاریخ میلادی 21 مارس رو بهم میده در صورتی که باید 22 مارس رو بهم بده
var t = new persianDate([1397,01,02]);
gDate => Date 2018-03-21T20:30:00.000Z

problem with safari

everything looks good in chrome but in safari something goes wrong!
NaN/NaN/NaN ساعت NaN:NaN

any ideas would be greatly appreciated

Problem in get day of week in format function

When use ddd and dddd in wednesday output result like this:

const date = new persianDate([1397, 06, 23]);
date.formatPersian = false;

console.log(date.toLocale('en').format('YYYYMMDD hh:mm ddd'); // 13970823 00:00 Thu
console.log(date.toLocale('en').format('YYYYMMDD hh:mm dddd'); // 13970823 00:00 Wednesday

in ddd day of week must be wed but is thu

عدم نمایش صحیح تاریخ برگشتی از سرور

سلام
وقتی که مقدار رشته تاریخ شمسی برگشتی از سرور در
MVC
به فیلد مورد نظر
Bind
میشه مقدار آن عوض میشه
مثلا مقدار برگشتی از سرور ۱۳۹۵/۰۸/۰۸ هست ولی در دیت پیکر ۷۷۴/۰۵/۱۷ نمایش داده میشه

<input asp-for="FromDate" class="persian-datepicker" type="text">

<script>
$('.persian-datepicker').persianDatepicker({
        format: 'YYYY/MM/DD',
        observer: true
    });
</script>

typings

Hi,
Thanks for your wonderful effort.
Is there any plan to provide .d.ts ?

مشکل با نسخه جدید

به نام خدا

سلام
نمی دونم در به روزرسانی چه اتفاقی افتاده که persianDate شناخته نمیشه. مشکلی با نسخه های قدیمی ندارم ولی هر زمان که به روزرسانی می کنم به این مشکل بر موخورم. من از این بسته برای انگولار 2 استفاده می کنم و با دستور زیر import می کنم
import '../../../../../node_modules/persian-date/dist/persian-date';
declare var persianDate;
ولی هر زمان که به روز می کنم به مشکل persianDate is no defiend بر می خورم

HELP

how to use Persian date package inside webpack?

I'm using laravel elixir and
require('../bower_components/persian-date/dist/0.1.8/persian-date-0.1.8');
works good but I get this error in browser
Duration is not defined

thnaks

مشکل هنگام رفرش کردن صفحه

وقتی صفحه رفرش میشه ، یه تاریخ اشتباه نشون میده مثلا ۷۷۷/۱۲/۵ ، اما اگه روی آدرس صفحه کلیک کنیم و کلید اینتر رو بزنیم درسته

این مشکل وقتی رخ میده که فرمت رو به این صورت ست میکنم
YYYY/MM/DD

Diff method always returns a positive value

Hello.
Diff method always returns a positive value regardless of input values, but in documentation you have said the result will be a negative value if a is less than b. I looked at the source code and found out in this line you are multiplying the output value by -1 if its negative.
Is it an intended behavior or a bug?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.