englishnepalidateconverter 0.0.2 → 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 +5 -5
- data/.rspec +1 -0
- data/.rubocop.yml +23 -0
- data/Gemfile +3 -1
- data/LICENSE.txt +1 -1
- data/README.md +65 -11
- data/Rakefile +4 -2
- data/englishnepalidateconverter.gemspec +20 -13
- data/lib/englishnepalidateconverter/bs_calendar.rb +151 -0
- data/lib/englishnepalidateconverter/bs_date.rb +111 -95
- data/lib/englishnepalidateconverter/extensions/date.rb +20 -0
- data/lib/englishnepalidateconverter/extensions/integer.rb +21 -0
- data/lib/englishnepalidateconverter/version.rb +3 -1
- data/lib/englishnepalidateconverter.rb +28 -7
- data/spec/englishnepalidateconverter/bs_date_spec.rb +119 -0
- data/spec/englishnepalidateconverter/version_spec.rb +7 -0
- data/spec/spec_helper.rb +98 -5
- metadata +85 -28
- data/lib/englishnepalidateconverter/constants.rb +0 -11
- data/lib/englishnepalidateconverter/date_conversion.rb +0 -129
- data/spec/englishnepalidateconverter/date_conversion_spec.rb +0 -80
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 659b8de7ddfe4d8de1bd128e8e8528ca20aed20e580e5b9a96991a5589e62b5d
|
|
4
|
+
data.tar.gz: d783218484da57fccd4606f08d233ad5321cd1dbe4096eb2cc253a026321bc8e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e61c85f805523b0e66a2ba38dc85db696d3e9474d541953d79ec57abca42a314b25495f4cc07266d6af3cb8fc6f9624da948989e6582b6a0f961c4f22d90e9cc
|
|
7
|
+
data.tar.gz: a7a10d0992d37e5c7f97283b99abf2ae0bc9d7c649dc4e6ad9ebfb79282bbcc3912867fe36a3f1092b78dc27e33c8e75663f0307357e5d75a80966e22ea89ca1
|
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.4
|
|
3
|
+
|
|
4
|
+
Style/StringLiterals:
|
|
5
|
+
EnforcedStyle: double_quotes
|
|
6
|
+
|
|
7
|
+
Style/StringLiteralsInInterpolation:
|
|
8
|
+
EnforcedStyle: double_quotes
|
|
9
|
+
|
|
10
|
+
Metrics/ModuleLength:
|
|
11
|
+
Max: 150
|
|
12
|
+
|
|
13
|
+
Metrics/MethodLength:
|
|
14
|
+
Max: 100
|
|
15
|
+
|
|
16
|
+
Metrics/ClassLength:
|
|
17
|
+
Max: 200
|
|
18
|
+
|
|
19
|
+
Metrics/BlockLength:
|
|
20
|
+
Enabled: false
|
|
21
|
+
|
|
22
|
+
Lint/IneffectiveAccessModifier:
|
|
23
|
+
Enabled: false
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# EnglishNepaliDateConverter
|
|
2
2
|
|
|
3
|
-
This EnglishNepaliDateConverter gem converts
|
|
4
|
-
|
|
3
|
+
This EnglishNepaliDateConverter gem converts between Anno Domini (AD/Gregorian) and Bikram Sambat (BS/Nepali) dates.
|
|
4
|
+
|
|
5
|
+
**Supported date ranges:**
|
|
6
|
+
|
|
7
|
+
- AD to BS: 1943-04-14 to 2034-04-13
|
|
8
|
+
- BS to AD: 2000-01-01 to 2090-12-30
|
|
5
9
|
|
|
6
10
|
## Installation
|
|
7
11
|
|
|
@@ -19,17 +23,67 @@ Or install it yourself as:
|
|
|
19
23
|
|
|
20
24
|
## Usage
|
|
21
25
|
|
|
26
|
+
### Basic Date Conversion
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
require 'englishnepalidateconverter'
|
|
30
|
+
|
|
31
|
+
# Create a BS date from year, month, day
|
|
32
|
+
bs_date = BSDate.new(2070, 10, 3)
|
|
33
|
+
puts bs_date.to_ad # => 2014-01-16
|
|
34
|
+
|
|
35
|
+
# Create a BS date from an AD date
|
|
36
|
+
bs_date = BSDate.from_ad(Date.new(2014, 1, 16))
|
|
37
|
+
puts "#{bs_date.year}-#{bs_date.month}-#{bs_date.day}" # => 2070-10-3
|
|
38
|
+
|
|
39
|
+
# Create current BS date (no arguments)
|
|
40
|
+
current_bs = BSDate.new
|
|
41
|
+
puts current_bs.to_ad
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Using Date Extensions
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
# Convert AD date to BS using Date extension
|
|
48
|
+
ad_date = Date.new(2014, 1, 16)
|
|
49
|
+
bs_date = ad_date.to_bs
|
|
50
|
+
puts "#{bs_date.year}-#{bs_date.month}-#{bs_date.day}" # => 2070-10-3
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Nepali Text Formatting
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
bs_date = BSDate.new(2070, 10, 3)
|
|
57
|
+
|
|
58
|
+
# Get month name in Nepali
|
|
59
|
+
puts bs_date.month_name # => "मंसिर"
|
|
60
|
+
|
|
61
|
+
# Get month name in romanized form
|
|
62
|
+
puts bs_date.month_name(romanized: true) # => "Mangsir"
|
|
63
|
+
|
|
64
|
+
# Get day name in Nepali
|
|
65
|
+
puts bs_date.day_name # => "बुधबार"
|
|
66
|
+
|
|
67
|
+
# Get day name in romanized form
|
|
68
|
+
puts bs_date.day_name(romanized: true) # => "Budhbar"
|
|
69
|
+
|
|
70
|
+
# Get day name in English
|
|
71
|
+
puts bs_date.day_name(localized: true) # => "Wednesday"
|
|
72
|
+
|
|
73
|
+
# Get formatted Nepali date string
|
|
74
|
+
puts bs_date.to_nepali # => "मंसिर ३, २०७०"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Integer Extensions for Nepali Numbers
|
|
22
78
|
|
|
23
79
|
```ruby
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
80
|
+
# Convert numbers to Nepali digits
|
|
81
|
+
puts 2070.to_nepali # => "२०७०"
|
|
82
|
+
puts 16.to_nepali # => "१६"
|
|
27
83
|
```
|
|
28
84
|
|
|
29
|
-
##
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.
|
|
30
88
|
|
|
31
|
-
|
|
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
|
|
89
|
+
Copyright (c) 2014 dlamichhane
|
data/Rakefile
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "English"
|
|
4
|
+
lib = File.expand_path("lib", __dir__)
|
|
3
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require
|
|
6
|
+
require "englishnepalidateconverter/version"
|
|
5
7
|
|
|
6
8
|
Gem::Specification.new do |spec|
|
|
7
9
|
spec.name = "englishnepalidateconverter"
|
|
8
10
|
spec.version = EnglishNepaliDateConverter::VERSION
|
|
9
|
-
spec.date = %
|
|
11
|
+
spec.date = %(2025-09-01)
|
|
10
12
|
spec.authors = ["dlamichhane"]
|
|
11
|
-
spec.email = ["
|
|
12
|
-
spec.description =
|
|
13
|
-
spec.summary =
|
|
14
|
-
spec.homepage =
|
|
15
|
-
spec.licenses
|
|
16
|
-
|
|
17
|
-
spec.add_development_dependency "rspec"
|
|
13
|
+
spec.email = ["lamichhanedeepak@gmail.com"]
|
|
14
|
+
spec.description = "Conversion of Gregorian calendar to Nepali Calendar"
|
|
15
|
+
spec.summary = "Converts the English calendar date to Nepali calendar date"
|
|
16
|
+
spec.homepage = "https://github.com/dlamichhane/englishnepalidateconverter"
|
|
17
|
+
spec.licenses = ["MIT"]
|
|
18
18
|
|
|
19
|
-
spec.files = `git ls-files`.split(
|
|
19
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
20
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
21
21
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
22
22
|
spec.require_paths = ["lib"]
|
|
23
23
|
|
|
24
|
-
spec.add_development_dependency "bundler", "~>
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.7"
|
|
25
|
+
spec.add_development_dependency "pry-byebug"
|
|
25
26
|
spec.add_development_dependency "rake"
|
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
28
|
+
spec.add_development_dependency "rubocop", "~> 1.8"
|
|
29
|
+
spec.add_development_dependency "rubocop-rake"
|
|
30
|
+
spec.add_development_dependency "rubocop-rspec"
|
|
31
|
+
|
|
32
|
+
spec.required_ruby_version = ">= 3.4"
|
|
26
33
|
end
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module EnglishNepaliDateConverter
|
|
4
|
+
# Bikram Sambat calendar constants and data for date conversion
|
|
5
|
+
module BSCalendar
|
|
6
|
+
# Epoch reference
|
|
7
|
+
EPOCH_BS = [2000, 1, 1].freeze
|
|
8
|
+
private_constant :EPOCH_BS
|
|
9
|
+
|
|
10
|
+
EPOCH_AD = Date.new(1943, 4, 14)
|
|
11
|
+
private_constant :EPOCH_AD
|
|
12
|
+
|
|
13
|
+
EPOCH_JD = EPOCH_AD.jd
|
|
14
|
+
private_constant :EPOCH_JD
|
|
15
|
+
|
|
16
|
+
# Month lengths per year
|
|
17
|
+
# Example: { year => [month1_days, month2_days, ..., month12_days] }
|
|
18
|
+
MONTH_DAYS = {
|
|
19
|
+
2000 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
20
|
+
2001 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
21
|
+
2002 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
22
|
+
2003 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
23
|
+
2004 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
24
|
+
2005 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
25
|
+
2006 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
26
|
+
2007 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
27
|
+
2008 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
28
|
+
2009 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
29
|
+
2010 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
30
|
+
2011 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
31
|
+
2012 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
32
|
+
2013 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
33
|
+
2014 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
34
|
+
2015 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
35
|
+
2016 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
36
|
+
2017 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
37
|
+
2018 => [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
38
|
+
2019 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
39
|
+
2020 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
40
|
+
2021 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
41
|
+
2022 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
42
|
+
2023 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
43
|
+
2024 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
44
|
+
2025 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
45
|
+
2026 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
46
|
+
2027 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
47
|
+
2028 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
48
|
+
2029 => [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
|
|
49
|
+
2030 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
50
|
+
2031 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
51
|
+
2032 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
52
|
+
2033 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
53
|
+
2034 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
54
|
+
2035 => [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
55
|
+
2036 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
56
|
+
2037 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
57
|
+
2038 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
58
|
+
2039 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
59
|
+
2040 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
60
|
+
2041 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
61
|
+
2042 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
62
|
+
2043 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
63
|
+
2044 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
64
|
+
2045 => [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
65
|
+
2046 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
66
|
+
2047 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
67
|
+
2048 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
68
|
+
2049 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
69
|
+
2050 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
70
|
+
2051 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
71
|
+
2052 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
72
|
+
2053 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
73
|
+
2054 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
74
|
+
2055 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
75
|
+
2056 => [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
|
|
76
|
+
2057 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
77
|
+
2058 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
78
|
+
2059 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
79
|
+
2060 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
80
|
+
2061 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
81
|
+
2062 => [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31],
|
|
82
|
+
2063 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
83
|
+
2064 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
84
|
+
2065 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
85
|
+
2066 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
86
|
+
2067 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
87
|
+
2068 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
88
|
+
2069 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
89
|
+
2070 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
90
|
+
2071 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
91
|
+
2072 => [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
92
|
+
2073 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
93
|
+
2074 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
94
|
+
2075 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
95
|
+
2076 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
96
|
+
2077 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
97
|
+
2078 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
98
|
+
2079 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
99
|
+
2080 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
100
|
+
2081 => [31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
101
|
+
2082 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
102
|
+
2083 => [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
103
|
+
2084 => [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
104
|
+
2085 => [31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
|
105
|
+
2086 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
106
|
+
2087 => [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
|
|
107
|
+
2088 => [30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
|
108
|
+
2089 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
109
|
+
2090 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30]
|
|
110
|
+
}.freeze
|
|
111
|
+
private_constant :MONTH_DAYS
|
|
112
|
+
|
|
113
|
+
MONTHS = {
|
|
114
|
+
"बैशाख" => "Baisakh",
|
|
115
|
+
"जेठ" => "Jeth",
|
|
116
|
+
"असार" => "Asar",
|
|
117
|
+
"श्रावण" => "Shrawan",
|
|
118
|
+
"भाद्र" => "Bhadra",
|
|
119
|
+
"आश्विन" => "Ashwin",
|
|
120
|
+
"कार्तिक" => "Kartik",
|
|
121
|
+
"मंसिर" => "Mangsir",
|
|
122
|
+
"पुष" => "Poush",
|
|
123
|
+
"माघ" => "Magh",
|
|
124
|
+
"फाल्गुण" => "Falgun",
|
|
125
|
+
"चैत" => "Chaitra"
|
|
126
|
+
}.freeze
|
|
127
|
+
private_constant :MONTHS
|
|
128
|
+
|
|
129
|
+
WEEKDAYS = {
|
|
130
|
+
"आइतबार" => "Aaitabar",
|
|
131
|
+
"सोमबार" => "Sombar",
|
|
132
|
+
"मंगलवार" => "Mangalbar",
|
|
133
|
+
"बुधबार" => "Budhbar",
|
|
134
|
+
"बिहीबार" => "Bihibar",
|
|
135
|
+
"शुक्रबार" => "Shukrabar",
|
|
136
|
+
"शनिवार" => "Shanibar"
|
|
137
|
+
}.freeze
|
|
138
|
+
|
|
139
|
+
private_constant :WEEKDAYS
|
|
140
|
+
|
|
141
|
+
def self.included(base)
|
|
142
|
+
# Expose constant in the including class
|
|
143
|
+
base.const_set(:MONTHS, MONTHS)
|
|
144
|
+
base.const_set(:WEEKDAYS, WEEKDAYS)
|
|
145
|
+
base.const_set(:MONTH_DAYS, MONTH_DAYS)
|
|
146
|
+
base.const_set(:EPOCH_BS, EPOCH_BS)
|
|
147
|
+
base.const_set(:EPOCH_AD, EPOCH_AD)
|
|
148
|
+
base.const_set(:EPOCH_JD, EPOCH_JD)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
@@ -1,95 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "bs_calendar"
|
|
4
|
+
|
|
5
|
+
module EnglishNepaliDateConverter
|
|
6
|
+
# Base BS Date class
|
|
7
|
+
class BSDate
|
|
8
|
+
include BSCalendar
|
|
9
|
+
|
|
10
|
+
attr_reader :year, :month, :day
|
|
11
|
+
|
|
12
|
+
def initialize(year = nil, month = nil, day = nil)
|
|
13
|
+
if year && month && day
|
|
14
|
+
@year = year
|
|
15
|
+
@month = month
|
|
16
|
+
@day = day
|
|
17
|
+
else
|
|
18
|
+
# No arguments provided, use current AD date and convert to BS
|
|
19
|
+
bs = BSDate.from_ad(Date.today)
|
|
20
|
+
@year = bs.year
|
|
21
|
+
@month = bs.month
|
|
22
|
+
@day = bs.day
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_nepali
|
|
27
|
+
"#{month_name} #{day.to_nepali}, #{year.to_nepali}"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Convert Bikram Sambat date to Anno Domini (Gregorian) date
|
|
31
|
+
def to_ad
|
|
32
|
+
validate_date!
|
|
33
|
+
Date.jd(bs_to_jd(@year, @month, @day))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Convert Anno Domini (Gregorian) date to Bikram Sambat date
|
|
37
|
+
def self.from_ad(ad_date)
|
|
38
|
+
year, month, day = jd_to_bs(ad_date.jd)
|
|
39
|
+
new(year, month, day)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def month_name(romanized: false)
|
|
43
|
+
romanized ? MONTHS.values[@month - 1] : MONTHS.keys[@month - 1]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def day_name(romanized: nil, localized: nil)
|
|
47
|
+
if [romanized, localized].reject { |v| v.nil? || v == false }.size > 1
|
|
48
|
+
raise ArgumentError, "You must provide exactly one of :romanized or :localized"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
ad_date = to_ad
|
|
52
|
+
|
|
53
|
+
return WEEKDAYS.values[ad_date.wday] if romanized
|
|
54
|
+
return Date::DAYNAMES[ad_date.wday] if localized
|
|
55
|
+
|
|
56
|
+
WEEKDAYS.keys[ad_date.wday]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def validate_date!
|
|
62
|
+
return if valid_date?
|
|
63
|
+
|
|
64
|
+
raise BSDateOutOfRangeError,
|
|
65
|
+
"Year #{year} is out of valid range (#{MONTH_DAYS.keys.first}-#{MONTH_DAYS.keys.last})"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def valid_date?
|
|
69
|
+
MONTH_DAYS.key?(year) && (1..12).include?(month) && (1..MONTH_DAYS[year][month - 1]).include?(day)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def bs_to_jd(year, month, day)
|
|
73
|
+
julian_day = EPOCH_JD
|
|
74
|
+
|
|
75
|
+
# Add days from complete years
|
|
76
|
+
(EPOCH_BS[0]...year).each do |year_index|
|
|
77
|
+
julian_day += MONTH_DAYS[year_index].sum
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Add days from complete months in the current year
|
|
81
|
+
julian_day += MONTH_DAYS[year][0...(month - 1)].sum
|
|
82
|
+
|
|
83
|
+
# Add remaining days
|
|
84
|
+
julian_day += (day - 1)
|
|
85
|
+
|
|
86
|
+
julian_day
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def self.jd_to_bs(julian_day)
|
|
90
|
+
year = EPOCH_BS[0]
|
|
91
|
+
remaining_days = julian_day - EPOCH_JD
|
|
92
|
+
|
|
93
|
+
# Find the correct year by subtracting complete years
|
|
94
|
+
while remaining_days >= MONTH_DAYS[year].sum
|
|
95
|
+
remaining_days -= MONTH_DAYS[year].sum
|
|
96
|
+
year += 1
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Find the correct month and day within the year
|
|
100
|
+
month = 1
|
|
101
|
+
MONTH_DAYS[year].each do |days_in_month|
|
|
102
|
+
break if remaining_days < days_in_month
|
|
103
|
+
|
|
104
|
+
remaining_days -= days_in_month
|
|
105
|
+
month += 1
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
[year, month, remaining_days + 1]
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "date"
|
|
4
|
+
require_relative "../bs_date"
|
|
5
|
+
|
|
6
|
+
# Extension to Ruby's Date class to add Bikram Sambat conversion methods
|
|
7
|
+
class Date
|
|
8
|
+
EPOCH_AD_START = Date.new(1943, 4, 14)
|
|
9
|
+
EPOCH_AD_END = Date.new(2034, 4, 13)
|
|
10
|
+
private_constant :EPOCH_AD_START, :EPOCH_AD_END
|
|
11
|
+
|
|
12
|
+
def to_bs
|
|
13
|
+
if self < EPOCH_AD_START || self > EPOCH_AD_END
|
|
14
|
+
raise DateOutOfRangeError,
|
|
15
|
+
"Date #{self} is out of supported AD Range (1943-04-14 - 2034-04-13)"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
BSDate.from_ad(self)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Extension to Integer class to add Nepali number method
|
|
4
|
+
class Integer
|
|
5
|
+
NEPALI_DIGITS = {
|
|
6
|
+
"0" => "०",
|
|
7
|
+
"1" => "१",
|
|
8
|
+
"2" => "२",
|
|
9
|
+
"3" => "३",
|
|
10
|
+
"4" => "४",
|
|
11
|
+
"5" => "५",
|
|
12
|
+
"6" => "६",
|
|
13
|
+
"7" => "७",
|
|
14
|
+
"8" => "८",
|
|
15
|
+
"9" => "९"
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
def to_nepali
|
|
19
|
+
to_s.chars.map { |c| NEPALI_DIGITS[c] || c }.join
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -1,11 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
$LOAD_PATH << File.dirname(__FILE__)
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
require_relative "englishnepalidateconverter/version"
|
|
4
6
|
require "date"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
require_relative "englishnepalidateconverter/bs_date"
|
|
8
|
+
require_relative "englishnepalidateconverter/bs_calendar"
|
|
9
|
+
require_relative "englishnepalidateconverter/extensions/date"
|
|
10
|
+
require_relative "englishnepalidateconverter/extensions/integer"
|
|
11
|
+
|
|
12
|
+
module EnglishNepaliDateConverter
|
|
13
|
+
class Error < StandardError; end
|
|
14
|
+
|
|
15
|
+
# Date out of range error
|
|
16
|
+
class DateOutOfRangeError < Error
|
|
17
|
+
def initialize(message = "Date out of range")
|
|
18
|
+
super(message)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# BS Date out of range error
|
|
23
|
+
class BSDateOutOfRangeError < Error
|
|
24
|
+
def initialize(message = "BS Date out of range")
|
|
25
|
+
super(message)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
8
29
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
30
|
+
BSDate = EnglishNepaliDateConverter::BSDate
|
|
31
|
+
DateOutOfRangeError = EnglishNepaliDateConverter::DateOutOfRangeError
|
|
32
|
+
BSDateOutOfRangeError = EnglishNepaliDateConverter::BSDateOutOfRangeError
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
describe EnglishNepaliDateConverter::BSDate do
|
|
6
|
+
let(:described_instance) { described_class.new(2082, 5, 18) }
|
|
7
|
+
|
|
8
|
+
it "should be a valid instance" do
|
|
9
|
+
expect(described_instance).to be_a(EnglishNepaliDateConverter::BSDate)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "#month_name" do
|
|
13
|
+
subject { described_instance.month_name }
|
|
14
|
+
|
|
15
|
+
it "should return a valid month name" do
|
|
16
|
+
expect(subject).to eq("भाद्र")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context "with romanized option" do
|
|
20
|
+
subject { described_instance.month_name(romanized: true) }
|
|
21
|
+
|
|
22
|
+
it "should return a valid month name" do
|
|
23
|
+
expect(subject).to eq("Bhadra")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "#to_nepali" do
|
|
29
|
+
subject { described_instance.to_nepali }
|
|
30
|
+
|
|
31
|
+
it "should return a valid Nepali number" do
|
|
32
|
+
expect(subject).to eq("भाद्र १८, २०८२")
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "#day_name" do
|
|
37
|
+
subject { described_instance.day_name }
|
|
38
|
+
|
|
39
|
+
it "should return a valid day name" do
|
|
40
|
+
expect(subject).to eq("बुधबार")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "with romanized option" do
|
|
44
|
+
subject { described_instance.day_name(romanized: true) }
|
|
45
|
+
|
|
46
|
+
it "should return a valid day name" do
|
|
47
|
+
expect(subject).to eq("Budhbar")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "with localized option" do
|
|
52
|
+
subject { described_instance.day_name(localized: true) }
|
|
53
|
+
|
|
54
|
+
it "should return a valid day name" do
|
|
55
|
+
expect(subject).to eq("Wednesday")
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
describe "BS to AD conversion" do
|
|
61
|
+
subject { date.to_ad }
|
|
62
|
+
|
|
63
|
+
context "with valid date" do
|
|
64
|
+
let(:date) { BSDate.new(2082, 5, 18) }
|
|
65
|
+
|
|
66
|
+
it "should return a valid AD date instance" do
|
|
67
|
+
expect(subject).to be_a(Date)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should return a valid AD date" do
|
|
71
|
+
expect(subject.year).to eq(2025)
|
|
72
|
+
expect(subject.month).to eq(9)
|
|
73
|
+
expect(subject.day).to eq(3)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context "with invalid date" do
|
|
78
|
+
let(:date) { BSDate.new(1999, 1, 1) }
|
|
79
|
+
|
|
80
|
+
it "should raise an error" do
|
|
81
|
+
expect { subject }.to raise_error(BSDateOutOfRangeError)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "with no arguments" do
|
|
86
|
+
let(:date) { BSDate.new }
|
|
87
|
+
|
|
88
|
+
it "should return a valid AD date instance" do
|
|
89
|
+
expect(subject).to be_a(Date)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
describe "AD to BS conversion" do
|
|
95
|
+
subject { date.to_bs }
|
|
96
|
+
|
|
97
|
+
context "with valid date" do
|
|
98
|
+
let(:date) { Date.new(2025, 9, 3) }
|
|
99
|
+
|
|
100
|
+
it "should return a valid BS date instance" do
|
|
101
|
+
expect(subject).to be_a(described_class)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "should return a valid BS date" do
|
|
105
|
+
expect(subject.year).to eq(2082)
|
|
106
|
+
expect(subject.month).to eq(5)
|
|
107
|
+
expect(subject.day).to eq(18)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
context "with invalid date" do
|
|
112
|
+
let(:date) { Date.new }
|
|
113
|
+
|
|
114
|
+
it "should raise an error" do
|
|
115
|
+
expect { subject }.to raise_error(EnglishNepaliDateConverter::DateOutOfRangeError)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,7 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
require 'englishnepalidateconverter'
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
3
|
+
require "englishnepalidateconverter"
|
|
4
|
+
|
|
5
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
6
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
7
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
|
8
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
|
9
|
+
# files.
|
|
10
|
+
#
|
|
11
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
|
12
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
|
13
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
|
14
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
|
15
|
+
# a separate helper file that requires the additional dependencies and performs
|
|
16
|
+
# the additional setup, and require it from the spec files that actually need
|
|
17
|
+
# it.
|
|
18
|
+
#
|
|
19
|
+
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
4
20
|
RSpec.configure do |config|
|
|
5
|
-
config.
|
|
6
|
-
|
|
7
|
-
|
|
21
|
+
# rspec-expectations config goes here. You can use an alternate
|
|
22
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
23
|
+
# assertions if you prefer.
|
|
24
|
+
config.expect_with :rspec do |expectations|
|
|
25
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
26
|
+
# and `failure_message` of custom matchers include text for helper methods
|
|
27
|
+
# defined using `chain`, e.g.:
|
|
28
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
|
29
|
+
# # => "be bigger than 2 and smaller than 4"
|
|
30
|
+
# ...rather than:
|
|
31
|
+
# # => "be bigger than 2"
|
|
32
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
|
36
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
37
|
+
config.mock_with :rspec do |mocks|
|
|
38
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
|
39
|
+
# a real object. This is generally recommended, and will default to
|
|
40
|
+
# `true` in RSpec 4.
|
|
41
|
+
mocks.verify_partial_doubles = true
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
|
45
|
+
# have no way to turn it off -- the option exists only for backwards
|
|
46
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
|
47
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
|
48
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
|
49
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
50
|
+
|
|
51
|
+
# The settings below are suggested to provide a good initial experience
|
|
52
|
+
# with RSpec, but feel free to customize to your heart's content.
|
|
53
|
+
# # This allows you to limit a spec run to individual examples or groups
|
|
54
|
+
# # you care about by tagging them with `:focus` metadata. When nothing
|
|
55
|
+
# # is tagged with `:focus`, all examples get run. RSpec also provides
|
|
56
|
+
# # aliases for `it`, `describe`, and `context` that include `:focus`
|
|
57
|
+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
|
58
|
+
config.filter_run_when_matching :focus
|
|
59
|
+
#
|
|
60
|
+
# # Allows RSpec to persist some state between runs in order to support
|
|
61
|
+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
|
62
|
+
# # you configure your source control system to ignore this file.
|
|
63
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
|
64
|
+
#
|
|
65
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
|
66
|
+
# # recommended. For more details, see:
|
|
67
|
+
# # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
|
|
68
|
+
# config.disable_monkey_patching!
|
|
69
|
+
#
|
|
70
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
|
71
|
+
# # be too noisy due to issues in dependencies.
|
|
72
|
+
# config.warnings = true
|
|
73
|
+
#
|
|
74
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
|
75
|
+
# # file, and it's useful to allow more verbose output when running an
|
|
76
|
+
# # individual spec file.
|
|
77
|
+
# if config.files_to_run.one?
|
|
78
|
+
# # Use the documentation formatter for detailed output,
|
|
79
|
+
# # unless a formatter has already been configured
|
|
80
|
+
# # (e.g. via a command-line flag).
|
|
81
|
+
# config.default_formatter = "doc"
|
|
82
|
+
# end
|
|
83
|
+
#
|
|
84
|
+
# # Print the 10 slowest examples and example groups at the
|
|
85
|
+
# # end of the spec run, to help surface which specs are running
|
|
86
|
+
# # particularly slow.
|
|
87
|
+
# config.profile_examples = 10
|
|
88
|
+
#
|
|
89
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
|
90
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
|
91
|
+
# # the seed, which is printed after each run.
|
|
92
|
+
# # --seed 1234
|
|
93
|
+
# config.order = :random
|
|
94
|
+
#
|
|
95
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
|
96
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
|
97
|
+
# # test failures related to randomization by passing the same `--seed` value
|
|
98
|
+
# # as the one that triggered the failure.
|
|
99
|
+
# Kernel.srand config.seed
|
|
100
|
+
end
|
metadata
CHANGED
|
@@ -1,101 +1,158 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: englishnepalidateconverter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- dlamichhane
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2025-09-01 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
13
|
+
name: bundler
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.7'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.7'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: pry-byebug
|
|
15
28
|
requirement: !ruby/object:Gem::Requirement
|
|
16
29
|
requirements:
|
|
17
|
-
- -
|
|
30
|
+
- - ">="
|
|
18
31
|
- !ruby/object:Gem::Version
|
|
19
32
|
version: '0'
|
|
20
33
|
type: :development
|
|
21
34
|
prerelease: false
|
|
22
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
36
|
requirements:
|
|
24
|
-
- -
|
|
37
|
+
- - ">="
|
|
25
38
|
- !ruby/object:Gem::Version
|
|
26
39
|
version: '0'
|
|
27
40
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
41
|
+
name: rake
|
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
|
30
43
|
requirements:
|
|
31
|
-
- -
|
|
44
|
+
- - ">="
|
|
32
45
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
46
|
+
version: '0'
|
|
34
47
|
type: :development
|
|
35
48
|
prerelease: false
|
|
36
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
50
|
requirements:
|
|
38
|
-
- -
|
|
51
|
+
- - ">="
|
|
39
52
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
53
|
+
version: '0'
|
|
41
54
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
55
|
+
name: rspec
|
|
43
56
|
requirement: !ruby/object:Gem::Requirement
|
|
44
57
|
requirements:
|
|
45
|
-
- -
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '3.0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '3.0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rubocop
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '1.8'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '1.8'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: rubocop-rake
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
46
87
|
- !ruby/object:Gem::Version
|
|
47
88
|
version: '0'
|
|
48
89
|
type: :development
|
|
49
90
|
prerelease: false
|
|
50
91
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
92
|
requirements:
|
|
52
|
-
- -
|
|
93
|
+
- - ">="
|
|
53
94
|
- !ruby/object:Gem::Version
|
|
54
95
|
version: '0'
|
|
55
|
-
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: rubocop-rspec
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
description: Conversion of Gregorian calendar to Nepali Calendar
|
|
56
111
|
email:
|
|
57
|
-
-
|
|
112
|
+
- lamichhanedeepak@gmail.com
|
|
58
113
|
executables: []
|
|
59
114
|
extensions: []
|
|
60
115
|
extra_rdoc_files: []
|
|
61
116
|
files:
|
|
62
|
-
- .gitignore
|
|
117
|
+
- ".gitignore"
|
|
118
|
+
- ".rspec"
|
|
119
|
+
- ".rubocop.yml"
|
|
63
120
|
- Gemfile
|
|
64
121
|
- LICENSE.txt
|
|
65
122
|
- README.md
|
|
66
123
|
- Rakefile
|
|
67
124
|
- englishnepalidateconverter.gemspec
|
|
68
125
|
- lib/englishnepalidateconverter.rb
|
|
126
|
+
- lib/englishnepalidateconverter/bs_calendar.rb
|
|
69
127
|
- lib/englishnepalidateconverter/bs_date.rb
|
|
70
|
-
- lib/englishnepalidateconverter/
|
|
71
|
-
- lib/englishnepalidateconverter/
|
|
128
|
+
- lib/englishnepalidateconverter/extensions/date.rb
|
|
129
|
+
- lib/englishnepalidateconverter/extensions/integer.rb
|
|
72
130
|
- lib/englishnepalidateconverter/version.rb
|
|
73
|
-
- spec/englishnepalidateconverter/
|
|
131
|
+
- spec/englishnepalidateconverter/bs_date_spec.rb
|
|
132
|
+
- spec/englishnepalidateconverter/version_spec.rb
|
|
74
133
|
- spec/spec_helper.rb
|
|
75
134
|
homepage: https://github.com/dlamichhane/englishnepalidateconverter
|
|
76
135
|
licenses:
|
|
77
136
|
- MIT
|
|
78
137
|
metadata: {}
|
|
79
|
-
post_install_message:
|
|
80
138
|
rdoc_options: []
|
|
81
139
|
require_paths:
|
|
82
140
|
- lib
|
|
83
141
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
142
|
requirements:
|
|
85
|
-
- -
|
|
143
|
+
- - ">="
|
|
86
144
|
- !ruby/object:Gem::Version
|
|
87
|
-
version: '
|
|
145
|
+
version: '3.4'
|
|
88
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
147
|
requirements:
|
|
90
|
-
- -
|
|
148
|
+
- - ">="
|
|
91
149
|
- !ruby/object:Gem::Version
|
|
92
150
|
version: '0'
|
|
93
151
|
requirements: []
|
|
94
|
-
|
|
95
|
-
rubygems_version: 2.2.2
|
|
96
|
-
signing_key:
|
|
152
|
+
rubygems_version: 3.6.9
|
|
97
153
|
specification_version: 4
|
|
98
154
|
summary: Converts the English calendar date to Nepali calendar date
|
|
99
155
|
test_files:
|
|
100
|
-
- spec/englishnepalidateconverter/
|
|
156
|
+
- spec/englishnepalidateconverter/bs_date_spec.rb
|
|
157
|
+
- spec/englishnepalidateconverter/version_spec.rb
|
|
101
158
|
- spec/spec_helper.rb
|
|
@@ -1,11 +0,0 @@
|
|
|
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"}
|
|
@@ -1,129 +0,0 @@
|
|
|
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
|
|
@@ -1,80 +0,0 @@
|
|
|
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
|