english_nepali_date_converter 0.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6c1b6e1517a27ca7832c04fd19c2d392b95092cc
4
- data.tar.gz: 03dae0683c74ac7626b3b5c3bb5610cf0518312b
2
+ SHA256:
3
+ metadata.gz: de2949abe9248d8bb5f22cc7d4c78b0c3e41b3cbb1d96c9397ddc2facf1ee483
4
+ data.tar.gz: d028e9ed3fef01eaa703aad112538ee811cf5b600011d835fd839446c305fe8a
5
5
  SHA512:
6
- metadata.gz: cc16224f4372faab604f5cad8dc73ad1dcf6eb668344dde5acd522cf27aefeba4bc2111e105c237a515a1feea8b0a0e1da510fc365aea372c42c949f88a3d678
7
- data.tar.gz: 6497c7a024e3c7f20fb9d563b4f5471f9d74adf2d1f8388937d8f0a01783362c4eda9c43b6496622ecabf33a21398c14ffa2bbf62cb21ddd0b6f795c3dd0256b
6
+ metadata.gz: 1b6267e5fc227b6196cf0d9fdbf3d163aa275f68e09f6e6cd7b8b20551dccd3f1e2a80da4c1a98db032951b467dae336495a8ad3db8292b43a0c42878a365d0d
7
+ data.tar.gz: 1f51ac59dabffa7e2c900ee0081558a991402fc169bf8d375b3c57f8019bacff6b340a249e34fe46e01676ac0497853bd8c1728e5272750f980969038632e6d3
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
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in english_nepali_date_converter.gemspec
4
6
  gemspec
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 dlamichhane
1
+ Copyright (c) 2025 dlamichhane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,12 +1,17 @@
1
1
  # EnglishNepaliDateConverter
2
2
 
3
- TODO: Write a gem description
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
4
9
 
5
10
  ## Installation
6
11
 
7
12
  Add this line to your application's Gemfile:
8
13
 
9
- gem 'english_nepali_date_converter'
14
+ gem 'englishnepalidateconverter'
10
15
 
11
16
  And then execute:
12
17
 
@@ -14,21 +19,71 @@ And then execute:
14
19
 
15
20
  Or install it yourself as:
16
21
 
17
- $ gem install english_nepali_date_converter
22
+ $ gem install englishnepalidateconverter
18
23
 
19
24
  ## Usage
20
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
21
78
 
22
79
  ```ruby
23
- call = EnglishNepaliDateConverter::DateConversion.new
24
- p call.eng_to_nep(16,01,2014)
25
- p call.nep_to_eng(03,10,2070)
80
+ # Convert numbers to Nepali digits
81
+ puts 2070.to_nepali # => "२०७०"
82
+ puts 16.to_nepali # => "१६"
26
83
  ```
27
84
 
28
- ## Contributing
85
+ ## License
86
+
87
+ This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.
29
88
 
