nepali_calendar 1.0.0
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 +12 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/README.md +33 -0
- data/Rakefile +6 -0
- data/lib/nepali_calendar/version.rb +3 -0
- data/lib/nepali_calendar.rb +203 -0
- data/nepali_calendar.gemspec +25 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8e46ef94c195c92423496b6892587e45e54c7b4
|
4
|
+
data.tar.gz: a7e8b250de3d34996c779f9ebaa856655a302bd0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3d6f19903b5c28a3a6f05b6914d510427ccac0142c3b8e87b5f1a83f606cc3a51918858d04de48f5ec66164dbe206ea0dbf4a5d51a1488711fac18c5818d977
|
7
|
+
data.tar.gz: ad4d5bf2c3bccd97908d8c788aa0f67670e538bee6ed83d436d221d20ea46f867df19f511729b92ed395b930a958dcb4ddda984e36cf5e7ce5a3790fcff5d9b5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Nepali Calendar
|
2
|
+
|
3
|
+
[](https://travis-ci.org/lalusaud/nepali_calendar)
|
4
|
+
|
5
|
+
A Ruby gem for generating Nepali Calendar (Bikram Sambat Calendar). You can also convert dates between BS and AD.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'nepali_calendar'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install nepali_calendar
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/lalusaud/nepali_calendar/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
require "nepali_calendar/version"
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
module NepaliCalendar
|
5
|
+
|
6
|
+
class Calendar
|
7
|
+
def self.bs
|
8
|
+
{
|
9
|
+
'2000' => [30,32,31,32,31,30,30,30,29,30,29,31],
|
10
|
+
'2001' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
11
|
+
'2002' => [31,31,32,32,31,30,30,29,30,29,30,30],
|
12
|
+
'2003' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
13
|
+
'2004' => [30,32,31,32,31,30,30,30,29,30,29,31],
|
14
|
+
'2005' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
15
|
+
'2006' => [31,31,32,32,31,30,30,29,30,29,30,30],
|
16
|
+
'2007' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
17
|
+
'2008' => [31,31,31,32,31,31,29,30,30,29,29,31],
|
18
|
+
'2009' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
19
|
+
'2010' => [31,31,32,32,31,30,30,29,30,29,30,30],
|
20
|
+
'2011' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
21
|
+
'2012' => [31,31,31,32,31,31,29,30,30,29,30,30],
|
22
|
+
'2013' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
23
|
+
'2014' => [31,31,32,32,31,30,30,29,30,29,30,30],
|
24
|
+
'2015' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
25
|
+
'2016' => [31,31,31,32,31,31,29,30,30,29,30,30],
|
26
|
+
'2017' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
27
|
+
'2018' => [31,32,31,32,31,30,30,29,30,29,30,30],
|
28
|
+
'2019' => [31,32,31,32,31,30,30,30,29,30,29,31],
|
29
|
+
'2020' => [31,31,31,32,31,31,30,29,30,29,30,30],
|
30
|
+
'2021' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
31
|
+
'2022' => [31,32,31,32,31,30,30,30,29,29,30,30],
|
32
|
+
'2023' => [31,32,31,32,31,30,30,30,29,30,29,31],
|
33
|
+
'2024' => [31,31,31,32,31,31,30,29,30,29,30,30],
|
34
|
+
'2025' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
35
|
+
'2026' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
36
|
+
'2027' => [30,32,31,32,31,30,30,30,29,30,29,31],
|
37
|
+
'2028' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
38
|
+
'2029' => [31,31,32,31,32,30,30,29,30,29,30,30],
|
39
|
+
'2030' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
40
|
+
'2031' => [30,32,31,32,31,30,30,30,29,30,29,31],
|
41
|
+
'2032' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
42
|
+
'2033' => [31,31,32,32,31,30,30,29,30,29,30,30],
|
43
|
+
'2034' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
44
|
+
'2035' => [30,32,31,32,31,31,29,30,30,29,29,31],
|
45
|
+
'2036' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
46
|
+
'2037' => [31,31,32,32,31,30,30,29,30,29,30,30],
|
47
|
+
'2038' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
48
|
+
'2039' => [31,31,31,32,31,31,29,30,30,29,30,30],
|
49
|
+
'2040' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
50
|
+
'2041' => [31,31,32,32,31,30,30,29,30,29,30,30],
|
51
|
+
'2042' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
52
|
+
'2043' => [31,31,31,32,31,31,29,30,30,29,30,30],
|
53
|
+
'2044' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
54
|
+
'2045' => [31,32,31,32,31,30,30,29,30,29,30,30],
|
55
|
+
'2046' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
56
|
+
'2047' => [31,31,31,32,31,31,30,29,30,29,30,30],
|
57
|
+
'2048' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
58
|
+
'2049' => [31,32,31,32,31,30,30,30,29,29,30,30],
|
59
|
+
'2050' => [31,32,31,32,31,30,30,30,29,30,29,31],
|
60
|
+
'2051' => [31,31,31,32,31,31,30,29,30,29,30,30],
|
61
|
+
'2052' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
62
|
+
'2053' => [31,32,31,32,31,30,30,30,29,29,30,30],
|
63
|
+
'2054' => [31,32,31,32,31,30,30,30,29,30,29,31],
|
64
|
+
'2055' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
65
|
+
'2056' => [31,31,32,31,32,30,30,29,30,29,30,30],
|
66
|
+
'2057' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
67
|
+
'2058' => [30,32,31,32,31,30,30,30,29,30,29,31],
|
68
|
+
'2059' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
69
|
+
'2060' => [31,31,32,32,31,30,30,29,30,29,30,30],
|
70
|
+
'2061' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
71
|
+
'2062' => [30,32,31,32,31,31,29,30,29,30,29,31],
|
72
|
+
'2063' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
73
|
+
'2064' => [31,31,32,32,31,30,30,29,30,29,30,30],
|
74
|
+
'2065' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
75
|
+
'2066' => [31,31,31,32,31,31,29,30,30,29,29,31],
|
76
|
+
'2067' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
77
|
+
'2068' => [31,31,32,32,31,30,30,29,30,29,30,30],
|
78
|
+
'2069' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
79
|
+
'2070' => [31,31,31,32,31,31,29,30,30,29,30,30],
|
80
|
+
'2071' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
81
|
+
'2072' => [31,32,31,32,31,30,30,29,30,29,30,30],
|
82
|
+
'2073' => [31,32,31,32,31,30,30,30,29,29,30,31],
|
83
|
+
'2074' => [31,31,31,32,31,31,30,29,30,29,30,30],
|
84
|
+
'2075' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
85
|
+
'2076' => [31,32,31,32,31,30,30,30,29,29,30,30],
|
86
|
+
'2077' => [31,32,31,32,31,30,30,30,29,30,29,31],
|
87
|
+
'2078' => [31,31,31,32,31,31,30,29,30,29,30,30],
|
88
|
+
'2079' => [31,31,32,31,31,31,30,29,30,29,30,30],
|
89
|
+
'2080' => [31,32,31,32,31,30,30,30,29,29,30,30],
|
90
|
+
'2081' => [31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
91
|
+
'2082' => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
92
|
+
'2083' => [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
93
|
+
'2084' => [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
94
|
+
'2085' => [31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
95
|
+
'2086' => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
96
|
+
'2087' => [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
|
97
|
+
'2088' => [30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
98
|
+
'2089' => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
99
|
+
'2090' => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30]
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.ad_to_bs(year, month, day)
|
104
|
+
date_ad = "#{year}/#{month}/#{day}"
|
105
|
+
return unless date_in_range?(date_ad, 'ad')
|
106
|
+
|
107
|
+
ref_day_nep = ref_date['ad_to_bs']['bs']
|
108
|
+
ref_day_eng = ref_date['ad_to_bs']['ad']
|
109
|
+
|
110
|
+
days = total_days(date_ad, ref_day_eng)
|
111
|
+
|
112
|
+
year, month, day = ref_day_nep.split('/').map(&:to_i)
|
113
|
+
i = year
|
114
|
+
j = month
|
115
|
+
|
116
|
+
while(days != 0) do
|
117
|
+
bs_month_days = bs["#{i}"][j-1]
|
118
|
+
day += 1
|
119
|
+
|
120
|
+
if day > bs_month_days
|
121
|
+
month += 1
|
122
|
+
day = 1
|
123
|
+
j += 1
|
124
|
+
end
|
125
|
+
|
126
|
+
if month > 12
|
127
|
+
year += 1
|
128
|
+
month = 1
|
129
|
+
end
|
130
|
+
|
131
|
+
if j > 12
|
132
|
+
j = 1
|
133
|
+
i += 1
|
134
|
+
end
|
135
|
+
|
136
|
+
days -= 1
|
137
|
+
end
|
138
|
+
|
139
|
+
Date.parse("#{year}/#{month}/#{day}")
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.bs_to_ad(year, month, day)
|
143
|
+
date_bs = "#{year}/#{month}/#{day}"
|
144
|
+
return unless date_in_range?(date_bs, 'bs')
|
145
|
+
|
146
|
+
ref_day_nep = ref_date['bs_to_ad']['bs']
|
147
|
+
ref_day_eng = ref_date['bs_to_ad']['ad']
|
148
|
+
|
149
|
+
ref_year, ref_month, ref_day = ref_day_nep.split('/').map(&:to_i)
|
150
|
+
k = ref_year
|
151
|
+
|
152
|
+
# No. of Days from year
|
153
|
+
i = 0
|
154
|
+
days = 0
|
155
|
+
j = 0
|
156
|
+
while(i < (year.to_i - ref_year)) do
|
157
|
+
i += 1
|
158
|
+
while(j < 12) do
|
159
|
+
days += bs["#{k}"][j]
|
160
|
+
j += 1
|
161
|
+
end
|
162
|
+
j = 0
|
163
|
+
k += 1
|
164
|
+
end
|
165
|
+
|
166
|
+
# No. of Days from month
|
167
|
+
j = 0
|
168
|
+
while(j < (month.to_i - 1)) do
|
169
|
+
days += bs["#{k}"][j]
|
170
|
+
j += 1
|
171
|
+
end
|
172
|
+
|
173
|
+
days += (day.to_i - ref_day)
|
174
|
+
Date.parse(ref_day_eng) + days
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.total_days(date_eng, reference_date)
|
178
|
+
(Date.parse(date_eng) - Date.parse(reference_date)).to_i
|
179
|
+
end
|
180
|
+
|
181
|
+
def self.date_in_range?(date, type)
|
182
|
+
year, month, day = date.split('/')
|
183
|
+
return unless Date.valid_date?(year.to_i, month.to_i, day.to_i)
|
184
|
+
|
185
|
+
case type
|
186
|
+
when 'ad'
|
187
|
+
Date.parse(date) > Date.parse(ref_date['ad_to_bs']['ad'])
|
188
|
+
when 'bs'
|
189
|
+
Date.parse(date) > Date.parse(ref_date['ad_to_bs']['bs'])
|
190
|
+
else
|
191
|
+
raise Exception.new("Invalid date type!")
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def self.ref_date
|
196
|
+
{
|
197
|
+
'bs_to_ad' => { 'bs' => '2000/01/01', 'ad' => '1943/04/14' },
|
198
|
+
'ad_to_bs' => { 'bs' => '2000/09/17', 'ad' => '1944/01/01'}
|
199
|
+
}
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nepali_calendar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nepali_calendar"
|
8
|
+
spec.version = NepaliCalendar::VERSION
|
9
|
+
spec.authors = ["Lal B. Saud"]
|
10
|
+
spec.email = ["lalusaud@gmail.com"]
|
11
|
+
spec.summary = %q{Generate Nepali Calendar (Bikram Sambat Calendar) and convert dates between BS & AD}
|
12
|
+
spec.description = %q{Nepali Calendar is a Ruby gem to generate Nepali Calendar. You can also use it to convert dates between BS and AD calendars.}
|
13
|
+
spec.homepage = "https://github.com/lalusaud/nepali_calendar"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.required_ruby_version = '>= 1.9.3'
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10.6"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nepali_calendar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lal B. Saud
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-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.10.6
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.10.6
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
description: Nepali Calendar is a Ruby gem to generate Nepali Calendar. You can also
|
56
|
+
use it to convert dates between BS and AD calendars.
|
57
|
+
email:
|
58
|
+
- lalusaud@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/nepali_calendar.rb
|
70
|
+
- lib/nepali_calendar/version.rb
|
71
|
+
- nepali_calendar.gemspec
|
72
|
+
homepage: https://github.com/lalusaud/nepali_calendar
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.9.3
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.8
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Generate Nepali Calendar (Bikram Sambat Calendar) and convert dates between
|
96
|
+
BS & AD
|
97
|
+
test_files: []
|