miti 0.0.1 → 0.0.3
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/LICENSE +21 -0
- data/README.md +34 -9
- data/lib/miti/ad_to_bs.rb +51 -0
- data/lib/miti/bs_to_ad.rb +3 -3
- data/lib/miti/nepali_date.rb +7 -7
- data/lib/miti/version.rb +1 -1
- data/lib/miti.rb +20 -0
- data/miti.gemspec +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1f30a2d951f109ab5cdc4a290dec5dde6dcbeabd97a68217056c93751cca658
|
4
|
+
data.tar.gz: 21a30dcc1e05e5d9c3c38dbf24a9a2507c6ec096504a93ec5de83af9ba210140
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 577e91a616bc035f388939c883373666f7b514b030a16b1918747b1f3e48ecd11b149ee8246fa77235fd1343135a3ef9e4226602b1c57c65a86c11a3e734b8d7
|
7
|
+
data.tar.gz: 3efe7397bfa2198b7d8489a1776344190e826694f4487f2be1cf225c49ff9c06560afeb3152d04662db8636af0d7b7a676cc0697eb9d39f382d74ee5a189039a
|
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,17 +3,40 @@
|
|
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]
|
9
|
+
#
|
6
10
|
def initialize(english_date)
|
7
11
|
@english_date = english_date
|
8
12
|
@nepali_year = english_date.year + 56
|
9
13
|
end
|
10
14
|
|
15
|
+
##
|
16
|
+
# 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
|
11
21
|
def convert(to_h: false)
|
12
22
|
return NepaliDate.new(barsa: final_nepali_year_month_value[:year], mahina: mahina, gatey: gatey) unless to_h
|
13
23
|
|
14
24
|
{ barsa: final_nepali_year_month_value[:year], mahina: mahina, gatey: gatey }
|
15
25
|
end
|
16
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
|
+
#
|
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]*
|
17
40
|
def final_nepali_year_month_value
|
18
41
|
@final_nepali_year_month_value = if (nepali_nth_day - total_days_in_nepali_year).positive?
|
19
42
|
{ year: nepali_year + 1, month: english_date.month - 4 }
|
@@ -57,6 +80,13 @@ module Miti
|
|
57
80
|
end
|
58
81
|
end
|
59
82
|
|
83
|
+
##
|
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
|
88
|
+
#
|
89
|
+
# @return [Integer], refers to number of days remaining in nepali year
|
60
90
|
def remaining_days_in_nepali_year
|
61
91
|
remaining_days = nepali_nth_day % total_days_in_nepali_year
|
62
92
|
if remaining_days.zero?
|
@@ -66,25 +96,46 @@ module Miti
|
|
66
96
|
end
|
67
97
|
end
|
68
98
|
|
99
|
+
##
|
100
|
+
# Calculates the total number of days in a specific year
|
101
|
+
#
|
102
|
+
# @return [Integer], refers to the total number of days
|
69
103
|
def total_days_in_nepali_year
|
70
104
|
@total_days_in_nepali_year ||= year_data[nepali_year].sum
|
71
105
|
end
|
72
106
|
|
107
|
+
##
|
108
|
+
# Calculates the number of days in nepali year as on from Jan 1st
|
109
|
+
#
|
110
|
+
# @return [Integer], refers to number of days
|
73
111
|
def nepali_nth_day
|
74
112
|
@nepali_nth_day = english_date.yday + nepali_nth_day_for_english_new_year - 1
|
75
113
|
end
|
76
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
|
77
120
|
def nepali_nth_day_for_english_new_year
|
78
121
|
return 264 if year_after_leap_year?
|
79
122
|
|
80
123
|
263
|
81
124
|
end
|
82
125
|
|
126
|
+
##
|
127
|
+
# Checks the previous year of @english_date from params is leap year or not?
|
128
|
+
#
|
129
|
+
# @return [Boolean], refers previous year is whether leap year or not
|
83
130
|
def year_after_leap_year?
|
84
131
|
year_before = english_date.year - 1
|
85
132
|
(year_before % 400).zero? || (year_before % 100 != 0 && (year_before % 4).zero?)
|
86
133
|
end
|
87
134
|
|
135
|
+
##
|
136
|
+
# Calls DateData class to retrieve the nepali date data consisting total no of days, month
|
137
|
+
#
|
138
|
+
# @return [Hash], refers to hash object consisting the nepali date data
|
88
139
|
def year_data
|
89
140
|
@year_data = Miti::Data::DateData.year_month_days_hash
|
90
141
|
end
|
data/lib/miti/bs_to_ad.rb
CHANGED
@@ -8,7 +8,7 @@ module Miti
|
|
8
8
|
##
|
9
9
|
# Creating an object of BsToAd requires a Miti::NepaliDate object
|
10
10
|
#
|
11
|
-
#
|
11
|
+
# @param [Miti::NepaliDate]
|
12
12
|
def initialize(nepali_date)
|
13
13
|
@barsa = nepali_date.barsa
|
14
14
|
@mahina = nepali_date.mahina
|
@@ -28,7 +28,7 @@ module Miti
|
|
28
28
|
# Incase the date is not found, error is raised.
|
29
29
|
# For fixing the issue, the value for range in date_range method should be increased.
|
30
30
|
#
|
31
|
-
#
|
31
|
+
# @return [Date]
|
32
32
|
def english_date
|
33
33
|
date_range.each do |date|
|
34
34
|
return date if Miti::AdToBs.new(date).convert(to_h: true) ==
|
@@ -43,7 +43,7 @@ module Miti
|
|
43
43
|
# This method creates new english date with year/month/day value equal to Nepali date and subtracts by 20,711
|
44
44
|
# and returns the range of date around it.
|
45
45
|
#
|
46
|
-
# return []
|
46
|
+
# @return [DateRange]
|
47
47
|
def date_range(range = 8)
|
48
48
|
probable_english_date = Date.new(barsa, mahina, gatey) - 20_711
|
49
49
|
probable_english_date.prev_day(range)..probable_english_date.next_day(range)
|
data/lib/miti/nepali_date.rb
CHANGED
@@ -18,7 +18,7 @@ module Miti
|
|
18
18
|
##
|
19
19
|
# Get equivalent tarik(AD) for NepaliDate
|
20
20
|
#
|
21
|
-
# return Date
|
21
|
+
# @return [Date]
|
22
22
|
def tarik
|
23
23
|
@tarik ||= BsToAd.new(self).convert
|
24
24
|
end
|
@@ -26,7 +26,7 @@ module Miti
|
|
26
26
|
##
|
27
27
|
# Get weekday for a nepali date.
|
28
28
|
#
|
29
|
-
#
|
29
|
+
# @return [Integer](0-6) that represents weekdays starting from 0.
|
30
30
|
def bar
|
31
31
|
@bar ||= tarik&.wday
|
32
32
|
end
|
@@ -34,7 +34,7 @@ module Miti
|
|
34
34
|
##
|
35
35
|
# returns details of nepali date in a ruby Hash
|
36
36
|
#
|
37
|
-
#
|
37
|
+
# @return [Hash]
|
38
38
|
def to_h
|
39
39
|
{ barsa: barsa, mahina: mahina, gatey: gatey, bar: bar, tarik: tarik }
|
40
40
|
end
|
@@ -42,9 +42,9 @@ module Miti
|
|
42
42
|
##
|
43
43
|
# Returns Nepali Date in string format(yyyy/mm/dd).
|
44
44
|
#
|
45
|
-
#
|
45
|
+
# @param separator(- by default)
|
46
46
|
#
|
47
|
-
#
|
47
|
+
# @return [String]
|
48
48
|
def to_s(seperator = "-")
|
49
49
|
return unless [" ", "/", "-"].include?(seperator)
|
50
50
|
|
@@ -57,7 +57,7 @@ module Miti
|
|
57
57
|
# Descriptive output for current date
|
58
58
|
# When nepali flag is true, month is returned in nepali font and week day in Nepali
|
59
59
|
#
|
60
|
-
#
|
60
|
+
# @return [String]
|
61
61
|
def descriptive(nepali: false)
|
62
62
|
month_index = mahina - 1
|
63
63
|
if nepali
|
@@ -96,7 +96,7 @@ module Miti
|
|
96
96
|
##
|
97
97
|
# This method parses date in yyyy/mm/dd to NepaliDate object
|
98
98
|
#
|
99
|
-
#
|
99
|
+
# @return [Miti::NepaliDate]
|
100
100
|
def parse(date_string)
|
101
101
|
regex = %r{\A\d{4}[-/\s]\d{1,2}[-/\s]\d{1,2}\z}
|
102
102
|
raise "Invalid Date Format" unless regex.match(date_string)
|
data/lib/miti/version.rb
CHANGED
data/lib/miti.rb
CHANGED
@@ -10,6 +10,10 @@ module Miti
|
|
10
10
|
class Error < StandardError; end
|
11
11
|
|
12
12
|
class << self
|
13
|
+
##
|
14
|
+
# This method converts the provided english date to nepali date
|
15
|
+
# @param english_date [String], refers to date in string format
|
16
|
+
# @return [<Miti::NepaliDate>], refers to the converted nepali date
|
13
17
|
def to_bs(english_date)
|
14
18
|
date = parse_english_date(english_date)
|
15
19
|
Miti::AdToBs.new(date).convert
|
@@ -17,6 +21,10 @@ module Miti
|
|
17
21
|
"Invalid Date"
|
18
22
|
end
|
19
23
|
|
24
|
+
##
|
25
|
+
# This method converts the provided nepali date to english date
|
26
|
+
# @param nepali_date [String], refers to date in string format
|
27
|
+
# @return [<Date>], refers to the converted english date from nepali date
|
20
28
|
def to_ad(nepali_date)
|
21
29
|
date = parse_nepali_date(nepali_date)
|
22
30
|
Miti::BsToAd.new(date).convert
|
@@ -24,6 +32,12 @@ module Miti
|
|
24
32
|
|
25
33
|
private
|
26
34
|
|
35
|
+
##
|
36
|
+
# This method parses the provided parameter english date to Date object
|
37
|
+
# It checks the class of the parameter and returns the Date object accordingly
|
38
|
+
# @param english_date [String], refers to date in string format OR
|
39
|
+
# @param english_date [Date], refers to date object
|
40
|
+
# @return [<Date>], refers to Date object
|
27
41
|
def parse_english_date(english_date)
|
28
42
|
klass = english_date.class.to_s
|
29
43
|
|
@@ -36,6 +50,12 @@ module Miti
|
|
36
50
|
end
|
37
51
|
end
|
38
52
|
|
53
|
+
##
|
54
|
+
# This method parses the provided parameter nepali_date to Miti::NepaliDate object
|
55
|
+
# It checks the class of the parameter and returns the Miti::NepaliDate object accordingly
|
56
|
+
# @param nepali_date [String], refers to date in string format OR
|
57
|
+
# @param nepali_date [Miti::NepaliDate ], refers to date object
|
58
|
+
# @return [<Date>], refers to Date object
|
39
59
|
def parse_nepali_date(nepali_date)
|
40
60
|
klass = nepali_date.class.to_s
|
41
61
|
|
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 = "
|
11
|
+
spec.description = "This gem can help to convert English date(AD) to Nepali date(BS) and vice-versa."
|
12
12
|
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
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
17
|
# spec.metadata["homepage_uri"] = spec.homepage
|
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" }
|
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.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xkshitizx
|
@@ -9,10 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
15
|
-
|
14
|
+
description: This gem can help to convert English date(AD) to Nepali date(BS) and
|
15
|
+
vice-versa.
|
16
16
|
email:
|
17
17
|
- kshitizlama03@gmail.com
|
18
18
|
- sanzaymanandhar99@gmail.com
|
@@ -22,6 +22,7 @@ extra_rdoc_files: []
|
|
22
22
|
files:
|
23
23
|
- CHANGELOG.md
|
24
24
|
- Gemfile
|
25
|
+
- LICENSE
|
25
26
|
- README.md
|
26
27
|
- Rakefile
|
27
28
|
- lib/miti.rb
|