miti 0.0.3 → 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
2
  SHA256:
3
- metadata.gz: f1f30a2d951f109ab5cdc4a290dec5dde6dcbeabd97a68217056c93751cca658
4
- data.tar.gz: 21a30dcc1e05e5d9c3c38dbf24a9a2507c6ec096504a93ec5de83af9ba210140
3
+ metadata.gz: 44383837579fa3f0fbca4203616117938adfcc02a39d383d448ec5a8d8fc3a6b
4
+ data.tar.gz: 9f9b9415bd30a4cb3c7007bf531f04f44173a2cd1a28afa901431f69026880d7
5
5
  SHA512:
6
- metadata.gz: 577e91a616bc035f388939c883373666f7b514b030a16b1918747b1f3e48ecd11b149ee8246fa77235fd1343135a3ef9e4226602b1c57c65a86c11a3e734b8d7
7
- data.tar.gz: 3efe7397bfa2198b7d8489a1776344190e826694f4487f2be1cf225c49ff9c06560afeb3152d04662db8636af0d7b7a676cc0697eb9d39f382d74ee5a189039a
6
+ metadata.gz: 8436ce93a8ba9b3fe57387ec6c6e240b821665e37a052dadf6ae87bfbfd477a7a5c2c37a1fbb351a7e13e5db900d684ae5c0a91124631e9f4bef3e4f8aaa63ed
7
+ data.tar.gz: 2c4efc488ab171d0765c78f65707ea66296a8affa5f39564747f0835d448717845b27676168b84152c91cb89035b8d04ab1dbef51c5531470dec191b2704d978
data/CHANGELOG.md CHANGED
@@ -3,3 +3,13 @@
3
3
  ## [0.0.1] - 2022-09-24
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.1.0] - 2023-05-21
8
+ - Change Class method to constant for fetching date. Add corresponding date for Baisakh 1 and Jan 1.
9
+ - Simplify logic for AD to BS conversion
10
+ - Refactor and add comments
11
+
12
+ ## [1.0.0] - 2023-06-27
13
+ - New release 1.0.0
14
+ - Integrate Miti CLI
15
+ - Miti CLI now accepts arguments for date conversion
data/Gemfile CHANGED
@@ -13,4 +13,6 @@ gem "rubocop", "~> 1.21"
13
13
 
14
14
  gem "byebug"
15
15
 
16
+ gem "thor"
17
+
16
18
  gem "simplecov"
data/exe/miti ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "miti"
6
+ require_relative "../lib/cli"
7
+
8
+ Miti::CLI.start(ARGV)
data/lib/cli.rb ADDED
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require "date"
5
+ require_relative "miti"
6
+
7
+ module Miti
8
+ # class to integrate CLI
9
+ class CLI < Thor
10
+ def initialize(*args)
11
+ super
12
+ @shell = Thor::Shell::Color.new
13
+ @output_color = :green
14
+ end
15
+
16
+ desc "today", "today's nepali miti"
17
+ def today
18
+ date = Date.today
19
+ current_nepali_miti = Miti.to_bs(date.to_s)
20
+ formatted_miti = "[#{current_nepali_miti} BS] #{current_nepali_miti.descriptive}"
21
+ formatted_date = "[#{date} AD] " + date.strftime("%B %d, %Y %A")
22
+
23
+ @shell.say("#{formatted_miti}\n#{formatted_date}", :green)
24
+ end
25
+
26
+ desc "on ENGLISH_DATE", "converts english date to nepali miti"
27
+ def to_bs(english_date)
28
+ converted_nepali_miti = Miti.to_bs(english_date)
29
+ output_txt = "[#{converted_nepali_miti} BS] #{converted_nepali_miti.descriptive}"
30
+ rescue ConversionUnavailableError => e
31
+ output_txt = e
32
+ @output_color = :red
33
+ ensure
34
+ @shell.say(output_txt, @output_color)
35
+ end
36
+
37
+ desc "to NEPALI_DATE", "converts nepali miti to english date"
38
+ def to_ad(nepali_date)
39
+ converted_english_date = Miti.to_ad(nepali_date)
40
+ output_txt = "[#{converted_english_date} AD] #{converted_english_date.strftime("%B %d, %Y %A")}"
41
+ rescue ConversionUnavailableError => e
42
+ output_txt = e
43
+ @output_color = :red
44
+ ensure
45
+ @shell.say(output_txt, @output_color)
46
+ end
47
+
48
+ no_commands do
49
+ def self.exit_on_failure?
50
+ true
51
+ end
52
+ end
53
+ end
54
+ end
data/lib/miti/ad_to_bs.rb CHANGED
@@ -6,138 +6,79 @@ module Miti
6
6
  ##
