miti 0.0.1 → 0.1.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +34 -9
- data/lib/miti/ad_to_bs.rb +59 -67
- data/lib/miti/bs_to_ad.rb +13 -29
- data/lib/miti/data/date_data.rb +389 -134
- data/lib/miti/nepali_date.rb +19 -14
- data/lib/miti/version.rb +1 -1
- data/lib/miti.rb +21 -0
- data/miti.gemspec +4 -4
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3046737d4f617e9117de445868dd35175bac198b1cec974171baf13d6152f3c1
|
4
|
+
data.tar.gz: 548fcde9debb5f4330a85339a77ef8f8f9e53a9324dd262d135c4b08a800a306
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f911891efb4efbc8d82eb5e125cfc86d9ebf7efdea3dfafc881415370658076a895e139343b1a9de1f2397ea8551518d61ee975cc11a431c62389e60d749676
|
7
|
+
data.tar.gz: aba5f7ee0122b77d213afb349c5fd8424e606ca7a3ee72a07e7fdef8100fab24c85d143bec5bb5efcd858275ca82633f6ff26bb56d86452f19a34a80fade8083
|
data/CHANGELOG.md
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 xkshitizx sanzay_mdr
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
# Miti
|
1
|
+
# Miti
|
2
|
+
[](https://badge.fury.io/rb/miti)
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
4
|
+
This gem can help to convert English date to Nepali date and vice-versa.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -13,21 +12,47 @@ Install the gem and add to the application's Gemfile by executing:
|
|
13
12
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
13
|
|
15
14
|
$ gem install miti
|
16
|
-
|
17
15
|
## Usage
|
18
16
|
|
19
|
-
|
17
|
+
A Miti::NepaliDate(nepali miti) object is created with Miti.to_bs, while Date(english date) object is created with Miti.to_ad
|
18
|
+
```ruby
|
19
|
+
require 'miti'
|
20
|
+
|
21
|
+
Miti.to_bs("2022/10/12") # args can also be sent as "2022-12-12"
|
22
|
+
#=> #<Miti::NepaliDate:0x00007fec31b93ac8 @barsa=2079, @gatey=26, @mahina=6>
|
23
|
+
|
24
|
+
Miti.to_bs("2022/10/12").descriptive
|
25
|
+
#=> "Asoj 26, 2079 Wednesday"
|
26
|
+
|
27
|
+
Miti.to_bs("2022/10/12").descriptive(nepali: true)
|
28
|
+
#=> "आश्विन 27, 2079 Thursday(बिहिबार)"
|
29
|
+
|
30
|
+
Miti.to_bs("2022/10/12").tarik
|
31
|
+
#=> #<Date: 2022-10-12 ((2459865j,0s,0n),+0s,2299161j)>
|
32
|
+
|
33
|
+
Miti.to_bs("2022/10/12").to_h
|
34
|
+
#=> {:barsa=>2079, :mahina=>6, :gatey=>26, :bar=>3, :tarik=>#<Date: 2022-10-12 ((2459865j,0s,0n),+0s,2299161j)>}
|
35
|
+
|
36
|
+
Miti.to_bs("2022/10/12").to_s
|
37
|
+
#=> "2079-06-26"
|
38
|
+
|
39
|
+
Miti.to_bs("2022/10/12").to_s(separator: "/") # separator can be [" ", "/"]
|
40
|
+
#=> "2079/06/26" when (separator: "/")
|
41
|
+
#=> "2079 06 26" when (separator: " ")
|
20
42
|
|
43
|
+
Miti.to_ad("2079/06/26")
|
44
|
+
#=> #<Date: 2022-10-12 ((2459865j,0s,0n),+0s,2299161j)>
|
45
|
+
```
|
21
46
|
## Development
|
22
47
|
|
23
48
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
24
49
|
|
25
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
50
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
26
51
|
|
27
52
|
## Contributing
|
28
53
|
|
29
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/xkshitizx/miti. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/xkshitizx/miti/blob/main/CODE_OF_CONDUCT.md).
|
30
55
|
|
31
56
|
## Code of Conduct
|
32
57
|
|
33
|
-
Everyone interacting in the Miti project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
58
|
+
Everyone interacting in the Miti project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/xkshitizx/miti/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/miti/ad_to_bs.rb
CHANGED
@@ -3,90 +3,82 @@
|
|
3
3
|
module Miti
|
4
4
|
# class to handle the algorithm for converting AD to BS
|
5
5
|
class AdToBs
|
6
|
+
##
|
7
|
+
# Initializes a AdToBs object
|
8
|
+
# @param @english_date [Date]
|
6
9
|
def initialize(english_date)
|
7
10
|
@english_date = english_date
|
8
|
-
@nepali_year = english_date.year + 56
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def mahina
|
26
|
-
days_passed = mahina_gatey[:days_passed_in_current_month]
|
27
|
-
current_month_max_day = mahina_gatey[:current_month_max_day]
|
28
|
-
probable_nepali_month = mahina_gatey[:probable_nepali_month]
|
29
|
-
return probable_nepali_month += 1 if days_passed.positive?
|
30
|
-
|
31
|
-
probable_nepali_month += 1 unless current_month_max_day.zero? || days_passed <= current_month_max_day
|
32
|
-
probable_nepali_month
|
33
|
-
end
|
34
|
-
|
35
|
-
def gatey
|
36
|
-
days_passed = mahina_gatey[:days_passed_in_current_month]
|
37
|
-
current_month_max_day = mahina_gatey[:current_month_max_day]
|
38
|
-
days_passed -= current_month_max_day if days_passed.positive? && days_passed > current_month_max_day
|
39
|
-
return days_passed if days_passed.positive?
|
40
|
-
|
41
|
-
return current_month_max_day - days_passed.abs if days_passed.negative?
|
42
|
-
|
43
|
-
current_month_max_day if days_passed.zero?
|
13
|
+
##
|
14
|
+
# Converts the @english_date to nepali date
|
15
|
+
#
|
16
|
+
# @return [Miti::NepaliDate]
|
17
|
+
def convert
|
18
|
+
year, month, day = nepali_date_for_new_year
|
19
|
+
# Jan 1 can be poush 16, 17 or 18. The gatey obtained has to be subtracted because
|
20
|
+
# days in month is added in days calculation and jan 1 is in mid poush.
|
21
|
+
day_count_from_poush1 = 1 - day
|
22
|
+
nepali_date = corresponding_nepali_date(year, month - 1, day_count_from_poush1)
|
23
|
+
Miti::NepaliDate.new(**nepali_date)
|
44
24
|
end
|
45
25
|
|
46
26
|
private
|
47
27
|
|
48
|
-
attr_reader :english_date
|
28
|
+
attr_reader :english_date
|
49
29
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
30
|
+
##
|
31
|
+
# Returns the corresponding **Nepali Date** for **Jan 1st**.
|
32
|
+
#
|
33
|
+
# @return Array, refers to [year, month, day] of nepali calendar
|
34
|
+
def nepali_date_for_new_year
|
35
|
+
year = english_date.year
|
36
|
+
jan_first_corresponding_gatey = Miti::Data::JAN_FIRST_CORRESPONDING_GATEY[year]
|
59
37
|
|
60
|
-
|
61
|
-
|
62
|
-
if remaining_days.zero?
|
63
|
-
total_days_in_nepali_year
|
64
|
-
else
|
65
|
-
remaining_days
|
66
|
-
end
|
38
|
+
# year is added by 56 and month is always 9(poush) for jan 1
|
39
|
+
[year + 56, 9, jan_first_corresponding_gatey]
|
67
40
|
end
|
68
41
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
def
|
78
|
-
|
42
|
+
##
|
43
|
+
# Returns corresponding nepali date for specific english date.
|
44
|
+
#
|
45
|
+
# @param **year**<Integer>, Refers to nepali year
|
46
|
+
# @param **start_month_index**<Integer>, Refers to index of month(eg: 1 for Baisakh)
|
47
|
+
# @param **day_count_from_poush1**<Integer>, Refers to number of days from poush
|
48
|
+
#
|
49
|
+
# @return [Hash], hash consisting (:barsa, :mahina, :gatey)
|
50
|
+
def corresponding_nepali_date(year, start_month_index, day_count_from_poush1)
|
51
|
+
# start_month_index can be 8(poush) or 0(baisakh)
|
52
|
+
nepali_year_month_hash[year][start_month_index..].each_with_index do |days_in_month, month_index|
|
53
|
+
# keep track of number of days counted
|
54
|
+
counted_days = day_count_from_poush1 + days_in_month
|
55
|
+
# keep iterating if counted days is less than days to count.
|
56
|
+
next day_count_from_poush1 += days_in_month if counted_days < days_to_count
|
57
|
+
|
58
|
+
# the day is days_in_month if counted and days to count are equal. Else extra days should be subtracted.
|
59
|
+
calculated_gatey = counted_days == days_to_count ? days_in_month : days_to_count - day_count_from_poush1
|
60
|
+
return { barsa: year, mahina: month_index + start_month_index + 1, gatey: calculated_gatey }
|
61
|
+
end
|
79
62
|
|
80
|
-
|
63
|
+
# If corresponding date does not lie within chaitra, method does not return from loop above.
|
64
|
+
# So, the method is recursively called with next year's new year date.
|
65
|
+
corresponding_nepali_date(year + 1, 0, day_count_from_poush1)
|
81
66
|
end
|
82
67
|
|
83
|
-
|
84
|
-
|
85
|
-
|
68
|
+
##
|
69
|
+
# Returns year_month hash from date_data
|
70
|
+
#
|
71
|
+
# @return Hash
|
72
|
+
def nepali_year_month_hash
|
73
|
+
@nepali_year_month_hash ||= Miti::Data::NEPALI_YEAR_MONTH_HASH
|
86
74
|
end
|
87
75
|
|
88
|
-
|
89
|
-
|
76
|
+
##
|
77
|
+
# Returns number specifying **Nth english date** after **Jan 1st** in specific year
|
78
|
+
#
|
79
|
+
# @return Integer
|
80
|
+
def days_to_count
|
81
|
+
@days_to_count ||= english_date.yday
|
90
82
|
end
|
91
83
|
end
|
92
84
|
end
|
data/lib/miti/bs_to_ad.rb
CHANGED
@@ -1,52 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "date"
|
4
|
-
|
5
3
|
module Miti
|
6
4
|
# class to handle the algorithm for converting AD to BS
|
7
5
|
class BsToAd
|
8
6
|
##
|
9
7
|
# Creating an object of BsToAd requires a Miti::NepaliDate object
|
10
8
|
#
|
11
|
-
#
|
9
|
+
# @param [Miti::NepaliDate]
|
12
10
|
def initialize(nepali_date)
|
13
|
-
@
|
14
|
-
@mahina = nepali_date.mahina
|
15
|
-
@gatey = nepali_date.gatey
|
11
|
+
@nepali_date = nepali_date
|
16
12
|
end
|
17
13
|
|
14
|
+
# Return equivalent english date for nepali date
|
18
15
|
def convert
|
19
|
-
|
16
|
+
corresponding_ad_for_baisakh1 + days_to_be_added_from_baisakh1
|
20
17
|
end
|
21
18
|
|
22
19
|
private
|
23
20
|
|
24
|
-
attr_reader :
|
21
|
+
attr_reader :nepali_date
|
25
22
|
|
26
23
|
##
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
date_range.each do |date|
|
34
|
-
return date if Miti::AdToBs.new(date).convert(to_h: true) ==
|
35
|
-
{ barsa: barsa, mahina: mahina, gatey: gatey }
|
36
|
-
end
|
37
|
-
raise "Failed to convert."
|
24
|
+
# Returns corresponding AD for baisakh first of nepali year
|
25
|
+
def corresponding_ad_for_baisakh1
|
26
|
+
current_year = nepali_date.barsa
|
27
|
+
baisakh1_corresponding_ad = Miti::Data::BAISHKH_FIRST_CORRESPONDING_APRIL[current_year]
|
28
|
+
# AD is 57 years ahead of BS and always in April
|
29
|
+
Date.new(current_year - 57, 4, baisakh1_corresponding_ad)
|
38
30
|
end
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
# The average gap between nepali year and english date is 20,711 days considering the numericality of months.
|
43
|
-
# This method creates new english date with year/month/day value equal to Nepali date and subtracts by 20,711
|
44
|
-
# and returns the range of date around it.
|
45
|
-
#
|
46
|
-
# return []<Date>
|
47
|
-
def date_range(range = 8)
|
48
|
-
probable_english_date = Date.new(barsa, mahina, gatey) - 20_711
|
49
|
-
probable_english_date.prev_day(range)..probable_english_date.next_day(range)
|
32
|
+
def days_to_be_added_from_baisakh1
|
33
|
+
nepali_date.yday - 1
|
50
34
|
end
|
51
35
|
end
|
52
36
|
end
|
data/lib/miti/data/date_data.rb
CHANGED
@@ -1,139 +1,394 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Miti
|
4
|
-
module Data
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
4
|
+
module Data # rubocop:disable Metrics/ModuleLength
|
5
|
+
# date reference https://github.com/dxillar/nepali-datetime/blob/master/nepali_datetime/data/calendar_bs.csv
|
6
|
+
NEPALI_YEAR_MONTH_HASH = {
|
7
|
+
1975 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
8
|
+
1976 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
9
|
+
1977 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
10
|
+
1978 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
11
|
+
1979 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
12
|
+
1980 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
13
|
+
1981 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
14
|
+
1982 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
15
|
+
1983 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
16
|
+
1984 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
17
|
+
1985 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
18
|
+
1986 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
19
|
+
1987 => [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
20
|
+
1988 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
21
|
+
1989 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
22
|
+
1990 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
23
|
+
1991 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
24
|
+
1992 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
25
|
+
1993 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
26
|
+
1994 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
27
|
+
1995 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
28
|
+
1996 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
29
|
+
1997 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
30
|
+
1998 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
31
|
+
1999 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
32
|
+
2000 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
33
|
+
2001 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
34
|
+
2002 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
35
|
+
2003 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
36
|
+
2004 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
37
|
+
2005 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
38
|
+
2006 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
39
|
+
2007 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
40
|
+
2008 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
41
|
+
2009 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
42
|
+
2010 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
43
|
+
2011 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
44
|
+
2012 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
45
|
+
2013 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
46
|
+
2014 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
47
|
+
2015 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
48
|
+
2016 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
49
|
+
2017 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
50
|
+
2018 => [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
51
|
+
2019 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
52
|
+
2020 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
53
|
+
2021 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
54
|
+
2022 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
55
|
+
2023 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
56
|
+
2024 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
57
|
+
2025 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
58
|
+
2026 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
59
|
+
2027 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
60
|
+
2028 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
61
|
+
2029 => [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
|
62
|
+
2030 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
63
|
+
2031 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
64
|
+
2032 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
65
|
+
2033 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
66
|
+
2034 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
67
|
+
2035 => [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
68
|
+
2036 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
69
|
+
2037 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
70
|
+
2038 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
71
|
+
2039 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
72
|
+
2040 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
73
|
+
2041 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
74
|
+
2042 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
75
|
+
2043 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
76
|
+
2044 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
77
|
+
2045 => [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
78
|
+
2046 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
79
|
+
2047 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
80
|
+
2048 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
81
|
+
2049 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
82
|
+
2050 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
83
|
+
2051 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
84
|
+
2052 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
85
|
+
2053 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
86
|
+
2054 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
87
|
+
2055 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
88
|
+
2056 => [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
|
89
|
+
2057 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
90
|
+
2058 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
91
|
+
2059 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
92
|
+
2060 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
93
|
+
2061 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
94
|
+
2062 => [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31],
|
95
|
+
2063 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
96
|
+
2064 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
97
|
+
2065 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
98
|
+
2066 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
99
|
+
2067 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
100
|
+
2068 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
101
|
+
2069 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
102
|
+
2070 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
103
|
+
2071 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
104
|
+
2072 => [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
105
|
+
2073 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
106
|
+
2074 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
107
|
+
2075 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
108
|
+
2076 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
109
|
+
2077 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
110
|
+
2078 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
111
|
+
2079 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
112
|
+
2080 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
113
|
+
2081 => [31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
114
|
+
2082 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
115
|
+
2083 => [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
116
|
+
2084 => [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
117
|
+
2085 => [31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
118
|
+
2086 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
119
|
+
2087 => [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
|
120
|
+
2088 => [30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
121
|
+
2089 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
122
|
+
2090 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
123
|
+
2091 => [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
|
124
|
+
2092 => [30, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
125
|
+
2093 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
126
|
+
2094 => [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
127
|
+
2095 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30],
|
128
|
+
2096 => [30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
129
|
+
2097 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
130
|
+
2098 => [31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 29, 31],
|
131
|
+
2099 => [31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30],
|
132
|
+
2100 => [31, 32, 31, 32, 30, 31, 30, 29, 30, 29, 30, 30]
|
133
|
+
}.freeze
|
134
|
+
|
135
|
+
# scraped from https://www.ashesh.com.np/nepali-date-converter.php
|
136
|
+
BAISHKH_FIRST_CORRESPONDING_APRIL = {
|
137
|
+
1975 => 13,
|
138
|
+
1976 => 13,
|
139
|
+
1977 => 13,
|
140
|
+
1978 => 13,
|
141
|
+
1979 => 13,
|
142
|
+
1980 => 13,
|
143
|
+
1981 => 13,
|
144
|
+
1982 => 13,
|
145
|
+
1983 => 13,
|
146
|
+
1984 => 13,
|
147
|
+
1985 => 13,
|
148
|
+
1986 => 13,
|
149
|
+
1987 => 13,
|
150
|
+
1988 => 13,
|
151
|
+
1989 => 13,
|
152
|
+
1990 => 13,
|
153
|
+
1991 => 13,
|
154
|
+
1992 => 13,
|
155
|
+
1993 => 13,
|
156
|
+
1994 => 13,
|
157
|
+
1995 => 13,
|
158
|
+
1996 => 13,
|
159
|
+
1997 => 13,
|
160
|
+
1998 => 13,
|
161
|
+
1999 => 13,
|
162
|
+
2000 => 14,
|
163
|
+
2001 => 13,
|
164
|
+
2002 => 13,
|
165
|
+
2003 => 13,
|
166
|
+
2004 => 14,
|
167
|
+
2005 => 13,
|
168
|
+
2006 => 13,
|
169
|
+
2007 => 13,
|
170
|
+
2008 => 14,
|
171
|
+
2009 => 13,
|
172
|
+
2010 => 13,
|
173
|
+
2011 => 13,
|
174
|
+
2012 => 14,
|
175
|
+
2013 => 13,
|
176
|
+
2014 => 13,
|
177
|
+
2015 => 13,
|
178
|
+
2016 => 14,
|
179
|
+
2017 => 13,
|
180
|
+
2018 => 13,
|
181
|
+
2019 => 13,
|
182
|
+
2020 => 14,
|
183
|
+
2021 => 13,
|
184
|
+
2022 => 13,
|
185
|
+
2023 => 13,
|
186
|
+
2024 => 14,
|
187
|
+
2025 => 13,
|
188
|
+
2026 => 13,
|
189
|
+
2027 => 14,
|
190
|
+
2028 => 14,
|
191
|
+
2029 => 13,
|
192
|
+
2030 => 13,
|
193
|
+
2031 => 14,
|
194
|
+
2032 => 14,
|
195
|
+
2033 => 13,
|
196
|
+
2034 => 13,
|
197
|
+
2035 => 14,
|
198
|
+
2036 => 14,
|
199
|
+
2037 => 13,
|
200
|
+
2038 => 13,
|
201
|
+
2039 => 14,
|
202
|
+
2040 => 14,
|
203
|
+
2041 => 13,
|
204
|
+
2042 => 13,
|
205
|
+
2043 => 14,
|
206
|
+
2044 => 14,
|
207
|
+
2045 => 13,
|
208
|
+
2046 => 13,
|
209
|
+
2047 => 14,
|
210
|
+
2048 => 14,
|
211
|
+
2049 => 13,
|
212
|
+
2050 => 13,
|
213
|
+
2051 => 14,
|
214
|
+
2052 => 14,
|
215
|
+
2053 => 13,
|
216
|
+
2054 => 13,
|
217
|
+
2055 => 14,
|
218
|
+
2056 => 14,
|
219
|
+
2057 => 13,
|
220
|
+
2058 => 14,
|
221
|
+
2059 => 14,
|
222
|
+
2060 => 14,
|
223
|
+
2061 => 13,
|
224
|
+
2062 => 14,
|
225
|
+
2063 => 14,
|
226
|
+
2064 => 14,
|
227
|
+
2065 => 13,
|
228
|
+
2066 => 14,
|
229
|
+
2067 => 14,
|
230
|
+
2068 => 14,
|
231
|
+
2069 => 13,
|
232
|
+
2070 => 14,
|
233
|
+
2071 => 14,
|
234
|
+
2072 => 14,
|
235
|
+
2073 => 13,
|
236
|
+
2074 => 14,
|
237
|
+
2075 => 14,
|
238
|
+
2076 => 14,
|
239
|
+
2077 => 13,
|
240
|
+
2078 => 14,
|
241
|
+
2079 => 14,
|
242
|
+
2080 => 14,
|
243
|
+
2081 => 13,
|
244
|
+
2082 => 14,
|
245
|
+
2083 => 14,
|
246
|
+
2084 => 14,
|
247
|
+
2085 => 14,
|
248
|
+
2086 => 14,
|
249
|
+
2087 => 14,
|
250
|
+
2088 => 14,
|
251
|
+
2089 => 14,
|
252
|
+
2090 => 14,
|
253
|
+
2091 => 14,
|
254
|
+
2092 => 14,
|
255
|
+
2093 => 14,
|
256
|
+
2094 => 14,
|
257
|
+
2095 => 14,
|
258
|
+
2096 => 14,
|
259
|
+
2097 => 14,
|
260
|
+
2098 => 14,
|
261
|
+
2099 => 14,
|
262
|
+
2100 => 14
|
263
|
+
}.freeze
|
264
|
+
|
265
|
+
JAN_FIRST_CORRESPONDING_GATEY = {
|
266
|
+
1919 => 18,
|
267
|
+
1920 => 17,
|
268
|
+
1921 => 18,
|
269
|
+
1922 => 18,
|
270
|
+
1923 => 18,
|
271
|
+
1924 => 17,
|
272
|
+
1925 => 18,
|
273
|
+
1926 => 18,
|
274
|
+
1927 => 18,
|
275
|
+
1928 => 17,
|
276
|
+
1929 => 18,
|
277
|
+
1930 => 18,
|
278
|
+
1931 => 18,
|
279
|
+
1932 => 17,
|
280
|
+
1933 => 18,
|
281
|
+
1934 => 18,
|
282
|
+
1935 => 17,
|
283
|
+
1936 => 17,
|
284
|
+
1937 => 18,
|
285
|
+
1938 => 18,
|
286
|
+
1939 => 17,
|
287
|
+
1940 => 17,
|
288
|
+
1941 => 18,
|
289
|
+
1942 => 18,
|
290
|
+
1943 => 17,
|
291
|
+
1944 => 17,
|
292
|
+
1945 => 18,
|
293
|
+
1946 => 18,
|
294
|
+
1947 => 17,
|
295
|
+
1948 => 17,
|
296
|
+
1949 => 18,
|
297
|
+
1950 => 18,
|
298
|
+
1951 => 17,
|
299
|
+
1952 => 17,
|
300
|
+
1953 => 18,
|
301
|
+
1954 => 18,
|
302
|
+
1955 => 17,
|
303
|
+
1956 => 17,
|
304
|
+
1957 => 18,
|
305
|
+
1958 => 18,
|
306
|
+
1959 => 17,
|
307
|
+
1960 => 17,
|
308
|
+
1961 => 18,
|
309
|
+
1962 => 18,
|
310
|
+
1963 => 17,
|
311
|
+
1964 => 17,
|
312
|
+
1965 => 18,
|
313
|
+
1966 => 17,
|
314
|
+
1967 => 17,
|
315
|
+
1968 => 17,
|
316
|
+
1969 => 18,
|
317
|
+
1970 => 17,
|
318
|
+
1971 => 17,
|
319
|
+
1972 => 17,
|
320
|
+
1973 => 18,
|
321
|
+
1974 => 17,
|
322
|
+
1975 => 17,
|
323
|
+
1976 => 17,
|
324
|
+
1977 => 18,
|
325
|
+
1978 => 17,
|
326
|
+
1979 => 17,
|
327
|
+
1980 => 17,
|
328
|
+
1981 => 18,
|
329
|
+
1982 => 17,
|
330
|
+
1983 => 17,
|
331
|
+
1984 => 17,
|
332
|
+
1985 => 18,
|
333
|
+
1986 => 17,
|
334
|
+
1987 => 17,
|
335
|
+
1988 => 17,
|
336
|
+
1989 => 18,
|
337
|
+
1990 => 17,
|
338
|
+
1991 => 17,
|
339
|
+
1992 => 17,
|
340
|
+
1993 => 17,
|
341
|
+
1994 => 17,
|
342
|
+
1995 => 17,
|
343
|
+
1996 => 17,
|
344
|
+
1997 => 17,
|
345
|
+
1998 => 17,
|
346
|
+
1999 => 17,
|
347
|
+
2000 => 17,
|
348
|
+
2001 => 17,
|
349
|
+
2002 => 17,
|
350
|
+
2003 => 17,
|
351
|
+
2004 => 17,
|
352
|
+
2005 => 17,
|
353
|
+
2006 => 17,
|
354
|
+
2007 => 17,
|
355
|
+
2008 => 17,
|
356
|
+
2009 => 17,
|
357
|
+
2010 => 17,
|
358
|
+
2011 => 17,
|
359
|
+
2012 => 17,
|
360
|
+
2013 => 17,
|
361
|
+
2014 => 17,
|
362
|
+
2015 => 17,
|
363
|
+
2016 => 17,
|
364
|
+
2017 => 17,
|
365
|
+
2018 => 17,
|
366
|
+
2019 => 17,
|
367
|
+
2020 => 16,
|
368
|
+
2021 => 17,
|
369
|
+
2022 => 17,
|
370
|
+
2023 => 17,
|
371
|
+
2024 => 16,
|
372
|
+
2025 => 17,
|
373
|
+
2026 => 17,
|
374
|
+
2027 => 17,
|
375
|
+
2028 => 16,
|
376
|
+
2029 => 17,
|
377
|
+
2030 => 17,
|
378
|
+
2031 => 17,
|
379
|
+
2032 => 16,
|
380
|
+
2033 => 17,
|
381
|
+
2034 => 17,
|
382
|
+
2035 => 17,
|
383
|
+
2036 => 16,
|
384
|
+
2037 => 17,
|
385
|
+
2038 => 17,
|
386
|
+
2039 => 17,
|
387
|
+
2040 => 16,
|
388
|
+
2041 => 17,
|
389
|
+
2042 => 17,
|
390
|
+
2043 => 17,
|
391
|
+
2044 => 16
|
392
|
+
}.freeze
|
138
393
|
end
|
139
394
|
end
|
data/lib/miti/nepali_date.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative "data/date_data"
|
|
5
5
|
module Miti
|
6
6
|
# Class for nepali date
|
7
7
|
class NepaliDate
|
8
|
+
class InvalidSeparatorError < StandardError; end
|
8
9
|
attr_reader :barsa, :mahina, :gatey
|
9
10
|
|
10
11
|
##
|
@@ -18,7 +19,7 @@ module Miti
|
|
18
19
|
##
|
19
20
|
# Get equivalent tarik(AD) for NepaliDate
|
20
21
|
#
|
21
|
-
# return Date
|
22
|
+
# @return [Date]
|
22
23
|
def tarik
|
23
24
|
@tarik ||= BsToAd.new(self).convert
|
24
25
|
end
|
@@ -26,7 +27,7 @@ module Miti
|
|
26
27
|
##
|
27
28
|
# Get weekday for a nepali date.
|
28
29
|
#
|
29
|
-
#
|
30
|
+
# @return [Integer](0-6) that represents weekdays starting from 0.
|
30
31
|
def bar
|
31
32
|
@bar ||= tarik&.wday
|
32
33
|
end
|
@@ -34,7 +35,7 @@ module Miti
|
|
34
35
|
##
|
35
36
|
# returns details of nepali date in a ruby Hash
|
36
37
|
#
|
37
|
-
#
|
38
|
+
# @return [Hash]
|
38
39
|
def to_h
|
39
40
|
{ barsa: barsa, mahina: mahina, gatey: gatey, bar: bar, tarik: tarik }
|
40
41
|
end
|
@@ -42,14 +43,14 @@ module Miti
|
|
42
43
|
##
|
43
44
|
# Returns Nepali Date in string format(yyyy/mm/dd).
|
44
45
|
#
|
45
|
-
#
|
46
|
+
# @param separator(- by default)
|
46
47
|
#
|
47
|
-
#
|
48
|
-
def to_s(
|
49
|
-
|
48
|
+
# @return [String]
|
49
|
+
def to_s(separator: "-")
|
50
|
+
raise InvalidSeparatorError, "Invalid separator provided." unless [" ", "/", "-"].include?(separator)
|
50
51
|
|
51
52
|
[barsa, mahina, gatey].reduce("") do |final_date, date_element|
|
52
|
-
"#{final_date}#{final_date.
|
53
|
+
"#{final_date}#{final_date.empty? ? "" : separator}#{date_element < 10 ? 0 : ""}#{date_element}"
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
@@ -57,7 +58,7 @@ module Miti
|
|
57
58
|
# Descriptive output for current date
|
58
59
|
# When nepali flag is true, month is returned in nepali font and week day in Nepali
|
59
60
|
#
|
60
|
-
#
|
61
|
+
# @return [String]
|
61
62
|
def descriptive(nepali: false)
|
62
63
|
month_index = mahina - 1
|
63
64
|
if nepali
|
@@ -72,11 +73,15 @@ module Miti
|
|
72
73
|
end
|
73
74
|
|
74
75
|
def yday
|
75
|
-
days_before_month = Miti::Data::
|
76
|
+
days_before_month = Miti::Data::NEPALI_YEAR_MONTH_HASH[barsa].first(mahina - 1).sum
|
76
77
|
days_before_month + gatey
|
77
78
|
end
|
78
79
|
|
79
80
|
class << self
|
81
|
+
def today
|
82
|
+
AdToBs.new(Date.today).convert
|
83
|
+
end
|
84
|
+
|
80
85
|
def week_days
|
81
86
|
%w[आइतबार सोमबार मंगलबार बुधबार बिहिबार शुक्रबार शनिबार]
|
82
87
|
end
|
@@ -96,12 +101,12 @@ module Miti
|
|
96
101
|
##
|
97
102
|
# This method parses date in yyyy/mm/dd to NepaliDate object
|
98
103
|
#
|
99
|
-
#
|
104
|
+
# @return [Miti::NepaliDate]
|
100
105
|
def parse(date_string)
|
101
|
-
regex = %r{\A\d{4}[
|
106
|
+
regex = %r{\A\d{4}[,-/\s]\d{1,2}[,-/\s]\d{1,2}\z}
|
102
107
|
raise "Invalid Date Format" unless regex.match(date_string)
|
103
108
|
|
104
|
-
delimiters = ["-", " ", "/"]
|
109
|
+
delimiters = ["-", " ", "/", ","]
|
105
110
|
barsa, mahina, gatey = date_string.split(Regexp.union(delimiters))
|
106
111
|
validate_parsed_date(barsa.to_i, mahina.to_i, gatey.to_i)
|
107
112
|
NepaliDate.new(barsa: barsa.to_i, mahina: mahina.to_i, gatey: gatey.to_i)
|
@@ -112,7 +117,7 @@ module Miti
|
|
112
117
|
def validate_parsed_date(barsa, mahina, gatey)
|
113
118
|
raise "Mahina can't be greater than 12" if mahina > 12
|
114
119
|
|
115
|
-
max_day_of_month = Miti::Data::
|
120
|
+
max_day_of_month = Miti::Data::NEPALI_YEAR_MONTH_HASH[barsa][mahina - 1]
|
116
121
|
|
117
122
|
return unless max_day_of_month < gatey
|
118
123
|
|
data/lib/miti/version.rb
CHANGED
data/lib/miti.rb
CHANGED
@@ -4,12 +4,17 @@ require "date"
|
|
4
4
|
require_relative "miti/ad_to_bs"
|
5
5
|
require_relative "miti/bs_to_ad"
|
6
6
|
require_relative "miti/nepali_date"
|
7
|
+
require_relative "miti/data/date_data"
|
7
8
|
|
8
9
|
# Base module for the gem
|
9
10
|
module Miti
|
10
11
|
class Error < StandardError; end
|
11
12
|
|
12
13
|
class << self
|
14
|
+
##
|
15
|
+
# This method converts the provided english date to nepali date
|
16
|
+
# @param english_date [String], refers to date in string format
|
17
|
+
# @return [<Miti::NepaliDate>], refers to the converted nepali date
|
13
18
|
def to_bs(english_date)
|
14
19
|
date = parse_english_date(english_date)
|
15
20
|
Miti::AdToBs.new(date).convert
|
@@ -17,6 +22,10 @@ module Miti
|
|
17
22
|
"Invalid Date"
|
18
23
|
end
|
19
24
|
|
25
|
+
##
|
26
|
+
# This method converts the provided nepali date to english date
|
27
|
+
# @param nepali_date [String], refers to date in string format
|
28
|
+
# @return [<Date>], refers to the converted english date from nepali date
|
20
29
|
def to_ad(nepali_date)
|
21
30
|
date = parse_nepali_date(nepali_date)
|
22
31
|
Miti::BsToAd.new(date).convert
|
@@ -24,6 +33,12 @@ module Miti
|
|
24
33
|
|
25
34
|
private
|
26
35
|
|
36
|
+
##
|
37
|
+
# This method parses the provided parameter english date to Date object
|
38
|
+
# It checks the class of the parameter and returns the Date object accordingly
|
39
|
+
# @param english_date [String], refers to date in string format OR
|
40
|
+
# @param english_date [Date], refers to date object
|
41
|
+
# @return [<Date>], refers to Date object
|
27
42
|
def parse_english_date(english_date)
|
28
43
|
klass = english_date.class.to_s
|
29
44
|
|
@@ -36,6 +51,12 @@ module Miti
|
|
36
51
|
end
|
37
52
|
end
|
38
53
|
|
54
|
+
##
|
55
|
+
# This method parses the provided parameter nepali_date to Miti::NepaliDate object
|
56
|
+
# It checks the class of the parameter and returns the Miti::NepaliDate object accordingly
|
57
|
+
# @param nepali_date [String], refers to date in string format OR
|
58
|
+
# @param nepali_date [Miti::NepaliDate ], refers to date object
|
59
|
+
# @return [<Date>], refers to Date object
|
39
60
|
def parse_nepali_date(nepali_date)
|
40
61
|
klass = nepali_date.class.to_s
|
41
62
|
|
data/miti.gemspec
CHANGED
@@ -8,14 +8,14 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.email = %w[kshitizlama03@gmail.com sanzaymanandhar99@gmail.com]
|
9
9
|
|
10
10
|
spec.summary = "Date converter BS to AD and vice-versa."
|
11
|
-
spec.description = "
|
12
|
-
|
11
|
+
spec.description = "Convert English date(AD) to Nepali date(BS) and vice-versa."
|
12
|
+
spec.homepage = "https://github.com/xkshitizx/miti"
|
13
13
|
spec.required_ruby_version = ">= 2.6.0"
|
14
14
|
|
15
15
|
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
spec.metadata["homepage_uri"] = "https://github.com/xkshitizx/miti"
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/xkshitizx/miti"
|
19
19
|
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
20
|
spec.metadata = { "rubygems_mfa_required" => "true" }
|
21
21
|
# Specify which files should be added to the gem when it is released.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xkshitizx
|
@@ -9,10 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-06-01 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
15
|
-
in AD to Nepali Date(BS).
|
14
|
+
description: Convert English date(AD) to Nepali date(BS) and vice-versa.
|
16
15
|
email:
|
17
16
|
- kshitizlama03@gmail.com
|
18
17
|
- sanzaymanandhar99@gmail.com
|
@@ -22,6 +21,7 @@ extra_rdoc_files: []
|
|
22
21
|
files:
|
23
22
|
- CHANGELOG.md
|
24
23
|
- Gemfile
|
24
|
+
- LICENSE
|
25
25
|
- README.md
|
26
26
|
- Rakefile
|
27
27
|
- lib/miti.rb
|
@@ -31,7 +31,7 @@ files:
|
|
31
31
|
- lib/miti/nepali_date.rb
|
32
32
|
- lib/miti/version.rb
|
33
33
|
- miti.gemspec
|
34
|
-
homepage:
|
34
|
+
homepage: https://github.com/xkshitizx/miti
|
35
35
|
licenses:
|
36
36
|
- MIT
|
37
37
|
metadata:
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '0'
|
53
53
|
requirements: []
|
54
|
-
rubygems_version: 3.3.
|
54
|
+
rubygems_version: 3.3.3
|
55
55
|
signing_key:
|
56
56
|
specification_version: 4
|
57
57
|
summary: Date converter BS to AD and vice-versa.
|