30
- 1. Fork it
31
- 2. Create your feature branch (`git checkout -b my-new-feature`)
32
- 3. Commit your changes (`git commit -am 'Add some feature'`)
33
- 4. Push to the branch (`git push origin my-new-feature`)
34
- 5. Create new Pull Request
89
+ Copyright (c) 2014 dlamichhane
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
4
+
5
+ require "rspec/core/rake_task"
6
+ RSpec::Core::RakeTask.new("spec")
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "English"
4
+ lib = File.expand_path("lib", __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require "englishnepalidateconverter/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "english_nepali_date_converter"
10
+ spec.version = EnglishNepaliDateConverter::VERSION
11
+ spec.date = %(2025-09-01)
12
+ spec.authors = ["dlamichhane"]
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
+
19
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
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", "~> 2.7"
25
+ spec.add_development_dependency "pry-byebug"
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"
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
@@ -0,0 +1,111 @@
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EnglishNepaliDateConverter
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH << File.dirname(__FILE__)
4
+
5
+ require_relative "englishnepalidateconverter/version"
6
+ require "date"
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
29
+
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
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe EnglishNepaliDateConverter do
4
+ it "should be a valid version" do
5
+ expect(EnglishNepaliDateConverter::VERSION).to eq("1.0.0")
6
+ end
7
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
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
20
+ RSpec.configure do |config|
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,82 +1,158 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: english_nepali_date_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
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: 2014-01-16 00:00:00.000000000 Z
10
+ date: 2025-09-01 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ~>
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '1.3'
18
+ version: '2.7'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ~>
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '1.3'
25
+ version: '2.7'
26
+ - !ruby/object:Gem::Dependency
27
+ name: pry-byebug
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
27
40
  - !ruby/object:Gem::Dependency
28
41
  name: rake
29
42
  requirement: !ruby/object:Gem::Requirement
30
43
  requirements:
31
- - - '>='
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: rspec
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
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
+ - - ">="
32
87
  - !ruby/object:Gem::Version
33
88
  version: '0'
34
89
  type: :development
35
90
  prerelease: false
36
91
  version_requirements: !ruby/object:Gem::Requirement
37
92
  requirements:
38
- - - '>='
93
+ - - ">="
39
94
  - !ruby/object:Gem::Version
40
95
  version: '0'
41
- description: '"Conversion of Gregorian calendar to Nepali Calendar"'
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
42
111
  email:
43
- - dlamichhane@hotmail.com
112
+ - lamichhanedeepak@gmail.com
44
113
  executables: []
45
114
  extensions: []
46
115
  extra_rdoc_files: []
47
116
  files:
48
- - .gitignore
117
+ - ".gitignore"
118
+ - ".rspec"
119
+ - ".rubocop.yml"
49
120
  - Gemfile
50
121
  - LICENSE.txt
51
122
  - README.md
52
123
  - Rakefile
53
- - english_nepali_date_converter.gemspec
54
- - lib/english_nepali_date_converter.rb
55
- - lib/english_nepali_date_converter/bs_date.rb
56
- - lib/english_nepali_date_converter/date_conversion.rb
57
- - lib/english_nepali_date_converter/version.rb
58
- homepage: https://github.com/dlamichhane/english_nepali_date_converter
124
+ - englishnepalidateconverter.gemspec
125
+ - lib/englishnepalidateconverter.rb
126
+ - lib/englishnepalidateconverter/bs_calendar.rb
127
+ - lib/englishnepalidateconverter/bs_date.rb
128
+ - lib/englishnepalidateconverter/extensions/date.rb
129
+ - lib/englishnepalidateconverter/extensions/integer.rb
130
+ - lib/englishnepalidateconverter/version.rb
131
+ - spec/englishnepalidateconverter/bs_date_spec.rb
132
+ - spec/englishnepalidateconverter/version_spec.rb
133
+ - spec/spec_helper.rb
134
+ homepage: https://github.com/dlamichhane/englishnepalidateconverter
59
135
  licenses:
60
136
  - MIT
61
137
  metadata: {}
62
- post_install_message:
63
138
  rdoc_options: []
64
139
  require_paths:
65
140
  - lib
66
141
  required_ruby_version: !ruby/object:Gem::Requirement
67
142
  requirements:
68
- - - '>='
143
+ - - ">="
69
144
  - !ruby/object:Gem::Version
70
- version: '0'
145
+ version: '3.4'
71
146
  required_rubygems_version: !ruby/object:Gem::Requirement
72
147
  requirements:
73
- - - '>='
148
+ - - ">="
74
149
  - !ruby/object:Gem::Version
75
150
  version: '0'
76
151
  requirements: []
77
- rubyforge_project:
78
- rubygems_version: 2.1.11
79
- signing_key:
152
+ rubygems_version: 3.6.9
80
153
  specification_version: 4
81
154
  summary: Converts the English calendar date to Nepali calendar date
82
- test_files: []
155
+ test_files:
156
+ - spec/englishnepalidateconverter/bs_date_spec.rb
157
+ - spec/englishnepalidateconverter/version_spec.rb
158
+ - spec/spec_helper.rb
@@ -1,24 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'english_nepali_date_converter/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "english_nepali_date_converter"
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/english_nepali_date_converter}
15
- spec.licenses = ['MIT']
16
-
17
- spec.files = `git ls-files`.split($/)
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
21
-
22
- spec.add_development_dependency "bundler", "~> 1.3"
23
- spec.add_development_dependency "rake"
24
- end
@@ -1,95 +0,0 @@
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
@@ -1,150 +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
- EN_DAY = { 1 => "Sunday", 2 => "Monday", 3 => "Tuesday", 4 => "Wednesday", 5 => "Thursday", 6 => "Friday", 7 => "Saturday" }
7
- NP_DAY = { 1 => "Aaitabar", 2 => "Sombar", 3 => "Mangalbar", 4 => "Budhabar", 5 => "Bihibar", 6 => "Sukrabar", 7 => "Sanibar" }
8
-
9
- NP_MONTH = { 1 => "Baisakh", 2 => "Jestha", 3 => "Asar", 4 => "Shrawan", 5 => "Bhadra", 6 => "Ashoj",
10
- 7 => "Kartik", 8 => "Mangsir", 9 => "Poush", 10 => "Magh", 11 => "Falgun", 12 => "Chaitra" }
11
-
12
- EN_MONTH = { 1 => "January", 2 => "February", 3 => "March", 4 => "April", 5 => "May", 6 => "June",
13
- 7 => "July", 8 => "August", 9 => "September", 10 => "October", 11 => "November", 12 => "December" }
14
-
15
- def eng_to_nep(*args)
16
-
17
- # Normal days in month except leap year
18
- enDaysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31]
19
- return "Enter appropriate month" unless (1..12).include?(args[1])
20
-
21
- if Date.leap?(args[2].to_i)
22
- return "Enter appropriate day of the month" unless (1.. + enDaysInMonth[args[1].to_i - 1] + 1).include?(args[0])
23
- else
24
- return "Enter appropriate day of the month" unless (1.. + enDaysInMonth[args[1].to_i - 1]).include?(args[0])
25
- end
26
-
27
- formated_date = args[0].to_s + "-" + args[1].to_s + "-" + args[2].to_s
28
- starting_date = DateTime.parse("01-01-1944").mjd.to_i
29
- ending_date = DateTime.parse("31-12-2033").mjd
30
- date_to_convert = DateTime.parse(formated_date).mjd
31
- return "Enter a valid date from 01-01-1944 to 31-12-2033" unless (starting_date..ending_date).include?(date_to_convert)
32
-
33
- enTotalDays = date_to_convert - starting_date
34
-
35
- # Conversion of 01-01-1944 AD will be 17.01.2000 BS. Take this BS as a base date
36
- @year = npStartYear = 2000
37
- @month_number = npStartMth = 9
38
- @day_in_month = npStartDay = 17
39
-
40
- startingIndexOfBSDate = 0
41
- @day_of_week = 7 # Saturday as Day 7 and Sunday as Day 1 of the week
42
-
43
- while enTotalDays !=0
44
- @day_in_month += 1
45
- @day_of_week += 1
46
-
47
- if @day_in_month > BsDate::BS_DATES[startingIndexOfBSDate][npStartMth]
48
- @month_number += 1
49
- @day_in_month = 1
50
- npStartMth += 1
51
- end
52
-
53
- @day_of_week = 1 if @day_of_week > 7
54
-
55
- if @month_number > 12
56
- @year += 1
57
- @month_number = 1
58
- end
59
-
60
- if npStartMth > 12
61
- npStartMth = 1
62
- startingIndexOfBSDate += 1
63
- end
64
-
65
- enTotalDays -= 1
66
- end
67
-
68
- @week_day = self.class.get_day_of_week(@day_of_week, 'np')
69
- @month = self.class.get_month_name(@month_number, 'np')
70
- return self
71
- end
72
-
73
- def nep_to_eng(*args)
74
-
75
- return "Enter appropriate month" unless (1..12).include?(args[1])
76
-
77
- check_year = []
78
- for i in 0..90
79
- check_year << BsDate::BS_DATES[i][0]
80
- end
81
-
82
- return "Enter appropriate year" unless check_year.index(args[2])
83
-
84
- return "Enter appropriate day of the month" if BsDate::BS_DATES[check_year.index(args[2])][args[1]] < args[0]
85
-
86
- enStartYear = 1943; enStartMonth = 4; enStartDay = 14 - 1
87
-
88
- npStartYear = 2000; npStartMth = 1; npStartDay = 1
89
-
90
- @day_of_week = 4 - 1
91
- # (2000..2089).include?(args[2]) && (01..12).include?(args[1]) && (01..32).include?(args[0])
92
- # 2000-01-01 to 2089-12-32
93
- enDaysInMonth = [0,31,28,31,30,31,30,31,31,30,31,30,31]
94
- leapEnDaysInMonth = [0,31,29,31,30,31,30,31,31,30,31,30,31]
95
-
96
- npYearDiff = args[2] - npStartYear - 1
97
- npTotalDays = 0
98
-
99
- for i in 0.. + npYearDiff
100
- BsDate::BS_DATES[i].shift
101
- npTotalDays += BsDate::BS_DATES[i].inject(:+)
102
- end
103
-
104
- npMonthDiff = args[1] -1
105
-
106
- for i in 1.. + npMonthDiff
107
- npTotalDays += BsDate::BS_DATES[args[2] - npStartYear][i]
108
- end
109
-
110
- npTotalDays += args[0]
111
-
112
- @day_in_month = enStartDay
113
- @month_number = enStartMonth;
114
- @year = enStartYear;
115
-
116
- while npTotalDays != 0
117
-
118
- total_month_days = Date.leap?(year) ? leapEnDaysInMonth[@month_number] : enDaysInMonth[@month_number]
119
-
120
- @day_in_month += 1
121
- @day_of_week += 1
122
-
123
- if @day_in_month > total_month_days
124
- @month_number += 1
125
- @day_in_month = 1
126
-
127
- if @month_number > 12
128
- @year += 1
129
- @month_number = 1
130
- end
131
- end
132
-
133
- @day_of_week = 1 if @day_of_week > 7
134
- npTotalDays -= 1
135
- end
136
- @week_day = self.class.get_day_of_week(@day_of_week, 'en')
137
- @month = self.class.get_month_name(@month_number, 'en')
138
- return self
139
- end
140
-
141
- def self.get_day_of_week(day, type)
142
- type == "en" ? self::EN_DAY[day] : self::NP_DAY[day]
143
- end
144
-
145
- def self.get_month_name(month, type)
146
- type == "en" ? self::EN_MONTH[month] : self::NP_MONTH[month]
147
- end
148
- end
149
-
150
- end
@@ -1,3 +0,0 @@
1
- module EnglishNepaliDateConverter
2
- VERSION = "0.0.1"
3
- end
@@ -1,4 +0,0 @@
1
- require_relative "english_nepali_date_converter/version"
2
- require "date"
3
- require_relative "english_nepali_date_converter/bs_date"
4
- require_relative "english_nepali_date_converter/date_conversion"