7
7
  # Initializes a AdToBs object
8
8
  # @param @english_date [Date]
9
- #
10
9
  def initialize(english_date)
11
10
  @english_date = english_date
12
- @nepali_year = english_date.year + 56
13
11
  end
14
12
 
15
13
  ##
16
14
  # Converts the @english_date to nepali date
17
- # @param to_h [boolean], default set to false
18
- #
19
- # @return <NepaliDate>, refers to converted nepali date object
20
- # @return [Hash], hash consisting (:barsa, :mahina, :gatey) if @params to_h is true
21
- def convert(to_h: false)
22
- return NepaliDate.new(barsa: final_nepali_year_month_value[:year], mahina: mahina, gatey: gatey) unless to_h
23
-
24
- { barsa: final_nepali_year_month_value[:year], mahina: mahina, gatey: gatey }
25
- end
26
-
27
- ##
28
- # Calculates the nepalese year and month respectively
29
- # determines the difference of nepali_nth_day and total_days_in_nepali_year
30
- #
31
- # if the difference is positive
32
- # - month -> @english_date's month - 4 = nepali_month
33
- # - year -> @english_date's year + 1 = nepali year
34
15
  #
35
- # if negative
36
- # - month -> @english_date's month + 8 = nepali_month
37
- # - year -> @english_date's year = nepali year
38
- #
39
- # @return [Hash],which includes (:year,:month) *[converted to nepali]*
40
- def final_nepali_year_month_value
41
- @final_nepali_year_month_value = if (nepali_nth_day - total_days_in_nepali_year).positive?
42
- { year: nepali_year + 1, month: english_date.month - 4 }
43
- else
44
- { year: nepali_year, month: english_date.month + 8 }
45
- end
46
- end
47
-
48
- def mahina
49
- days_passed = mahina_gatey[:days_passed_in_current_month]
50
- current_month_max_day = mahina_gatey[:current_month_max_day]
51
- probable_nepali_month = mahina_gatey[:probable_nepali_month]
52
- return probable_nepali_month += 1 if days_passed.positive?
53
-
54
- probable_nepali_month += 1 unless current_month_max_day.zero? || days_passed <= current_month_max_day
55
- probable_nepali_month
56
- end
57
-
58
- def gatey
59
- days_passed = mahina_gatey[:days_passed_in_current_month]
60
- current_month_max_day = mahina_gatey[:current_month_max_day]
61
- days_passed -= current_month_max_day if days_passed.positive? && days_passed > current_month_max_day
62
- return days_passed if days_passed.positive?
63
-
64
- return current_month_max_day - days_passed.abs if days_passed.negative?
65
-
66
- current_month_max_day if days_passed.zero?
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)
67
24
  end
68
25
 
69
26
  private
70
27
 
71
- attr_reader :english_date, :nepali_year
72
-
73
- def mahina_gatey
74
- @mahina_gatey ||= begin
75
- probable_nepali_month = final_nepali_year_month_value[:month]
76
- month_max_days_upto_current = year_data[final_nepali_year_month_value[:year]].first(probable_nepali_month)
77
- { probable_nepali_month: probable_nepali_month,
78
- days_passed_in_current_month: remaining_days_in_nepali_year - month_max_days_upto_current.sum,
79
- current_month_max_day: month_max_days_upto_current[probable_nepali_month - 1] || 0 }
80
- end
81
- end
28
+ attr_reader :english_date
82
29
 
83
30
  ##
84
- # Calculates the remaining days in a specific year
85
- # by retrieving the modulo of nepali_nth_day to total_days_in_nepali_year
86
- # - nepali_nth_day -> number of days from 1st Jan
87
- # - total_days_in_nepali_year -> number of days in specific nepali year
31
+ # Returns the corresponding **Nepali Date** for **Jan 1st**.
88
32
  #
