nanakshahi 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.gitlab-ci.yml +11 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +48 -0
- data/config/locales/pa.yml +47 -0
- data/lib/nanakshahi.rb +123 -0
- data/lib/nanakshahi/date.rb +10 -0
- data/lib/nanakshahi/grid.rb +28 -0
- data/lib/nanakshahi/utils.rb +34 -0
- data/lib/nanakshahi/version.rb +3 -0
- data/nanakshahi.gemspec +43 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fab6bdd67c7901cb3cee987cb4252b8881167d41bbe56edfa5399e05357b6a44
|
4
|
+
data.tar.gz: 79c9fdc1e17650dfe11ff1052dac116a05e7afebf835dc5ca39a7b61ecb7fe65
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25dc96ed703588be6103ce0d79a21d770a8cf63c70c4d82ba280cc2eff358f4297d7aa1ce1ddb1049cc6bf513b603b1c4038125102e15e3d5ebc7bda4aced57d
|
7
|
+
data.tar.gz: 4979c1a0b399877b0190e7b75250e2509f71b2d096b36f77e605c79bbecf92a6ed28f617bb88d8ea3a14b0ccedf1c58df6c3093d7c4c2cfd890f6973c2970dbd
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nanakshahi (0.1.1)
|
5
|
+
i18n (~> 1.1, >= 1.1.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
concurrent-ruby (1.1.4)
|
11
|
+
i18n (1.5.1)
|
12
|
+
concurrent-ruby (~> 1.0)
|
13
|
+
minitest (5.11.3)
|
14
|
+
rake (10.5.0)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
bundler (~> 1.17)
|
21
|
+
minitest (~> 5.0)
|
22
|
+
nanakshahi!
|
23
|
+
rake (~> 10.0)
|
24
|
+
|
25
|
+
BUNDLED WITH
|
26
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Arvinder Singh
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# ਨਾਨਕਸ਼ਾਹੀ (Nanakshahi)
|
2
|
+
|
3
|
+
ਨਾਨਕਸ਼ਾਹੀ ਇੱਕ ਰੂਬੀ ਪਰੋਗਰਾਮਿੰਗ ਭਾਸ਼ਾ ਚ ਲਿਖਿਆ ਗਿਆ gem ਹੈ ਜੋ ਕਿ [ਪਾਲ ਸਿੰਘ ਪੁਰੇਵਾਲ](http://purewal.biz/) ਦੁਆਰਾ ਲਿਖੇ ਗਏ [ਮੂਲ ਨਾਨਕਸ਼ਾਹੀ ਕਲੰਡਰ]((http://www.purewal.biz/Gurbani_and_Nanakshahi_Calendar.pdf) ਤੇ ਅਧਾਰਿਤ ਹੈ।
|
4
|
+
|
5
|
+
ਇਹ ਆਮ/ਗਰਿਗੋਰੀਅਨ ਕਲੰਡਰ ਦੀਆਂ ਤਰੀਕਾਂ ਤੋਂ ਨਾਨਕਸ਼ਾਹੀ ਤੇ ਵਾਪਸ ਬਦਲਣ ਦੇ ਤਰੀਕੇ ਮੁਹੱੲੀਆ ਕਰਵਾਉਂਦਾ ਹੈ। ਤੁਸੀਂ ਇਸ ਨੂੰ ਕਿਸੇ ਵੀ ਰੂਬੀ ਪਰੋਗਰਾਮ ਵਿੱਚ ਨਾਨਕਸ਼ਾਹੀ ਤਰੀਕਾਂ ਵਰਤਣ ਲੲੀ ਵਰਤ ਸਕਦੇ ਹੋ।
|
6
|
+
|
7
|
+
Nanakshahi is a ruby gem for Nanakshahi Calendar based on the [original work](http://www.purewal.biz/Gurbani_and_Nanakshahi_Calendar.pdf) by [Pal Singh Purewal](http://purewal.biz/).
|
8
|
+
|
9
|
+
It provides helper methods to convert a Gregorian or Common Era(CE) date into Nanakshahi date and vice versa. You can use it to enable Nankshahi dates in any of your applications.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'nanakshahi'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install nanakshahi
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
To start using Nanakshahi gem
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'nanakshahi'
|
33
|
+
```
|
34
|
+
|
35
|
+
### Create a Nanakshahi date object
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
date = Nanakshahi.new # Creates an object with 1 Chet, Nanakshahi
|
39
|
+
date = Nanakshahi.new(550)
|
40
|
+
date = Nanakshahi.new(550, 10)
|
41
|
+
date = Nanakshahi.new(550, 10, 5)
|
42
|
+
```
|
43
|
+
|
44
|
+
### Using common calendar/gregorian date
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
date = Nanakshahi.from_gregorian(2019,1,8)
|
48
|
+
```
|
49
|
+
|
50
|
+
### Nanakshahi date today
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
date = Nanakshahi.today
|
54
|
+
```
|
55
|
+
|
56
|
+
### Converting date object to Nanakshahi
|
57
|
+
|
58
|
+
Nankshahi gem monkey-patches `Date` class to provide it `to_nanakshahi` method
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
date = Date.new(2019-2-18)
|
62
|
+
p date.to_nanakshahi
|
63
|
+
```
|
64
|
+
|
65
|
+
### Printing Nanakshahi date
|
66
|
+
|
67
|
+
`to_s` method prints Nanakshahi date either Nanakshahi or Dhundkaal suffix (pre-Guru Nanak). To take care of 0 year correction, like gregorian, it is assumed that 1 Dhundkaal precedes 1 Nanakshahi when printed with suffix.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
date = Nanakshahi.new(1400-2-18)
|
71
|
+
puts date
|
72
|
+
```
|
73
|
+
|
74
|
+
### To Gurmukhi
|
75
|
+
|
76
|
+
`to_gurmukhi` prints the date in Gurmukhi characters, complete with Gurmukhi numerals.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
date = Nanakshahi.new(1400-2-18)
|
80
|
+
puts date.to_gurmukhi
|
81
|
+
```
|
82
|
+
|
83
|
+
For a complete list of all the methods, check out the documentation.
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/punjab/nanakshahi.
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nanakshahi"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
en:
|
2
|
+
nanakshahi_months:
|
3
|
+
-
|
4
|
+
- Chet
|
5
|
+
- Vaisakh
|
6
|
+
- Jeth
|
7
|
+
- Harh
|
8
|
+
- Sawan
|
9
|
+
- Bhadon
|
10
|
+
- Asu
|
11
|
+
- Katik
|
12
|
+
- Maghar
|
13
|
+
- Poh
|
14
|
+
- Magh
|
15
|
+
- Phagun
|
16
|
+
digits:
|
17
|
+
- 0
|
18
|
+
- 1
|
19
|
+
- 2
|
20
|
+
- 3
|
21
|
+
- 4
|
22
|
+
- 5
|
23
|
+
- 6
|
24
|
+
- 7
|
25
|
+
- 8
|
26
|
+
- 9
|
27
|
+
day_names:
|
28
|
+
- Sunday
|
29
|
+
- Monday
|
30
|
+
- Tuesday
|
31
|
+
- Wednesday
|
32
|
+
- Thursday
|
33
|
+
- Friday
|
34
|
+
- Saturday
|
35
|
+
month_names:
|
36
|
+
-
|
37
|
+
- January
|
38
|
+
- February
|
39
|
+
- March
|
40
|
+
- April
|
41
|
+
- May
|
42
|
+
- June
|
43
|
+
- July
|
44
|
+
- August
|
45
|
+
- September
|
46
|
+
- October
|
47
|
+
- November
|
48
|
+
- December
|
@@ -0,0 +1,47 @@
|
|
1
|
+
pa:
|
2
|
+
nanakshahi_months:
|
3
|
+
-
|
4
|
+
- ਚੇਤ
|
5
|
+
- ਵੈਸਾਖ
|
6
|
+
- ਜੇਠ
|
7
|
+
- ਹਾੜ
|
8
|
+
- ਸਾਵਣ
|
9
|
+
- ਭਾਦੋਂ
|
10
|
+
- ਅੱਸੂ
|
11
|
+
- ਕੱਤਕ
|
12
|
+
- ਮੱਘਰ
|
13
|
+
- ਪੋਹ
|
14
|
+
- ਮਾਘ
|
15
|
+
- ਫੱਗਣ
|
16
|
+
digits:
|
17
|
+
- ੦
|
18
|
+
- ੧
|
19
|
+
- ੨
|
20
|
+
- ੩
|
21
|
+
- ੪
|
22
|
+
- ੫
|
23
|
+
- ੬
|
24
|
+
- ੭
|
25
|
+
- ੮
|
26
|
+
- ੯
|
27
|
+
day_names:
|
28
|
+
- ਐਤਵਾਰ
|
29
|
+
- ਸੋਮਵਾਰ
|
30
|
+
- ਮੰਗਲਵਾਰ
|
31
|
+
- ਬੁੱਧਵਾਰ
|
32
|
+
- ਵੀਰਵਾਰ
|
33
|
+
- ਸ਼ੁੱਕਰਵਾਰ
|
34
|
+
- ਸ਼ਨਿੱਚਰਵਾਰ
|
35
|
+
month_names:
|
36
|
+
- ਜਨਵਰੀ
|
37
|
+
- ਫ਼ਰਵਰੀ
|
38
|
+
- ਮਾਰਚ
|
39
|
+
- ਅਪ੍ਰੈਲ
|
40
|
+
- ਮਈ
|
41
|
+
- ਜੂਨ
|
42
|
+
- ਜੁਲਾਈ
|
43
|
+
- ਅਗਸਤ
|
44
|
+
- ਸਤੰਬਰ
|
45
|
+
- ਅਕਤੂਬਰ
|
46
|
+
- ਨਵੰਬਰ
|
47
|
+
- ਦਸੰਬਰ
|
data/lib/nanakshahi.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require "date"
|
2
|
+
require "i18n"
|
3
|
+
I18n.load_path << Dir[File.expand_path("config/locales") + "/*.yml"]
|
4
|
+
require "nanakshahi/version"
|
5
|
+
require "nanakshahi/grid"
|
6
|
+
require "nanakshahi/utils"
|
7
|
+
require "nanakshahi/date"
|
8
|
+
|
9
|
+
# Nanakshahi Calendar date based on research by Pal Singh Purewal
|
10
|
+
# @author Arvinder Singh
|
11
|
+
# @see http://panjabilab.com Panjabi Lab
|
12
|
+
# @since 0.1.0
|
13
|
+
# @attr_reader [Integer] year Year part of Nanakshahi date object
|
14
|
+
# @attr_reader [Integer] month Month part of Nanakshahi date object
|
15
|
+
# @attr_reader [Integer] day Day part of Nanakshahi date object
|
16
|
+
class Nanakshahi
|
17
|
+
include Comparable
|
18
|
+
extend Utils
|
19
|
+
extend Grid
|
20
|
+
|
21
|
+
# Returns today as a Nanakshahi date
|
22
|
+
def self.today
|
23
|
+
Date.today.to_nanakshahi
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_reader :year, :month, :day
|
27
|
+
|
28
|
+
# Creates new instance of Nanakshahi
|
29
|
+
#
|
30
|
+
# @param [Integer] year Year part of Nanakshahi date
|
31
|
+
# @param [Integer] month Month part of Nanakshahi date
|
32
|
+
# @param [Integer] day Day part of Nanakshahi date
|
33
|
+
def initialize(year = 1, month = 1, day = 1)
|
34
|
+
@day = day
|
35
|
+
@month = month
|
36
|
+
@year = year
|
37
|
+
end
|
38
|
+
|
39
|
+
# Converts Nanakshahi to Gregorian date
|
40
|
+
#
|
41
|
+
# @return [Date] Converts nanakshahi into corresponding gregorian# as Date object
|
42
|
+
def to_gregorian
|
43
|
+
last_nmonth_of_gyear = 10 # ਪੋਹ
|
44
|
+
last_nday_of_gyear = 18 # ੧੮
|
45
|
+
|
46
|
+
if month <= last_nmonth_of_gyear && day <= last_nday_of_gyear
|
47
|
+
gyear = year + 1468
|
48
|
+
else
|
49
|
+
gyear = year + 1469
|
50
|
+
end
|
51
|
+
|
52
|
+
nanakshahi_months = self.class.date_grid(gyear)
|
53
|
+
nanakshahi_months[month - 1][day - 1]
|
54
|
+
end
|
55
|
+
|
56
|
+
# String representation of Nanakshahi object
|
57
|
+
#
|
58
|
+
# @return [String] String representation of Nanakshahi
|
59
|
+
def to_s
|
60
|
+
era = year < 1 ? :Dhundkaal : :Nanakshahi
|
61
|
+
"#{day} #{I18n.t(:nanakshahi_months)[month]}, #{year_zero_correction(year)} #{era}"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Gurmukhi String representation of Nanakshahi object
|
65
|
+
#
|
66
|
+
# @return [String] Gurmukhi String representation of Nanakshahi
|
67
|
+
def to_gurmukhi
|
68
|
+
era = year < 1 ? :ਧੁੰਦਕਾਲ : :ਨਾਨਕਸ਼ਾਹੀ
|
69
|
+
"#{panjabi_numerals(day)} #{I18n.t(:nanakshahi_months, locale: :pa)[month]}, #{panjabi_numerals(year_zero_correction(year))} #{era}"
|
70
|
+
end
|
71
|
+
|
72
|
+
# Checks Nanakshahi leap year
|
73
|
+
#
|
74
|
+
# @return [Boolean] True if Nanakshahi year's Phagun has 31 days
|
75
|
+
def leap?
|
76
|
+
self.to_gregorian.leap?
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
|
81
|
+
# Implementation of spaceship operator to enable comparision
|
82
|
+
#
|
83
|
+
# @param [Nanakshahi] other Other object to compare with
|
84
|
+
# @return [Integer]
|
85
|
+
# nil if not a Nanakshahi object
|
86
|
+
# -1 if self < other
|
87
|
+
# 0 if self == other
|
88
|
+
# 1 if self > other
|
89
|
+
# @protected
|
90
|
+
def <=>(other)
|
91
|
+
return nil unless self.is_a?(Nanakshahi) && other.is_a?(Nanakshahi)
|
92
|
+
if ((self.year < other.year) ||
|
93
|
+
(self.year == other.year && self.month < other.month) ||
|
94
|
+
(self.year == other.year && self.month == other.month && self.day < other.day))
|
95
|
+
return -1
|
96
|
+
elsif self.year == other.year && self.month == other.month && self.day == other.day
|
97
|
+
return 0
|
98
|
+
else
|
99
|
+
return 1
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
# Considering no year 0 just like in Gregorian
|
106
|
+
# Year 1 Dhundkaal precedes 1 Nanakshahi
|
107
|
+
#
|
108
|
+
# @param [Integer] dyear Year
|
109
|
+
# @return [Integer] Year corrected for year 0
|
110
|
+
# @private
|
111
|
+
def year_zero_correction(dyear)
|
112
|
+
dyear < 1 ? dyear.abs + 1 : dyear.abs
|
113
|
+
end
|
114
|
+
|
115
|
+
# Converts english numerals to Gurmukhi
|
116
|
+
#
|
117
|
+
# @param [Integer] number A numeric usually date
|
118
|
+
# @return [String] Panjabi representation of date
|
119
|
+
# @private
|
120
|
+
def panjabi_numerals(number)
|
121
|
+
number.to_s.chars.map { |digit| I18n.t(:digits, locale: :pa)[digit.to_i] }.join
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Monkey Patch Ruby Date object
|
2
|
+
#
|
3
|
+
class Date
|
4
|
+
# Adds conversion of date object to Nanakshahi in Ruby Date class
|
5
|
+
#
|
6
|
+
# @return [Nanakshahi] returns corresponding Nanakshahi date object after conversion
|
7
|
+
def to_nanakshahi
|
8
|
+
Nanakshahi.from_gregorian(self.year, self.mon, self.day)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# A module for date_grid class method. To be extended in nanakshahi.rb
|
2
|
+
#
|
3
|
+
module Grid
|
4
|
+
# Class method that return a date grid
|
5
|
+
#
|
6
|
+
# The months follow the same index as MONTHS constant
|
7
|
+
# therefore although in Gregorian calendar Poh is first
|
8
|
+
# month of the nanakshahi year, it is at index 9
|
9
|
+
# sort of a merry-go-round.
|
10
|
+
# @param [Integer] gyear Nankshahi Year
|
11
|
+
# @return [Array] A grid of all dates for that Nanakshahi year
|
12
|
+
def date_grid(gyear)
|
13
|
+
[
|
14
|
+
(Date.new(gyear, 3, 14)..Date.new(gyear, 4, 13)).to_a,
|
15
|
+
(Date.new(gyear, 4, 14)..Date.new(gyear, 5, 14)).to_a,
|
16
|
+
(Date.new(gyear, 5, 15)..Date.new(gyear, 6, 14)).to_a,
|
17
|
+
(Date.new(gyear, 6, 15)..Date.new(gyear, 7, 15)).to_a,
|
18
|
+
(Date.new(gyear, 7, 16)..Date.new(gyear, 8, 15)).to_a,
|
19
|
+
(Date.new(gyear, 8, 16)..Date.new(gyear, 9, 14)).to_a,
|
20
|
+
(Date.new(gyear, 9, 15)..Date.new(gyear, 10, 14)).to_a,
|
21
|
+
(Date.new(gyear, 10, 15)..Date.new(gyear, 11, 13)).to_a,
|
22
|
+
(Date.new(gyear, 11, 14)..Date.new(gyear, 12, 13)).to_a,
|
23
|
+
(Date.new(gyear, 12, 14)..Date.new(gyear, 12, 31)).to_a.concat((Date.new(gyear, 1, 1)..Date.new(gyear, 1, 12)).to_a),
|
24
|
+
(Date.new(gyear, 1, 13)..Date.new(gyear, 2, 11)).to_a,
|
25
|
+
(Date.new(gyear, 2, 12)..Date.new(gyear, 3, 13)).to_a,
|
26
|
+
]
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "date"
|
2
|
+
|
3
|
+
# A module for utility class methods. To be extended in nanakshahi.rb
|
4
|
+
#
|
5
|
+
module Utils
|
6
|
+
NANAKSHAHI_EPOCH_IN_GREGORIAN = Date.new(1469, 3, 14)
|
7
|
+
# classs method Gregorian to Nanakshahi date
|
8
|
+
# @param [Integer] year Year part of gregorian Date
|
9
|
+
# @param [Integer] month Month part of gregorian Date
|
10
|
+
# @param [Integer] day Day part of gregorian Date
|
11
|
+
# @return [Nanakshahi] Nanakshahi date object
|
12
|
+
def from_gregorian(gyear, gmonth, gday)
|
13
|
+
# Start of time - 1 Chet, 1 Nanakshahi
|
14
|
+
gdate = Date.new(gyear, gmonth, gday)
|
15
|
+
|
16
|
+
# Before Chet 1, it is previous year in Nanakshahi
|
17
|
+
if (gmonth <= NANAKSHAHI_EPOCH_IN_GREGORIAN.month) && (gday < NANAKSHAHI_EPOCH_IN_GREGORIAN.day)
|
18
|
+
nyear = gyear - NANAKSHAHI_EPOCH_IN_GREGORIAN.year
|
19
|
+
else
|
20
|
+
nyear = gyear - (NANAKSHAHI_EPOCH_IN_GREGORIAN.year - 1)
|
21
|
+
end
|
22
|
+
|
23
|
+
nanakshahi_months = date_grid(gyear)
|
24
|
+
|
25
|
+
row = nanakshahi_months.detect { |month| month.include?(gdate) }
|
26
|
+
nday, nmonth = [row.index(gdate), nanakshahi_months.index(row)]
|
27
|
+
|
28
|
+
# Months are 1 indexed, arrays are 0 indexed
|
29
|
+
nmonth += 1
|
30
|
+
nday += 1
|
31
|
+
# Create a new Nanakshahi::Date object
|
32
|
+
self.new(nyear, nmonth, nday)
|
33
|
+
end
|
34
|
+
end
|
data/nanakshahi.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "nanakshahi/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nanakshahi"
|
8
|
+
spec.version = Nanakshahi::VERSION
|
9
|
+
spec.authors = ["Arvinder Singh"]
|
10
|
+
spec.email = ["a@arvinderkang.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Nanakshahi calendar by Pal Singh Purewal}
|
13
|
+
spec.description = %q{This gem returns is based on original nanakshahi calendar developed by Pal Singh Purewal}
|
14
|
+
spec.homepage = "https://panjabilab.com"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
|
22
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
24
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
25
|
+
# else
|
26
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
# "public gem pushes."
|
28
|
+
# end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
42
|
+
spec.add_runtime_dependency "i18n", "~> 1.5", ">= 1.5.1"
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nanakshahi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Arvinder Singh
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: i18n
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.5'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.5.1
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.5'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.5.1
|
75
|
+
description: This gem returns is based on original nanakshahi calendar developed by
|
76
|
+
Pal Singh Purewal
|
77
|
+
email:
|
78
|
+
- a@arvinderkang.com
|
79
|
+
executables: []
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- ".gitignore"
|
84
|
+
- ".gitlab-ci.yml"
|
85
|
+
- ".travis.yml"
|
86
|
+
- Gemfile
|
87
|
+
- Gemfile.lock
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bin/console
|
92
|
+
- bin/setup
|
93
|
+
- config/locales/en.yml
|
94
|
+
- config/locales/pa.yml
|
95
|
+
- lib/nanakshahi.rb
|
96
|
+
- lib/nanakshahi/date.rb
|
97
|
+
- lib/nanakshahi/grid.rb
|
98
|
+
- lib/nanakshahi/utils.rb
|
99
|
+
- lib/nanakshahi/version.rb
|
100
|
+
- nanakshahi.gemspec
|
101
|
+
homepage: https://panjabilab.com
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.7.8
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Nanakshahi calendar by Pal Singh Purewal
|
125
|
+
test_files: []
|