Skip to content

Commit

Permalink
ADDED fromDate,
Browse files Browse the repository at this point in the history
Better docs
  • Loading branch information
FatulM committed Jan 7, 2019
1 parent b3c8565 commit cbf5c6a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@

- CHANGED static methods
- CHANGED monthLength to getter

## 0.3.0

- ADDED fromDate constructor
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
# A Flutter package for using Jalali (Shamsi, Solar or Persian) date. You can convert Jalali and Georgian dates to each other.

Converted from Javascript library hosted on: [jalaali-js](https://github.com/jalaali/jalaali-js)
Converted from the popular Javascript library [jalaali-js](https://github.com/jalaali/jalaali-js).

Calendar conversion is based on the [algorithm provided by Kazimierz M. Borkowski](http://www.astro.uni.torun.pl/~kb/Papers/EMP/PersianC-EMP.htm) and has a very good performance.

## Usage

Add it to your pubspec.yaml file:

```yaml
dependencies:
shamsi_date: ^0.2.1
shamsi_date: ^0.3.0
```
`Jalali` class is used for Shamsi (Jalali or Persian) date and `Gregorian` class is used for Gregorian date.
They can be instantiated by using their constructor:
```
Jalali(year, month, day)
Gregorian(year, month, day)
```
`month` and `day` default to 1

You can convert `Jalali` date to `Gregorian` by using `toGregorian()` method and convert `Gregorian` to `Jalali` date by using `toJalali()` method.

You can check `Jalali` date validity by `isValid()` method.
And find month length by `monthLength` getter.
And check if the year is a leap year by `isLeapYear()` method.

You can also convert `DateTime` object directly to `Jalali` or `Gregorian` date by using
```
Jalali.fromDate(dateTime)
Gregorian.fromDate(dateTime)
```
Import and use it:
Here is an example:
```dart
import 'package:shamsi_date/shamsi_date.dart';
Expand All @@ -33,5 +55,9 @@ main() {
// find month length
print('1390/12 month length? ${Jalali(1390, 12).monthLength}');
final now = DateTime.now();
print('now is ${Gregorian.fromDate(now)} in Gregorian');
print('now is ${Jalali.fromDate(now)} in Jalali');
}
```
13 changes: 13 additions & 0 deletions lib/shamsi_date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Jalali {
1;
}

/// Create a Jalali date by using year, month and day
/// year and month default to 1
Jalali(this.year, [this.month = 1, this.day = 1]);

/// Converts the Julian Day number to a date in the Jalali calendar.
Expand Down Expand Up @@ -58,6 +60,11 @@ class Jalali {
return Jalali(jy, jm, jd);
}

/// Create a Jalali date by using [DateTime] object
factory Jalali.fromDate(DateTime dateTime) {
return Gregorian.fromDate(dateTime).toJalali();
}

/// Converts a Jalali date to Gregorian.
Gregorian toGregorian() {
return Gregorian.fromJulianDayNumber(julianDayNumber);
Expand Down Expand Up @@ -120,6 +127,8 @@ class Gregorian {
return d;
}

/// Create a Gregorian date by using year, month and day
/// year and month default to 1
Gregorian(this.year, [this.month = 1, this.day = 1]);

/// Calculates Gregorian and Julian calendar dates from the Julian Day number
Expand All @@ -140,6 +149,10 @@ class Gregorian {
return Gregorian(gy, gm, gd);
}

/// Create a Gregorian date by using [DateTime] object
Gregorian.fromDate(DateTime dateTime)
: this(dateTime.year, dateTime.month, dateTime.day);

/// Converts a Gregorian date to Jalali.
Jalali toJalali() {
return Jalali.fromJulianDayNumber(julianDayNumber);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: shamsi_date
description: A Flutter package for using Jalali (Shamsi, Solar or Persian) date. You can convert Jalali and Georgian dates to each other.
version: 0.2.1
version: 0.3.0
homepage: https://github.com/FatulM/shamsi_date
author: Amirreza Madani <[email protected]>

Expand Down

0 comments on commit cbf5c6a

Please sign in to comment.