89
- # @return [Integer], refers to number of days remaining in nepali year
90
- def remaining_days_in_nepali_year
91
- remaining_days = nepali_nth_day % total_days_in_nepali_year
92
- if remaining_days.zero?
93
- total_days_in_nepali_year
94
- else
95
- remaining_days
96
- end
97
- end
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]
98
37
 
99
- ##
100
- # Calculates the total number of days in a specific year
101
- #
102
- # @return [Integer], refers to the total number of days
103
- def total_days_in_nepali_year
104
- @total_days_in_nepali_year ||= year_data[nepali_year].sum
38
+ # year is added by 56 and month is always 9(poush) for jan 1
39
+ [year + 56, 9, jan_first_corresponding_gatey]
105
40
  end
106
41
 
107
42
  ##
108
- # Calculates the number of days in nepali year as on from Jan 1st
43
+ # Returns corresponding nepali date for specific english date.
109
44
  #
110
- # @return [Integer], refers to number of days
111
- def nepali_nth_day
112
- @nepali_nth_day = english_date.yday + nepali_nth_day_for_english_new_year - 1
113
- end
114
-
115
- ##
116
- # Determines the number of days from Jan 1st to Baisakh 1st, for leap years
117
- # - 263 days for normal year
118
- # - 264 days for year following the leap years
119
- # @return [Integer], refers to the number of days
120
- def nepali_nth_day_for_english_new_year
121
- return 264 if year_after_leap_year?
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
122
62
 
123
- 263
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)
124
66
  end
125
67
 
126
68
  ##
127
- # Checks the previous year of @english_date from params is leap year or not?
69
+ # Returns year_month hash from date_data
128
70
  #
129
- # @return [Boolean], refers previous year is whether leap year or not
130
- def year_after_leap_year?
131
- year_before = english_date.year - 1
132
- (year_before % 400).zero? || (year_before % 100 != 0 && (year_before % 4).zero?)
71
+ # @return Hash
72
+ def nepali_year_month_hash
73
+ @nepali_year_month_hash ||= Miti::Data::NEPALI_YEAR_MONTH_HASH
133
74
  end
134
75
 
135
76
  ##
136
- # Calls DateData class to retrieve the nepali date data consisting total no of days, month
77
+ # Returns number specifying **Nth english date** after **Jan 1st** in specific year
137
78
  #
138
- # @return [Hash], refers to hash object consisting the nepali date data
139
- def year_data
140
- @year_data = Miti::Data::DateData.year_month_days_hash
79
+ # @return Integer
80
+ def days_to_count
81
+ @days_to_count ||= english_date.yday
141
82
  end
142
83
  end
143
84
  end
data/lib/miti/bs_to_ad.rb CHANGED
@@ -1,7 +1,5 @@
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
@@ -10,43 +8,29 @@ module Miti
10
8
  #
11
9
  # @param [Miti::NepaliDate]
12
10
  def initialize(nepali_date)
13
- @barsa = nepali_date.barsa
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
- english_date
16
+ corresponding_ad_for_baisakh1 + days_to_be_added_from_baisakh1
20
17
  end
21
18
 
22
19
  private
23
20
 
24
- attr_reader :barsa, :mahina, :gatey
21
+ attr_reader :nepali_date
25
22
 
26
23
  ##
