englishnepalidateconverter 0.0.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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +4 -0
- data/englishnepalidateconverter.gemspec +26 -0
- data/lib/englishnepalidateconverter/bs_date.rb +95 -0
- data/lib/englishnepalidateconverter/constants.rb +11 -0
- data/lib/englishnepalidateconverter/date_conversion.rb +129 -0
- data/lib/englishnepalidateconverter/version.rb +3 -0
- data/lib/englishnepalidateconverter.rb +11 -0
- data/spec/englishnepalidateconverter/date_conversion_spec.rb +80 -0
- data/spec/spec_helper.rb +7 -0
- metadata +101 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 308c2a1c028b81638ab28374f4e377796ea7afb4
|
|
4
|
+
data.tar.gz: 3105720d3e53ad953564252e2d06ccd96edccc67
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8f1b07696a3376593c1ae9c8f38a25c2f7d7c9339cda4df5dcea1f2e281f3573260fe504e7d64a991914847287e92f5da869ae92fe2725d45d287f6011a18fa6
|
|
7
|
+
data.tar.gz: fa7373cc480cc37d8cce0fcf288c489cb2304dccacf98a9874bc1c3ddca4e6a750c4e9d4e76e5a8e23db07ec4d6e8b14cd8008ccf2a47c4bb5641a3e110f9ad0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 dlamichhane
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# EnglishNepaliDateConverter
|
|
2
|
+
|
|
3
|
+
This EnglishNepaliDateConverter gem converts the AD to BS date between 01-01-1944 to 31-12-2033
|
|
4
|
+
and BS to AD date between 01-01-2000 to 30-12-2090
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Add this line to your application's Gemfile:
|
|
9
|
+
|
|
10
|
+
gem 'englishnepalidateconverter'
|
|
11
|
+
|
|
12
|
+
And then execute:
|
|
13
|
+
|
|
14
|
+
$ bundle
|
|
15
|
+
|
|
16
|
+
Or install it yourself as:
|
|
17
|
+
|
|
18
|
+
$ gem install englishnepalidateconverter
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
date = EnglishNepaliDateConverter::DateConversion.new
|
|
25
|
+
date.eng_to_nep(16,01,2014)
|
|
26
|
+
date.nep_to_eng(03,10,2070)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Contributing
|
|
30
|
+
|
|
31
|
+
1. Fork it
|
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'englishnepalidateconverter/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "englishnepalidateconverter"
|
|
8
|
+
spec.version = EnglishNepaliDateConverter::VERSION
|
|
9
|
+
spec.date = %{2014-01-16}
|
|
10
|
+
spec.authors = ["dlamichhane"]
|
|
11
|
+
spec.email = ["dlamichhane@hotmail.com"]
|
|
12
|
+
spec.description = %q{"Conversion of Gregorian calendar to Nepali Calendar"}
|
|
13
|
+
spec.summary = %q{Converts the English calendar date to Nepali calendar date}
|
|
14
|
+
spec.homepage = %q{https://github.com/dlamichhane/englishnepalidateconverter}
|
|
15
|
+
spec.licenses = ['MIT']
|
|
16
|
+
|
|
17
|
+
spec.add_development_dependency "rspec"
|
|
18
|
+
|
|
19
|
+
spec.files = `git ls-files`.split($/)
|
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
25
|
+
spec.add_development_dependency "rake"
|
|
26
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
module BsDate
|
|
2
|
+
BS_DATES = {
|
|
3
|
+
0 => [2000, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
4
|
+
1 => [2001, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
5
|
+
2 => [2002, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
6
|
+
3 => [2003, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
7
|
+
4 => [2004, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
8
|
+
5 => [2005, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
9
|
+
6 => [2006, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
10
|
+
7 => [2007, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
11
|
+
8 => [2008, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
12
|
+
9 => [2009, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
13
|
+
10 => [2010, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
14
|
+
11 => [2011, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
15
|
+
12 => [2012, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
16
|
+
13 => [2013, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
17
|
+
14 => [2014, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
18
|
+
15 => [2015, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
19
|
+
16 => [2016, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
20
|
+
17 => [2017, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
21
|
+
18 => [2018, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
22
|
+
19 => [2019, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
23
|
+
20 => [2020, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
24
|
+
21 => [2021, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
25
|
+
22 => [2022, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
26
|
+
23 => [2023, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
27
|
+
24 => [2024, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
28
|
+
25 => [2025, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
29
|
+
26 => [2026, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
30
|
+
27 => [2027, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
31
|
+
28 => [2028, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
32
|
+
29 => [2029, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
|
|
33
|
+
30 => [2030, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
34
|
+
31 => [2031, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
35
|
+
32 => [2032, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
36
|
+
33 => [2033, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
37
|
+
34 => [2034, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
38
|
+
35 => [2035, 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
39
|
+
36 => [2036, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
40
|
+
37 => [2037, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
41
|
+
38 => [2038, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
42
|
+
39 => [2039, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
43
|
+
40 => [2040, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
44
|
+
41 => [2041, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
45
|
+
42 => [2042, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
46
|
+
43 => [2043, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
47
|
+
44 => [2044, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
48
|
+
45 => [2045, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
49
|
+
46 => [2046, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
50
|
+
47 => [2047, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
51
|
+
48 => [2048, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
52
|
+
49 => [2049, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
53
|
+
50 => [2050, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
54
|
+
51 => [2051, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
55
|
+
52 => [2052, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
56
|
+
53 => [2053, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
57
|
+
54 => [2054, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
58
|
+
55 => [2055, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
59
|
+
56 => [2056, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
|
|
60
|
+
57 => [2057, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
61
|
+
58 => [2058, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
62
|
+
59 => [2059, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
63
|
+
60 => [2060, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
64
|
+
61 => [2061, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
65
|
+
62 => [2062, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31],
|
|
66
|
+
63 => [2063, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
67
|
+
64 => [2064, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
68
|
+
65 => [2065, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
69
|
+
66 => [2066, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
70
|
+
67 => [2067, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
71
|
+
68 => [2068, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
72
|
+
69 => [2069, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
73
|
+
70 => [2070, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
74
|
+
71 => [2071, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
75
|
+
72 => [2072, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
76
|
+
73 => [2073, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
77
|
+
74 => [2074, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
78
|
+
75 => [2075, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
79
|
+
76 => [2076, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
80
|
+
77 => [2077, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
81
|
+
78 => [2078, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
82
|
+
79 => [2079, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
83
|
+
80 => [2080, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
84
|
+
81 => [2081, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
85
|
+
82 => [2082, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
86
|
+
83 => [2083, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
87
|
+
84 => [2084, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
88
|
+
85 => [2085, 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
|
89
|
+
86 => [2086, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
90
|
+
87 => [2087, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
|
|
91
|
+
88 => [2088, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
|
92
|
+
89 => [2089, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
93
|
+
90 => [2090, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30]
|
|
94
|
+
}
|
|
95
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Error while using syntax in this format EN_DAY = {1: "Sunday", 2: "Monday", ...}
|
|
2
|
+
|
|
3
|
+
EN_DAY = {1 => "Sunday", 2 => "Monday", 3 => "Tuesday", 4 => "Wednesday", 5 => "Thursday", 6 => "Friday", 7 => "Saturday"}
|
|
4
|
+
|
|
5
|
+
NP_DAY = {1 => "Aaitabar", 2 => "Sombar", 3 => "Mangalbar", 4 => "Budhabar", 5 => "Bihibar", 6 => "Sukrabar", 7 => "Sanibar"}
|
|
6
|
+
|
|
7
|
+
NP_MONTH = {1 => "Baisakh", 2 => "Jestha", 3 => "Asar", 4 => "Shrawan", 5 => "Bhadra", 6 => "Ashoj",
|
|
8
|
+
7 => "Kartik", 8 => "Mangsir", 9 => "Poush", 10 => "Magh", 11 => "Falgun", 12 => "Chaitra"}
|
|
9
|
+
|
|
10
|
+
EN_MONTH = {1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June",
|
|
11
|
+
7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
module EnglishNepaliDateConverter
|
|
2
|
+
|
|
3
|
+
class DateConversion
|
|
4
|
+
attr_accessor :year, :month, :day_in_month, :day_of_week, :week_day, :month_number
|
|
5
|
+
|
|
6
|
+
def eng_to_nep(*args)
|
|
7
|
+
args.collect!{|i| i.to_i}
|
|
8
|
+
date_error = date_valid(args, "en")
|
|
9
|
+
|
|
10
|
+
unless date_error.empty?
|
|
11
|
+
return date_error.collect{ |error| "Enter appropriate #{error}"}
|
|
12
|
+
else
|
|
13
|
+
formatted_date = args[0].to_s + "-" + args[1].to_s + "-" + args[2].to_s
|
|
14
|
+
starting_date = DateTime.parse("01-01-1944").mjd.to_i
|
|
15
|
+
date_to_convert = DateTime.parse(formatted_date).mjd
|
|
16
|
+
en_total_days = date_to_convert - starting_date
|
|
17
|
+
year = np_start_year = 2000; month_number = np_start_month = 9; day_in_month = np_start_day = 17
|
|
18
|
+
|
|
19
|
+
starting_index_of_bs_date = 0; day_of_week = 7 # Saturday as Day 7 and Sunday as Day 1 of the week
|
|
20
|
+
|
|
21
|
+
while en_total_days !=0
|
|
22
|
+
day_in_month += 1; day_of_week += 1
|
|
23
|
+
(month_number += 1; day_in_month = 1; np_start_month += 1) if day_in_month > BsDate::BS_DATES[starting_index_of_bs_date][np_start_month]
|
|
24
|
+
day_of_week = 1 if day_of_week > 7
|
|
25
|
+
(year += 1; month_number = 1) if month_number > 12
|
|
26
|
+
(np_start_month = 1; starting_index_of_bs_date += 1) if np_start_month > 12
|
|
27
|
+
en_total_days -= 1
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
self.week_day = get_day_of_week(day_of_week, 'np')
|
|
31
|
+
self.month = get_month_name(month_number, 'np')
|
|
32
|
+
self.month_number = month_number
|
|
33
|
+
self.day_in_month = day_in_month
|
|
34
|
+
self.day_of_week = day_of_week
|
|
35
|
+
self.year = year
|
|
36
|
+
self
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def date_valid(date, state)
|
|
41
|
+
state == "np" ? np_date_valid(date) : en_date_valid(date)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def np_date_valid(date)
|
|
45
|
+
invalid = []
|
|
46
|
+
year = (0..90).collect {|year| BsDate::BS_DATES[year][0]}
|
|
47
|
+
invalid << "month" unless (1..12).include?(date[1])
|
|
48
|
+
invalid << "year" unless year.index(date[2])
|
|
49
|
+
invalid << "day" if invalid.empty? && (date[0] == 0 || BsDate::BS_DATES[year.index(date[2])][date[1]] < date[0])
|
|
50
|
+
invalid
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def en_date_valid(date)
|
|
54
|
+
invalid = []
|
|
55
|
+
# Normal days in month except leap year
|
|
56
|
+
en_days_in_month = [31,28,31,30,31,30,31,31,30,31,30,31]
|
|
57
|
+
invalid << "month" unless (1..12).include?(date[1])
|
|
58
|
+
invalid << "year" unless (1944..2033).include?(date[2])
|
|
59
|
+
|
|
60
|
+
if invalid.empty?
|
|
61
|
+
if Date.leap?(date[2].to_i)
|
|
62
|
+
invalid << "day" unless (1..en_days_in_month[date[1].to_i - 1] + 1).include?(date[0])
|
|
63
|
+
else
|
|
64
|
+
invalid << "day" unless (1..en_days_in_month[date[1].to_i - 1]).include?(date[0])
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
invalid
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def nep_to_eng(*args)
|
|
72
|
+
args.collect!{|i| i.to_i}
|
|
73
|
+
date_error = date_valid(args, "np")
|
|
74
|
+
|
|
75
|
+
unless date_error.empty?
|
|
76
|
+
return date_error.collect{ |error| "Enter appropriate #{error}"}
|
|
77
|
+
else
|
|
78
|
+
en_start_year = 1943; en_start_month = 4; en_start_day = 14 - 1
|
|
79
|
+
np_start_year = 2000; np_start_month = 1; np_start_day = 1
|
|
80
|
+
day_of_week = 4 - 1
|
|
81
|
+
en_days_in_month = [0,31,28,31,30,31,30,31,31,30,31,30,31]
|
|
82
|
+
leap_en_days_in_month = [0,31,29,31,30,31,30,31,31,30,31,30,31]
|
|
83
|
+
np_year_diff = args[2] - np_start_year - 1; np_total_days = 0
|
|
84
|
+
|
|
85
|
+
(0..np_year_diff).each do |idx|
|
|
86
|
+
BsDate::BS_DATES[idx].shift
|
|
87
|
+
np_total_days += BsDate::BS_DATES[idx].inject(:+)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
np_month_diff = args[1] - 1
|
|
91
|
+
(1..np_month_diff).each{| idx| np_total_days += BsDate::BS_DATES[args[2] - np_start_year][idx] }
|
|
92
|
+
|
|
93
|
+
np_total_days += args[0]
|
|
94
|
+
day_in_month = en_start_day; month_number = en_start_month; year = en_start_year
|
|
95
|
+
|
|
96
|
+
while np_total_days != 0
|
|
97
|
+
total_month_days = Date.leap?(year) ? leap_en_days_in_month[month_number] : en_days_in_month[month_number]
|
|
98
|
+
day_in_month += 1; day_of_week += 1
|
|
99
|
+
|
|
100
|
+
if day_in_month > total_month_days
|
|
101
|
+
month_number += 1; day_in_month = 1
|
|
102
|
+
(year += 1; month_number = 1) if month_number > 12
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
day_of_week = 1 if day_of_week > 7
|
|
106
|
+
np_total_days -= 1
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
self.week_day = get_day_of_week(day_of_week, 'en')
|
|
110
|
+
self.month = get_month_name(month_number, 'en')
|
|
111
|
+
self.month_number = month_number
|
|
112
|
+
self.day_in_month = day_in_month
|
|
113
|
+
self.day_of_week = day_of_week
|
|
114
|
+
self.year = year
|
|
115
|
+
self
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def get_day_of_week(day, type)
|
|
121
|
+
type == "en" ? ::EN_DAY[day] : ::NP_DAY[day]
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def get_month_name(month, type)
|
|
125
|
+
type == "en" ? ::EN_MONTH[month] : ::NP_MONTH[month]
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__)
|
|
2
|
+
|
|
3
|
+
require "englishnepalidateconverter/version"
|
|
4
|
+
require "date"
|
|
5
|
+
require "englishnepalidateconverter/constants"
|
|
6
|
+
require "englishnepalidateconverter/bs_date"
|
|
7
|
+
require "englishnepalidateconverter/date_conversion"
|
|
8
|
+
|
|
9
|
+
# date = EnglishNepaliDateConverter::DateConversion.new
|
|
10
|
+
# date.nep_to_eng(01, 01, 2033)
|
|
11
|
+
# date.eng_to_nep(42, 12, 2001)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Date Conversion" do
|
|
4
|
+
before(:each) do
|
|
5
|
+
@date = EnglishNepaliDateConverter::DateConversion.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context "from Gregorian to Nepali Calendar" do
|
|
9
|
+
it "should have appropriate days of the month" do
|
|
10
|
+
@date.eng_to_nep(42, 01, 2013).should == ["Enter appropriate day"]
|
|
11
|
+
@date.eng_to_nep(31, 01, 2013)
|
|
12
|
+
@date.day_in_month.should == 18
|
|
13
|
+
@date.day_of_week.should == 5
|
|
14
|
+
@date.month.should == "Magh"
|
|
15
|
+
@date.month_number.should == 10
|
|
16
|
+
@date.week_day.should == "Bihibar"
|
|
17
|
+
@date.year.should == 2069
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should have appropriate month" do
|
|
21
|
+
@date.eng_to_nep(01, 41, 2013).should == ["Enter appropriate month"]
|
|
22
|
+
@date.eng_to_nep(01, 00, 2013).should == ["Enter appropriate month"]
|
|
23
|
+
@date.eng_to_nep(01, 01, 2013)
|
|
24
|
+
@date.day_in_month.should == 17
|
|
25
|
+
@date.day_of_week.should == 3
|
|
26
|
+
@date.month.should == "Poush"
|
|
27
|
+
@date.month_number.should == 9
|
|
28
|
+
@date.week_day.should == "Mangalbar"
|
|
29
|
+
@date.year.should == 2069
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should have appropriate year" do
|
|
33
|
+
@date.eng_to_nep(01, 11, 2093).should == ["Enter appropriate year"]
|
|
34
|
+
@date.eng_to_nep("01", "01", "2013")
|
|
35
|
+
@date.day_in_month.should == 17
|
|
36
|
+
@date.day_of_week.should == 3
|
|
37
|
+
@date.month.should == "Poush"
|
|
38
|
+
@date.month_number.should == 9
|
|
39
|
+
@date.week_day.should == "Mangalbar"
|
|
40
|
+
@date.year.should == 2069
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "from Nepali Calendar to Gregorian calendar" do
|
|
45
|
+
it "should convert date range only from 01-01-2000 to 30-12-2090" do
|
|
46
|
+
@date.nep_to_eng(01, 01, 1943).should == ["Enter appropriate year"]
|
|
47
|
+
@date.nep_to_eng(01, 01, 3043).should == ["Enter appropriate year"]
|
|
48
|
+
@date.nep_to_eng(01, 01, 2033)
|
|
49
|
+
@date.year.should == 1976
|
|
50
|
+
@date.day_of_week.should == 3
|
|
51
|
+
@date.month.should == "April"
|
|
52
|
+
@date.day_in_month.should == 13
|
|
53
|
+
@date.month_number.should == 4
|
|
54
|
+
@date.week_day.should == "Tuesday"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "should have appropriate days of the month" do
|
|
58
|
+
@date.nep_to_eng(42, 12, 2001).should == ["Enter appropriate day"]
|
|
59
|
+
@date.nep_to_eng(12, 01, 2013)
|
|
60
|
+
@date.day_in_month.should == 24
|
|
61
|
+
@date.day_of_week.should == 3
|
|
62
|
+
@date.month.should == "April"
|
|
63
|
+
@date.month_number.should == 4
|
|
64
|
+
@date.week_day.should == "Tuesday"
|
|
65
|
+
@date.year.should == 1956
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should have appropriate month" do
|
|
69
|
+
@date.nep_to_eng(12, 00, 2013).should == ["Enter appropriate month"]
|
|
70
|
+
@date.nep_to_eng(12, 14, 2013).should == ["Enter appropriate month"]
|
|
71
|
+
@date.nep_to_eng(12, 11, 2013)
|
|
72
|
+
@date.day_in_month.should == 23
|
|
73
|
+
@date.day_of_week.should == 7
|
|
74
|
+
@date.month.should == "February"
|
|
75
|
+
@date.month_number.should == 2
|
|
76
|
+
@date.week_day.should == "Saturday"
|
|
77
|
+
@date.year.should == 1957
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: englishnepalidateconverter
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- dlamichhane
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-01-16 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.3'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ~>
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - '>='
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: '"Conversion of Gregorian calendar to Nepali Calendar"'
|
|
56
|
+
email:
|
|
57
|
+
- dlamichhane@hotmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- .gitignore
|
|
63
|
+
- Gemfile
|
|
64
|
+
- LICENSE.txt
|
|
65
|
+
- README.md
|
|
66
|
+
- Rakefile
|
|
67
|
+
- englishnepalidateconverter.gemspec
|
|
68
|
+
- lib/englishnepalidateconverter.rb
|
|
69
|
+
- lib/englishnepalidateconverter/bs_date.rb
|
|
70
|
+
- lib/englishnepalidateconverter/constants.rb
|
|
71
|
+
- lib/englishnepalidateconverter/date_conversion.rb
|
|
72
|
+
- lib/englishnepalidateconverter/version.rb
|
|
73
|
+
- spec/englishnepalidateconverter/date_conversion_spec.rb
|
|
74
|
+
- spec/spec_helper.rb
|
|
75
|
+
homepage: https://github.com/dlamichhane/englishnepalidateconverter
|
|
76
|
+
licenses:
|
|
77
|
+
- MIT
|
|
78
|
+
metadata: {}
|
|
79
|
+
post_install_message:
|
|
80
|
+
rdoc_options: []
|
|
81
|
+
require_paths:
|
|
82
|
+
- lib
|
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - '>='
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - '>='
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
requirements: []
|
|
94
|
+
rubyforge_project:
|
|
95
|
+
rubygems_version: 2.2.2
|
|
96
|
+
signing_key:
|
|
97
|
+
specification_version: 4
|
|
98
|
+
summary: Converts the English calendar date to Nepali calendar date
|
|
99
|
+
test_files:
|
|
100
|
+
- spec/englishnepalidateconverter/date_conversion_spec.rb
|
|
101
|
+
- spec/spec_helper.rb
|