englishnepalidateconverter 0.0.2 → 2.0.1
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/.github/workflows/ci.yml +71 -0
- data/.rspec +1 -0
- data/.rubocop.yml +23 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -1
- data/LICENSE.txt +1 -1
- data/README.md +239 -16
- data/Rakefile +4 -2
- data/englishnepalidateconverter.gemspec +20 -13
- data/lib/englishnepalidateconverter/bs_calendar.rb +151 -0
- data/lib/englishnepalidateconverter/bs_date.rb +58 -95
- data/lib/englishnepalidateconverter/converter.rb +84 -0
- data/lib/englishnepalidateconverter/errors.rb +19 -0
- data/lib/englishnepalidateconverter/extensions/date.rb +11 -0
- data/lib/englishnepalidateconverter/extensions/integer.rb +21 -0
- data/lib/englishnepalidateconverter/version.rb +3 -1
- data/lib/englishnepalidateconverter.rb +12 -7
- data/spec/englishnepalidateconverter/bs_date_spec.rb +119 -0
- data/spec/englishnepalidateconverter/converter_spec.rb +75 -0
- data/spec/englishnepalidateconverter/version_spec.rb +7 -0
- data/spec/spec_helper.rb +98 -5
- metadata +92 -29
- 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: c5b1bc863beae761d07b77b3e4ff5081c642e7e1aef2dd326bd646de58adaa4f
|
|
4
|
+
data.tar.gz: b9b0641bcb2a06604d94128efca2ccccd70d11cda5902efc69c155d97c73c306
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cce984e5a63bb15a2268318ab01eeb5de0f29dc6baad7b3097cb3391ee1b38efb4006e008e0a0b06967b96562e3477d2ea2d225d0bd236c567fd0883d9e5cf06
|
|
7
|
+
data.tar.gz: 5b6eed8c2afc6099fdcb6bfd4e0fa062bf0f29061d832506d1cd7bc8f8fc3e6705b75d2977198a931beb11364e174005532a12595fcb09a3e96e649c315fc55b
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: ruby/setup-ruby@v1
|
|
18
|
+
with:
|
|
19
|
+
ruby-version: .ruby-version
|
|
20
|
+
bundler-cache: true
|
|
21
|
+
- name: Run tests
|
|
22
|
+
run: bundle exec rspec
|
|
23
|
+
- name: Run linter
|
|
24
|
+
run: bundle exec rubocop
|
|
25
|
+
|
|
26
|
+
# Runs only when a version tag (e.g. v2.0.1) is pushed, after the tests pass.
|
|
27
|
+
# Publishes the same gem under two names on RubyGems.org.
|
|
28
|
+
release:
|
|
29
|
+
needs: test
|
|
30
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
permissions:
|
|
33
|
+
contents: read
|
|
34
|
+
id-token: write # needed for RubyGems.org trusted publishing
|
|
35
|
+
steps:
|
|
36
|
+
- uses: actions/checkout@v4
|
|
37
|
+
- uses: ruby/setup-ruby@v1
|
|
38
|
+
with:
|
|
39
|
+
ruby-version: .ruby-version
|
|
40
|
+
- name: Check tag matches gem version
|
|
41
|
+
run: |
|
|
42
|
+
version=$(ruby -Ilib -e 'require "englishnepalidateconverter/version"; puts EnglishNepaliDateConverter::VERSION')
|
|
43
|
+
if [ "v$version" != "$GITHUB_REF_NAME" ]; then
|
|
44
|
+
echo "Tag $GITHUB_REF_NAME does not match gem version $version"
|
|
45
|
+
exit 1
|
|
46
|
+
fi
|
|
47
|
+
- name: Build gems
|
|
48
|
+
run: |
|
|
49
|
+
ruby -rrubygems/package -e '
|
|
50
|
+
spec = Gem::Specification.load("englishnepalidateconverter.gemspec")
|
|
51
|
+
%w[englishnepalidateconverter english_nepali_date_converter].each do |name|
|
|
52
|
+
copy = spec.dup
|
|
53
|
+
copy.name = name
|
|
54
|
+
Gem::Package.build(copy)
|
|
55
|
+
end
|
|
56
|
+
'
|
|
57
|
+
ls -l *.gem
|
|
58
|
+
|
|
59
|
+
- name: Configure RubyGems credentials (englishnepalidateconverter)
|
|
60
|
+
uses: rubygems/configure-rubygems-credentials@v2.2.0
|
|
61
|
+
- name: Push englishnepalidateconverter
|
|
62
|
+
run: gem push englishnepalidateconverter-*.gem
|
|
63
|
+
|
|
64
|
+
# The first release of a new gem through a pending trusted publisher needs
|
|
65
|
+
# the RubyGems.org account ID. Set it as the repository variable RUBYGEMS_OWNER_ID.
|
|
66
|
+
- name: Configure RubyGems credentials (english_nepali_date_converter)
|
|
67
|
+
uses: rubygems/configure-rubygems-credentials@v2.2.0
|
|
68
|
+
with:
|
|
69
|
+
owner: ${{ vars.RUBYGEMS_OWNER_ID }}
|
|
70
|
+
- name: Push english_nepali_date_converter
|
|
71
|
+
run: gem push english_nepali_date_converter-*.gem
|
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 4.0
|
|
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/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4.0.10
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,35 +1,258 @@
|
|
|
1
1
|
# EnglishNepaliDateConverter
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
[](https://github.com/dlamichhane/englishnepalidateconverter/actions/workflows/ci.yml)
|
|
4
|
+
[](https://rubygems.org/gems/englishnepalidateconverter)
|
|
5
|
+
|
|
6
|
+
A dependency-free Ruby gem that converts dates between the Gregorian calendar (AD) and the Bikram Sambat calendar (BS), Nepal's official calendar. It can also format BS dates in Nepali script, with month and weekday names in Nepali, romanized Nepali or English.
|
|
7
|
+
|
|
8
|
+
```ruby
|
|
9
|
+
require "englishnepalidateconverter"
|
|
10
|
+
|
|
11
|
+
Converter = EnglishNepaliDateConverter::Converter
|
|
12
|
+
|
|
13
|
+
Converter.to_bs(Date.new(2014, 1, 17)).to_nepali # => "माघ ३, २०७०"
|
|
14
|
+
Converter.to_ad(2070, 10, 3) # => #<Date: 2014-01-17>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Contents
|
|
18
|
+
|
|
19
|
+
- [Features](#features)
|
|
20
|
+
- [Supported date range](#supported-date-range)
|
|
21
|
+
- [Installation](#installation)
|
|
22
|
+
- [Usage](#usage)
|
|
23
|
+
- [The converter](#the-converter)
|
|
24
|
+
- [Convert BS to AD](#convert-bs-to-ad)
|
|
25
|
+
- [Convert AD to BS](#convert-ad-to-bs)
|
|
26
|
+
- [Today's date in BS](#todays-date-in-bs)
|
|
27
|
+
- [Month and weekday names](#month-and-weekday-names)
|
|
28
|
+
- [Nepali digits](#nepali-digits)
|
|
29
|
+
- [Error handling](#error-handling)
|
|
30
|
+
- [API reference](#api-reference)
|
|
31
|
+
- [Development](#development)
|
|
32
|
+
- [Contributing](#contributing)
|
|
33
|
+
- [License](#license)
|
|
34
|
+
|
|
35
|
+
## Features
|
|
36
|
+
|
|
37
|
+
- Convert BS to AD and AD to BS.
|
|
38
|
+
- Get today's date in BS.
|
|
39
|
+
- Month names in Nepali (`माघ`) or romanized Nepali (`Magh`).
|
|
40
|
+
- Weekday names in Nepali (`शुक्रबार`), romanized Nepali (`Shukrabar`) or English (`Friday`).
|
|
41
|
+
- Full Nepali date strings such as `माघ ३, २०७०`.
|
|
42
|
+
- Convert any integer to Nepali digits (`2070` → `२०७०`).
|
|
43
|
+
- No runtime dependencies. It uses only Ruby's standard `Date` library.
|
|
44
|
+
|
|
45
|
+
## Supported date range
|
|
46
|
+
|
|
47
|
+
Conversion uses a built-in table of BS month lengths, so it only works within this range:
|
|
48
|
+
|
|
49
|
+
| Direction | From | To |
|
|
50
|
+
| --------- | ---------- | ---------- |
|
|
51
|
+
| AD → BS | 1943-04-14 | 2034-04-13 |
|
|
52
|
+
| BS → AD | 2000-01-01 | 2090-12-30 |
|
|
53
|
+
|
|
54
|
+
Dates outside this range raise an error. See [Error handling](#error-handling).
|
|
5
55
|
|
|
6
56
|
## Installation
|
|
7
57
|
|
|
8
|
-
|
|
58
|
+
Requires Ruby 4.0 or newer. Version 1.0.0 on RubyGems still supports Ruby 3.4.
|
|
9
59
|
|
|
10
|
-
|
|
60
|
+
Add the gem to your application's `Gemfile`:
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
gem "englishnepalidateconverter"
|
|
64
|
+
```
|
|
11
65
|
|
|
12
|
-
|
|
66
|
+
Then run:
|
|
13
67
|
|
|
14
|
-
|
|
68
|
+
```sh
|
|
69
|
+
bundle install
|
|
70
|
+
```
|
|
15
71
|
|
|
16
|
-
Or install it
|
|
72
|
+
Or install it directly:
|
|
17
73
|
|
|
18
|
-
|
|
74
|
+
```sh
|
|
75
|
+
gem install englishnepalidateconverter
|
|
76
|
+
```
|
|
19
77
|
|
|
20
78
|
## Usage
|
|
21
79
|
|
|
80
|
+
Require the gem once. It loads `date` for you:
|
|
22
81
|
|
|
23
82
|
```ruby
|
|
24
|
-
|
|
25
|
-
date.eng_to_nep(16,01,2014)
|
|
26
|
-
date.nep_to_eng(03,10,2070)
|
|
83
|
+
require "englishnepalidateconverter"
|
|
27
84
|
```
|
|
28
85
|
|
|
86
|
+
### The converter
|
|
87
|
+
|
|
88
|
+
`EnglishNepaliDateConverter::Converter` handles both directions in one place:
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
Converter = EnglishNepaliDateConverter::Converter
|
|
92
|
+
|
|
93
|
+
Converter.to_bs(Date.new(2025, 9, 3)) # => BSDate 2082-05-18
|
|
94
|
+
Converter.to_ad(BSDate.new(2082, 5, 18)) # => #<Date: 2025-09-03>
|
|
95
|
+
Converter.to_ad(2082, 5, 18) # => #<Date: 2025-09-03>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Both methods check that the date is within the [supported range](#supported-date-range). `Date#to_bs`, `BSDate#to_ad` and `BSDate.from_ad`, described below, are shortcuts that call the converter.
|
|
99
|
+
|
|
100
|
+
### Convert BS to AD
|
|
101
|
+
|
|
102
|
+
Create a `BSDate` from a year, month and day, then call `to_ad`. It returns a standard Ruby `Date`:
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
105
|
+
bs_date = BSDate.new(2070, 10, 3)
|
|
106
|
+
|
|
107
|
+
ad_date = bs_date.to_ad # => #<Date: 2014-01-17>
|
|
108
|
+
ad_date.to_s # => "2014-01-17"
|
|
109
|
+
ad_date.strftime("%d %B %Y") # => "17 January 2014"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Months are numbered 1 to 12, with 1 being Baisakh. See the [month table](#months).
|
|
113
|
+
|
|
114
|
+
### Convert AD to BS
|
|
115
|
+
|
|
116
|
+
Call `to_bs` on any `Date`:
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
bs_date = Date.new(2014, 1, 17).to_bs
|
|
120
|
+
|
|
121
|
+
bs_date.year # => 2070
|
|
122
|
+
bs_date.month # => 10
|
|
123
|
+
bs_date.day # => 3
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
`BSDate.from_ad(date)` does the same conversion.
|
|
127
|
+
|
|
128
|
+
### Today's date in BS
|
|
129
|
+
|
|
130
|
+
Call `BSDate.new` with no arguments to get today's date in BS:
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
today = BSDate.new
|
|
134
|
+
today.to_nepali # => e.g. "मंसिर २१, २०८३"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Month and weekday names
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
bs_date = BSDate.new(2070, 10, 3)
|
|
141
|
+
|
|
142
|
+
bs_date.month_name # => "माघ"
|
|
143
|
+
bs_date.month_name(romanized: true) # => "Magh"
|
|
144
|
+
|
|
145
|
+
bs_date.day_name # => "शुक्रबार"
|
|
146
|
+
bs_date.day_name(romanized: true) # => "Shukrabar"
|
|
147
|
+
bs_date.day_name(localized: true) # => "Friday"
|
|
148
|
+
|
|
149
|
+
bs_date.to_nepali # => "माघ ३, २०७०"
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
`day_name` takes either `romanized: true` or `localized: true`, not both at once.
|
|
153
|
+
|
|
154
|
+
#### Months
|
|
155
|
+
|
|
156
|
+
| # | Nepali | Romanized |
|
|
157
|
+
| --- | ------- | --------- |
|
|
158
|
+
| 1 | बैशाख | Baisakh |
|
|
159
|
+
| 2 | जेठ | Jeth |
|
|
160
|
+
| 3 | असार | Asar |
|
|
161
|
+
| 4 | श्रावण | Shrawan |
|
|
162
|
+
| 5 | भाद्र | Bhadra |
|
|
163
|
+
| 6 | आश्विन | Ashwin |
|
|
164
|
+
| 7 | कार्तिक | Kartik |
|
|
165
|
+
| 8 | मंसिर | Mangsir |
|
|
166
|
+
| 9 | पुष | Poush |
|
|
167
|
+
| 10 | माघ | Magh |
|
|
168
|
+
| 11 | फाल्गुण | Falgun |
|
|
169
|
+
| 12 | चैत | Chaitra |
|
|
170
|
+
|
|
171
|
+
#### Weekdays
|
|
172
|
+
|
|
173
|
+
| English | Nepali | Romanized |
|
|
174
|
+
| --------- | -------- | --------- |
|
|
175
|
+
| Sunday | आइतबार | Aaitabar |
|
|
176
|
+
| Monday | सोमबार | Sombar |
|
|
177
|
+
| Tuesday | मंगलवार | Mangalbar |
|
|
178
|
+
| Wednesday | बुधबार | Budhbar |
|
|
179
|
+
| Thursday | बिहीबार | Bihibar |
|
|
180
|
+
| Friday | शुक्रबार | Shukrabar |
|
|
181
|
+
| Saturday | शनिवार | Shanibar |
|
|
182
|
+
|
|
183
|
+
### Nepali digits
|
|
184
|
+
|
|
185
|
+
The gem adds `to_nepali` to `Integer`, which returns the number written in Nepali digits:
|
|
186
|
+
|
|
187
|
+
```ruby
|
|
188
|
+
2070.to_nepali # => "२०७०"
|
|
189
|
+
16.to_nepali # => "१६"
|
|
190
|
+
-5.to_nepali # => "-५"
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Error handling
|
|
194
|
+
|
|
195
|
+
All of the gem's errors inherit from `EnglishNepaliDateConverter::Error`, so you can catch them all with one `rescue`:
|
|
196
|
+
|
|
197
|
+
| Error | Raised when |
|
|
198
|
+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
199
|
+
| `DateOutOfRangeError` | `Converter.to_bs` (or `Date#to_bs`, `BSDate.from_ad`) gets a date outside 1943-04-14 to 2034-04-13. |
|
|
200
|
+
| `BSDateOutOfRangeError` | `Converter.to_ad` or `BSDate#to_ad` (and methods that use it, such as `day_name`) gets a year outside 2000 to 2090, a month outside 1 to 12, or a day that doesn't exist in that BS month. |
|
|
201
|
+
|
|
202
|
+
```ruby
|
|
203
|
+
begin
|
|
204
|
+
Date.new(1900, 1, 1).to_bs
|
|
205
|
+
rescue EnglishNepaliDateConverter::Error => e
|
|
206
|
+
puts e.message
|
|
207
|
+
# => "Date 1900-01-01 is out of supported AD Range (1943-04-14 - 2034-04-13)"
|
|
208
|
+
end
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
`BSDate.new` doesn't check its arguments when you create it. An invalid date raises an error only when you convert it or ask for its weekday.
|
|
212
|
+
|
|
213
|
+
## API reference
|
|
214
|
+
|
|
215
|
+
`Converter` lives only inside `EnglishNepaliDateConverter`. `BSDate`, `DateOutOfRangeError` and `BSDateOutOfRangeError` are available at the top level, and also inside `EnglishNepaliDateConverter`.
|
|
216
|
+
|
|
217
|
+
| Method | Returns | Description |
|
|
218
|
+
| ----------------------------------------------------------------- | --------- | ---------------------------------------------------- |
|
|
219
|
+
| `Converter.to_bs(date)` | `BSDate` | Converts a `Date` to BS, with a range check. |
|
|
220
|
+
| `Converter.to_ad(bs_date)` or `Converter.to_ad(year, month, day)` | `Date` | Converts a BS date to AD, with a range check. |
|
|
221
|
+
| `BSDate.new(year, month, day)` | `BSDate` | A BS date. Not validated until it is used. |
|
|
222
|
+
| `BSDate.new` | `BSDate` | Today's date in BS. |
|
|
223
|
+
| `BSDate.from_ad(date)` | `BSDate` | Same as `Converter.to_bs`. |
|
|
224
|
+
| `BSDate#year`, `#month`, `#day` | `Integer` | Parts of the BS date. |
|
|
225
|
+
| `BSDate#to_ad` | `Date` | Converts to AD. |
|
|
226
|
+
| `BSDate#month_name(romanized: false)` | `String` | Month name in Nepali, or romanized Nepali. |
|
|
227
|
+
| `BSDate#day_name(romanized: nil, localized: nil)` | `String` | Weekday name in Nepali, romanized Nepali or English. |
|
|
228
|
+
| `BSDate#to_nepali` | `String` | Formatted date, e.g. `"माघ ३, २०७०"`. |
|
|
229
|
+
| `Date#to_bs` | `BSDate` | Same as `Converter.to_bs`. |
|
|
230
|
+
| `Integer#to_nepali` | `String` | The number in Nepali digits. |
|
|
231
|
+
|
|
232
|
+
## Development
|
|
233
|
+
|
|
234
|
+
After cloning the repository:
|
|
235
|
+
|
|
236
|
+
```sh
|
|
237
|
+
bundle install # install development dependencies
|
|
238
|
+
bundle exec rspec # run the tests
|
|
239
|
+
bundle exec rubocop # run the linter
|
|
240
|
+
bundle exec rake install # build and install the gem locally
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The BS month-length table is in [`lib/englishnepalidateconverter/bs_calendar.rb`](lib/englishnepalidateconverter/bs_calendar.rb). To support more years, add rows there. The supported AD and BS ranges are derived from the table, and all conversion logic lives in [`lib/englishnepalidateconverter/converter.rb`](lib/englishnepalidateconverter/converter.rb).
|
|
244
|
+
|
|
29
245
|
## Contributing
|
|
30
246
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
247
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/dlamichhane/englishnepalidateconverter).
|
|
248
|
+
|
|
249
|
+
1. Fork the repository and create a branch for your change.
|
|
250
|
+
2. Add tests for it in `spec/`.
|
|
251
|
+
3. Make sure `bundle exec rspec` and `bundle exec rubocop` pass.
|
|
252
|
+
4. Open a pull request.
|
|
253
|
+
|
|
254
|
+
## License
|
|
255
|
+
|
|
256
|
+
This gem is available under the [MIT License](LICENSE.txt).
|
|
257
|
+
|
|
258
|
+
Copyright (c) 2027 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 = %(2026-12-06)
|
|
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", "~> 4.0"
|
|
25
|
+
spec.add_development_dependency "pry-byebug"
|
|
25
26
|
spec.add_development_dependency "rake"
|
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.13"
|
|
28
|
+
spec.add_development_dependency "rubocop", "~> 1.93"
|
|
29
|
+
spec.add_development_dependency "rubocop-rake", "~> 0.7"
|
|
30
|
+
spec.add_development_dependency "rubocop-rspec", "~> 3.11"
|
|
31
|
+
|
|
32
|
+
spec.required_ruby_version = ">= 4.0"
|
|
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
|