27
- # Iterates through range of dates close to probable english date and checks to get exact english_date
28
- # Incase the date is not found, error is raised.
29
- # For fixing the issue, the value for range in date_range method should be increased.
30
- #
31
- # @return [Date]
32
- def english_date
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
- # Since the obtained date is not exact, range of date (default 17) are returned containing the date.
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 [DateRange]
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
@@ -1,139 +1,394 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Miti
4
- module Data
5
- # class to return nepali date data
6
- class DateData
7
- def self.year_month_days_hash
8
- {
9
- 1975 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
10
- 1976 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
11
- 1977 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
12
- 1978 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
13
- 1979 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
14
- 1980 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
15
- 1981 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
16
- 1982 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
17
- 1983 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
18
- 1984 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
19
- 1985 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
20
- 1986 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
21
- 1987 => [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
22
- 1988 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
23
- 1989 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
24
- 1990 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
25
- 1991 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
26
- 1992 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
27
- 1993 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
28
- 1994 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
29
- 1995 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
30
- 1996 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
31
- 1997 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
32
- 1998 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
33
- 1999 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
34
- 2000 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
35
- 2001 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
36
- 2002 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
37
- 2003 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
38
- 2004 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
39
- 2005 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
40
- 2006 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
41
- 2007 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
42
- 2008 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
43
- 2009 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
44
- 2010 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
45
- 2011 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
46
- 2012 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
47
- 2013 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
48
- 2014 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
49
- 2015 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
50
- 2016 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
51
- 2017 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
52
- 2018 => [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
53
- 2019 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
54
- 2020 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
55
- 2021 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
56
- 2022 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
57
- 2023 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
58
- 2024 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
59
- 2025 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
60
- 2026 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
61
- 2027 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
62
- 2028 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
63
- 2029 => [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
64
- 2030 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
65
- 2031 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
66
- 2032 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
67
- 2033 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
68
- 2034 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
69
- 2035 => [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
70
- 2036 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
71
- 2037 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
72
- 2038 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
73
- 2039 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
74
- 2040 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
75
- 2041 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
76
- 2042 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
77
- 2043 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
78
- 2044 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
79
- 2045 => [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
80
- 2046 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
81
- 2047 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
82
- 2048 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
83
- 2049 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
84
- 2050 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
85
- 2051 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
86
- 2052 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
87
- 2053 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
88
- 2054 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
89
- 2055 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
90
- 2056 => [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
91
- 2057 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
92
- 2058 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
93
- 2059 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
94
- 2060 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
95
- 2061 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
96
- 2062 => [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31],
97
- 2063 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
98
- 2064 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
99
- 2065 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
100
- 2066 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
101
- 2067 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
102
- 2068 => [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
103
- 2069 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
104
- 2070 => [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
105
- 2071 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
106
- 2072 => [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
107
- 2073 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
108
- 2074 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
109
- 2075 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
110
- 2076 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
111
- 2077 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
112
- 2078 => [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
113
- 2079 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
114
- 2080 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
115
- 2081 => [31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
116
- 2082 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
117
- 2083 => [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
118
- 2084 => [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
119
- 2085 => [31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30],
120
- 2086 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
121
- 2087 => [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
122
- 2088 => [30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30],
123
- 2089 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
124
- 2090 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
125
- 2091 => [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
126
- 2092 => [30, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
127
- 2093 => [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
128
- 2094 => [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
129
- 2095 => [31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30],
130
- 2096 => [30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
131
- 2097 => [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
132
- 2098 => [31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 29, 31],
133
- 2099 => [31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30],
134
- 2100 => [31, 32, 31, 32, 30, 31, 30, 29, 30, 29, 30, 30]
135
- }
136
- end
137
- end
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
@@ -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
  ##
@@ -45,11 +46,11 @@ module Miti
45
46
  # @param separator(- by default)
46
47
  #
47
48
  # @return [String]
48
- def to_s(seperator = "-")
49
- return unless [" ", "/", "-"].include?(seperator)
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.blank? ? "" : seperator}#{date_element < 10 ? 0 : ""}#{date_element}"
53
+ "#{final_date}#{final_date.empty? ? "" : separator}#{date_element < 10 ? 0 : ""}#{date_element}"
53
54
  end
54
55
  end
55
56
 
@@ -72,11 +73,15 @@ module Miti
72
73
  end
73
74
 
74
75
  def yday
75
- days_before_month = Miti::Data::DateData.year_month_days_hash[barsa].first(mahina - 1).sum
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
@@ -98,10 +103,10 @@ module Miti
98
103
  #
99
104
  # @return [Miti::NepaliDate]
100
105
  def parse(date_string)
101
- regex = %r{\A\d{4}[-/\s]\d{1,2}[-/\s]\d{1,2}\z}
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::DateData.year_month_days_hash[barsa][mahina - 1]
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Miti
4
- VERSION = "0.0.3"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/miti.rb CHANGED
@@ -4,10 +4,12 @@ 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
12
+ class ConversionUnavailableError < StandardError; end
11
13
 
12
14
  class << self
13
15
  ##
@@ -15,6 +17,8 @@ module Miti
15
17
  # @param english_date [String], refers to date in string format
16
18
  # @return [<Miti::NepaliDate>], refers to the converted nepali date
17
19
  def to_bs(english_date)
20
+ validate_date_range(date: english_date, conversion: :to_bs)
21
+
18
22
  date = parse_english_date(english_date)
19
23
  Miti::AdToBs.new(date).convert
20
24
  rescue Date::Error
@@ -26,12 +30,37 @@ module Miti
26
30
  # @param nepali_date [String], refers to date in string format
27
31
  # @return [<Date>], refers to the converted english date from nepali date
28
32
  def to_ad(nepali_date)
33
+ validate_date_range(date: nepali_date, conversion: :to_ad)
34
+
29
35
  date = parse_nepali_date(nepali_date)
30
36
  Miti::BsToAd.new(date).convert
31
37
  end
32
38
 
33
39
  private
34
40
 
41
+ ##
42
+ # This method throws an exception if the conversion is not available
43
+ # for both BS and AD
44
+ # - For AD to BS conversion max conversion is supported upto 2044 AD
45
+ # - For BS to AD conversion max conversion is supported upto 2100 BS
46
+ # @param date [String], refers to date in string format '20XX-XX-XX'
47
+ # @param conversion, [Symbol], refers to the conversion either :to_ad or :to_bs
48
+ #
49
+ # @return ConversionUnavailableError
50
+
51
+ def validate_date_range(date:, conversion:)
52
+ max_conversion_year, min_conversion_year, date_format = if conversion == :to_bs
53
+ [2044, 1919, :AD]
54
+ else
55
+ [2100, 1975, :BS]
56
+ end
57
+ year_value = date.split("-")[0].to_i
58
+ return if year_value.between?(min_conversion_year, max_conversion_year)
59
+
60
+ raise ConversionUnavailableError,
61
+ "Conversion only available for #{min_conversion_year}-#{max_conversion_year} #{date_format}"
62
+ end
63
+
35
64
  ##
36
65
  # This method parses the provided parameter english date to Date object
37
66
  # It checks the class of the parameter and returns the Date object accordingly
data/miti.gemspec CHANGED
@@ -8,13 +8,13 @@ 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 = "This gem can help to convert English date(AD) to Nepali date(BS) and vice-versa."
12
- # spec.homepage = "TODO: Put your gem's website or public repo URL here."
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
- # spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["homepage_uri"] = "https://github.com/xkshitizx/miti"
18
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" }
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  "miti.gemspec", ".github/*.md",
27
27
  "Gemfile", "Rakefile"]
28
28
  spec.bindir = "exe"
29
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.executables = ["miti"]
30
30
  spec.require_paths = ["lib"]
31
31
  spec.license = "MIT"
32
32
 
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.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xkshitizx
@@ -9,14 +9,14 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-10-18 00:00:00.000000000 Z
12
+ date: 2023-06-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: This gem can help to convert English date(AD) to Nepali date(BS) and
15
- vice-versa.
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
19
- executables: []
18
+ executables:
19
+ - miti
20
20
  extensions: []
21
21
  extra_rdoc_files: []
22
22
  files:
@@ -25,6 +25,8 @@ files:
25
25
  - LICENSE
26
26
  - README.md
27
27
  - Rakefile
28
+ - exe/miti
29
+ - lib/cli.rb
28
30
  - lib/miti.rb
29
31
  - lib/miti/ad_to_bs.rb
30
32
  - lib/miti/bs_to_ad.rb
@@ -32,7 +34,7 @@ files:
32
34
  - lib/miti/nepali_date.rb
33
35
  - lib/miti/version.rb
34
36
  - miti.gemspec
35
- homepage:
37
+ homepage: https://github.com/xkshitizx/miti
36
38
  licenses:
37
39
  - MIT
38
40
  metadata:
@@ -52,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
54
  - !ruby/object:Gem::Version
53
55
  version: '0'
54
56
  requirements: []
55
- rubygems_version: 3.3.22
57
+ rubygems_version: 3.3.3
56
58
  signing_key:
57
59
  specification_version: 4
58
60
  summary: Date converter BS to AD and vice-versa.