nepali_date_converter 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4e382077b53e786ae0785aa4d8c43a57d671308f
4
- data.tar.gz: 02c04566c13ffe8bbe2524f8ee8a25e5a8aa0226
2
+ SHA256:
3
+ metadata.gz: 143ecab8f00d04ed9004fad2e8f9c96debd1bf50482a4cf97a2d6f61f9d763ef
4
+ data.tar.gz: f5acfd05476ff9123314b52abad373adb35a2a6f1b2bcc349acef552687c1811
5
5
  SHA512:
6
- metadata.gz: 496c57b8de085e3d5e7de4e2b2d230a60b09342eb9a5b51a3ab061bf59d5458e310402b394c40f163c0d7ca4b480bd32f04b5634e68309029ef992c5d6b2f55d
7
- data.tar.gz: 0e4be55412787a9ed02b82d4d2c25a11cf200a168770c8484c9b5677681892cf0f29c9922ef0588f8c14640cc88c3491317e0bf967d6de8dc95cde0689dfe35e
6
+ metadata.gz: 619215b149404f57a538cab02ca3ba2842ccb0c53d29ee1074049a7261b9e0cf5092d4b59b549936fa3bc52a6a78c1a7685f4df9b8bfd87106c48e117939dff8
7
+ data.tar.gz: eb5bf4d83bf394aed3cfd1dac51d34cd8c2f7ab4bf2d3487a43def32832b8ffc7dcce1b7abbfa4a186814b4857cac0aae315912ddbbfacd44e06f69a6cbd7a30
@@ -0,0 +1,20 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby: circleci/ruby@0.1.2
4
+
5
+ jobs:
6
+ build:
7
+ docker:
8
+ - image: circleci/ruby:3.0
9
+ environment:
10
+ BUNDLER_VERSION: 2.3.5
11
+ executor: ruby/default
12
+ steps:
13
+ - checkout
14
+ - run:
15
+ name: setup bundler
16
+ command: gem install bundler -v 2.3.5
17
+ - ruby/bundle-install
18
+ - run:
19
+ name: bundle exec rake
20
+ command: bundle exec rake
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.1
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
- [![Build Status](https://travis-ci.org/przbadu/nepali_date_converter.svg?branch=master)](https://travis-ci.org/przbadu/nepali_date_converter)
1
+ [![Build Status](https://circleci.com/gh/przbadu/nepali_date_converter.svg?style=svg)](https://app.circleci.com/pipelines/github/przbadu/nepali_date_converter)
2
2
  [![Gem Version](https://badge.fury.io/rb/nepali_date_converter.svg)](https://badge.fury.io/rb/nepali_date_converter)
3
+ # Related
4
+
5
+ [C# Class Library](https://github.com/przbadu/NepaliDateConverterCS)
3
6
 
4
7
  # NepaliDateConverter
5
8
 
@@ -33,6 +36,17 @@ NepaliDateConverter::Convert.to_nepali(2017, 06, 20)
33
36
  # => {:year=>2074, :month=>3, :date=>6, :day=>"Tuesday", :nepali_month=>"Ashad", :week_day=> 3}
34
37
  ```
35
38
 
39
+ ```ruby
40
+ NepaliDateConverter::Convert.to_nepali(2019,12,4, devanagari: true)
41
+ #=> {:year=>"२०७६", :month=>"८", :date=>"१८", :day=>"बुधवार", :nepali_month=>"मंसिर", :week_day=>"४"}
42
+
43
+ NepaliDateConverter::Calendar.get_nepali_month(1, devanagari: true)
44
+ #=> "बैशाख"
45
+
46
+ NepaliDateConverter::Calendar.get_day_of_week(1, devanagari: true)
47
+ #=> "आइतबार"
48
+ ```
49
+
36
50
  convert B.S to A.D
37
51
 
38
52
  ```ruby
@@ -49,7 +63,7 @@ NepaliDateConverter::Convert.to_english(2074, 3, 6)
49
63
 
50
64
  ## Gotcha
51
65
 
52
- Till now, we can only convert date from 2000 to 2033 B.S (nepali date).
66
+ Till now, we can only convert date from 2000 to 2089 B.S (nepali date).
53
67
 
54
68
  ## Development
55
69
 
@@ -2,102 +2,104 @@ require 'date'
2
2
 
3
3
  module NepaliDateConverter
4
4
  class Calendar
5
- NEPALI_MONTHS = %w(Baishakh Jestha Ashad Shrawan Bhadra Ashwin Kartik Mangshir Poush Magh Falgun Chaitra)
6
-
5
+ NEPALI_MONTHS = %w(Baishakh Jestha Ashad Shrawan Bhadra Ashwin Kartik Mangshir Poush Magh Falgun Chaitra)
6
+ NEPALI_MONTHS_DEVANAGARI = %w(बैशाख जेठ असार श्रावण भदौ आश्विन कार्तिक मंसिर पुष माघ फाल्गुन चैत्र)
7
+ WEEK_DAYS = %w(आइतबार सोमबार मंगलबार बुधवार बिहीबार शुक्रबार शनिबार)
8
+
7
9
  BS_CALENDAR = [
8
- [2000,30,32,31,32,31,30,30,30,29,30,29,31],
9
- [2001,31,31,32,31,31,31,30,29,30,29,30,30],
10
- [2002,31,31,32,32,31,30,30,29,30,29,30,30],
11
- [2003,31,32,31,32,31,30,30,30,29,29,30,31],
12
- [2004,30,32,31,32,31,30,30,30,29,30,29,31],
13
- [2005,31,31,32,31,31,31,30,29,30,29,30,30],
14
- [2006,31,31,32,32,31,30,30,29,30,29,30,30],
15
- [2007,31,32,31,32,31,30,30,30,29,29,30,31],
16
- [2008,31,31,31,32,31,31,29,30,30,29,29,31],
17
- [2009,31,31,32,31,31,31,30,29,30,29,30,30],
18
- [2010,31,31,32,32,31,30,30,29,30,29,30,30],
19
- [2011,31,32,31,32,31,30,30,30,29,29,30,31],
20
- [2012,31,31,31,32,31,31,29,30,30,29,30,30],
21
- [2013,31,31,32,31,31,31,30,29,30,29,30,30],
22
- [2014,31,31,32,32,31,30,30,29,30,29,30,30],
23
- [2015,31,32,31,32,31,30,30,30,29,29,30,31],
24
- [2016,31,31,31,32,31,31,29,30,30,29,30,30],
25
- [2017,31,31,32,31,31,31,30,29,30,29,30,30],
26
- [2018,31,32,31,32,31,30,30,29,30,29,30,30],
27
- [2019,31,32,31,32,31,30,30,30,29,30,29,31],
28
- [2020,31,31,31,32,31,31,30,29,30,29,30,30],
29
- [2021,31,31,32,31,31,31,30,29,30,29,30,30],
30
- [2022,31,32,31,32,31,30,30,30,29,29,30,30],
31
- [2023,31,32,31,32,31,30,30,30,29,30,29,31],
32
- [2024,31,31,31,32,31,31,30,29,30,29,30,30],
33
- [2025,31,31,32,31,31,31,30,29,30,29,30,30],
34
- [2026,31,32,31,32,31,30,30,30,29,29,30,31],
35
- [2027,30,32,31,32,31,30,30,30,29,30,29,31],
36
- [2028,31,31,32,31,31,31,30,29,30,29,30,30],
37
- [2029,31,31,32,31,32,30,30,29,30,29,30,30],
38
- [2030,31,32,31,32,31,30,30,30,29,29,30,31],
39
- [2031,30,32,31,32,31,30,30,30,29,30,29,31],
40
- [2032,31,31,32,31,31,31,30,29,30,29,30,30],
41
- [2033,31,31,32,32,31,30,30,29,30,29,30,30],
42
- [2034,31,32,31,32,31,30,30,30,29,29,30,31],
43
- [2035,30,32,31,32,31,31,29,30,30,29,29,31],
44
- [2036,31,31,32,31,31,31,30,29,30,29,30,30],
45
- [2037,31,31,32,32,31,30,30,29,30,29,30,30],
46
- [2038,31,32,31,32,31,30,30,30,29,29,30,31],
47
- [2039,31,31,31,32,31,31,29,30,30,29,30,30],
48
- [2040,31,31,32,31,31,31,30,29,30,29,30,30],
49
- [2041,31,31,32,32,31,30,30,29,30,29,30,30],
50
- [2042,31,32,31,32,31,30,30,30,29,29,30,31],
51
- [2043,31,31,31,32,31,31,29,30,30,29,30,30],
52
- [2044,31,31,32,31,31,31,30,29,30,29,30,30],
53
- [2045,31,32,31,32,31,30,30,29,30,29,30,30],
54
- [2046,31,32,31,32,31,30,30,30,29,29,30,31],
55
- [2047,31,31,31,32,31,31,30,29,30,29,30,30],
56
- [2048,31,31,32,31,31,31,30,29,30,29,30,30],
57
- [2049,31,32,31,32,31,30,30,30,29,29,30,30],
58
- [2050,31,32,31,32,31,30,30,30,29,30,29,31],
59
- [2051,31,31,31,32,31,31,30,29,30,29,30,30],
60
- [2052,31,31,32,31,31,31,30,29,30,29,30,30],
61
- [2053,31,32,31,32,31,30,30,30,29,29,30,30],
62
- [2054,31,32,31,32,31,30,30,30,29,30,29,31],
63
- [2055,31,31,32,31,31,31,30,29,30,29,30,30],
64
- [2056,31,31,32,31,32,30,30,29,30,29,30,30],
65
- [2057,31,32,31,32,31,30,30,30,29,29,30,31],
66
- [2058,30,32,31,32,31,30,30,30,29,30,29,31],
67
- [2059,31,31,32,31,31,31,30,29,30,29,30,30],
68
- [2060,31,31,32,32,31,30,30,29,30,29,30,30],
69
- [2061,31,32,31,32,31,30,30,30,29,29,30,31],
70
- [2062,30,32,31,32,31,31,29,30,29,30,29,31],
71
- [2063,31,31,32,31,31,31,30,29,30,29,30,30],
72
- [2064,31,31,32,32,31,30,30,29,30,29,30,30],
73
- [2065,31,32,31,32,31,30,30,30,29,29,30,31],
74
- [2066,31,31,31,32,31,31,29,30,30,29,29,31],
75
- [2067,31,31,32,31,31,31,30,29,30,29,30,30],
76
- [2068,31,31,32,32,31,30,30,29,30,29,30,30],
77
- [2069,31,32,31,32,31,30,30,30,29,29,30,31],
78
- [2070,31,31,31,32,31,31,29,30,30,29,30,30],
79
- [2071,31,31,32,31,31,31,30,29,30,29,30,30],
80
- [2072,31,32,31,32,31,30,30,29,30,29,30,30],
81
- [2073,31,32,31,32,31,30,30,30,29,29,30,31],
82
- [2074,31,31,31,32,31,31,30,29,30,29,30,30],
83
- [2075,31,31,32,31,31,31,30,29,30,29,30,30],
84
- [2076,31,32,31,32,31,30,30,30,29,29,30,30],
85
- [2077,31,32,31,32,31,30,30,30,29,30,29,31],
86
- [2078,31,31,31,32,31,31,30,29,30,29,30,30],
87
- [2079,31,31,32,31,31,31,30,29,30,29,30,30],
88
- [2080,31,32,31,32,31,30,30,30,29,29,30,30],
89
- [2081,31,31,32,32,31,30,30,30,29,30,30,30],
90
- [2082,30,32,31,32,31,30,30,30,29,30,30,30],
91
- [2083,31,31,32,31,31,30,30,30,29,30,30,30],
92
- [2084,31,31,32,31,31,30,30,30,29,30,30,30],
93
- [2085,31,32,31,32,30,31,30,30,29,30,30,30],
94
- [2086,30,32,31,32,31,30,30,30,29,30,30,30],
95
- [2087,31,31,32,31,31,31,30,30,29,30,30,30],
96
- [2088,30,31,32,32,30,31,30,30,29,30,30,30],
97
- [2089,30,32,31,32,31,30,30,30,29,30,30,30],
98
- [2090,30,32,31,32,31,30,30,30,29,30,30,30]
10
+ [2000, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
11
+ [2001, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
12
+ [2002, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
13
+ [2003, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
14
+ [2004, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
15
+ [2005, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
16
+ [2006, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
17
+ [2007, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
18
+ [2008, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
19
+ [2009, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
20
+ [2010, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
21
+ [2011, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
22
+ [2012, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
23
+ [2013, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
24
+ [2014, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
25
+ [2015, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
26
+ [2016, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
27
+ [2017, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
28
+ [2018, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
29
+ [2019, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
30
+ [2020, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
31
+ [2021, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
32
+ [2022, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
33
+ [2023, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
34
+ [2024, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
35
+ [2025, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
36
+ [2026, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
37
+ [2027, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
38
+ [2028, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
39
+ [2029, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
40
+ [2030, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
41
+ [2031, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
42
+ [2032, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
43
+ [2033, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
44
+ [2034, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
45
+ [2035, 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
46
+ [2036, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
47
+ [2037, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
48
+ [2038, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
49
+ [2039, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
50
+ [2040, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
51
+ [2041, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
52
+ [2042, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
53
+ [2043, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
54
+ [2044, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
55
+ [2045, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
56
+ [2046, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
57
+ [2047, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
58
+ [2048, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
59
+ [2049, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
60
+ [2050, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
61
+ [2051, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
62
+ [2052, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
63
+ [2053, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
64
+ [2054, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
65
+ [2055, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
66
+ [2056, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
67
+ [2057, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
68
+ [2058, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
69
+ [2059, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
70
+ [2060, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
71
+ [2061, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
72
+ [2062, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31],
73
+ [2063, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
74
+ [2064, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
75
+ [2065, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
76
+ [2066, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
77
+ [2067, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
78
+ [2068, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
79
+ [2069, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
80
+ [2070, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
81
+ [2071, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
82
+ [2072, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
83
+ [2073, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
84
+ [2074, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
85
+ [2075, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
86
+ [2076, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
87
+ [2077, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
88
+ [2078, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
89
+ [2079, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
90
+ [2080, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
91
+ [2081, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
92
+ [2082, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
93
+ [2083, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
94
+ [2084, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
95
+ [2085, 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30],
96
+ [2086, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
97
+ [2087, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
98
+ [2088, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30],
99
+ [2089, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
100
+ [2090, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30]
99
101
  ]
100
-
102
+
101
103
  class << self
102
104
  # Return english day of week
103
105
  #
@@ -106,10 +108,10 @@ module NepaliDateConverter
106
108
  # get_day_of_week(1) # => Sunday
107
109
  # get_day_of_week(2) # => Monday
108
110
  #
109
- def get_day_of_week(idx)
110
- Date::DAYNAMES[idx-1]
111
+ def get_day_of_week(idx, devanagari: false)
112
+ devanagari ? WEEK_DAYS[idx - 1] : Date::DAYNAMES[idx - 1]
111
113
  end
112
-
114
+
113
115
  # Return english month name
114
116
  #
115
117
  # Example:
@@ -120,7 +122,7 @@ module NepaliDateConverter
120
122
  def get_english_month(idx)
121
123
  Date::MONTHNAMES[idx]
122
124
  end
123
-
125
+
124
126
  # Return nepali month name
125
127
  #
126
128
  # Example:
@@ -128,30 +130,30 @@ module NepaliDateConverter
128
130
  # get_nepali_month(1) # => Baishakh
129
131
  # get_nepali_month(2) # => Jestha
130
132
  #
131
- def get_nepali_month(idx)
132
- NepaliDateConverter::Calendar::NEPALI_MONTHS[idx-1]
133
+ def get_nepali_month(idx, devanagari: false)
134
+ devanagari ? NEPALI_MONTHS_DEVANAGARI[idx-1] : NEPALI_MONTHS[idx - 1]
133
135
  end
134
-
136
+
135
137
  # Check if date range is in english date
136
138
  #
137
139
  # is_in_range_eng(1944, 12, 31) # => true
138
140
  #
139
141
  def valid_english_date?(year, month, day)
140
- raise 'Supported only between 1944-2033' unless (1944..2033).include?(year)
141
- raise 'Invalid month range' unless (1..12).include?(month)
142
- raise 'Invalid day range' unless (1..31).include?(day)
142
+ raise 'Supported only between 1944-2033' unless (1944 .. 2033).include?(year)
143
+ raise 'Invalid month range' unless (1 .. 12).include?(month)
144
+ raise 'Invalid day range' unless (1 .. 31).include?(day)
143
145
  true
144
146
  end
145
-
147
+
146
148
  # check if date range is in nepali date
147
149
  #
148
150
  def valid_nepali_date?(year, month, day)
149
- raise 'Supported only between 2000-2089' unless (2000..2089).include?(year)
150
- raise 'Invalid month range' unless (1..12).include?(month)
151
- raise 'Invalid day range' unless (1..32).include?(day)
151
+ raise 'Supported only between 2000-2089' unless (2000 .. 2089).include?(year)
152
+ raise 'Invalid month range' unless (1 .. 12).include?(month)
153
+ raise 'Invalid day range' unless (1 .. 32).include?(day)
152
154
  true
153
155
  end
154
-
156
+
155
157
  # Check if given year is leap year
156
158
  #
157
159
  def is_leap_year?(year)
@@ -1,3 +1,3 @@
1
1
  module NepaliDateConverter
2
- VERSION = "1.0.0"
2
+ VERSION = '1.0.1'.freeze
3
3
  end
@@ -4,7 +4,7 @@ require 'nepali_date_converter/calendar'
4
4
  module NepaliDateConverter
5
5
  class Convert
6
6
 
7
- def self.to_nepali(yy, mm, dd)
7
+ def self.to_nepali(yy, mm, dd, devanagari: false)
8
8
  if NepaliDateConverter::Calendar.valid_english_date?(yy, mm, dd)
9
9
  @yy, @mm, @dd = yy, mm, dd
10
10
  # english month data
@@ -79,15 +79,26 @@ module NepaliDateConverter
79
79
  end
80
80
 
81
81
  @numDay = @day
82
-
83
- {
84
- year: @y,
85
- month: @m,
86
- date: @total_nDays,
87
- day: NepaliDateConverter::Calendar.get_day_of_week(@day),
88
- nepali_month: NepaliDateConverter::Calendar.get_nepali_month(@m),
89
- week_day: @numDay
90
- }
82
+ if devanagari
83
+ {
84
+ year: num2nepali(@y),
85
+ month: num2nepali(@m),
86
+ date: num2nepali(@total_nDays),
87
+ day: NepaliDateConverter::Calendar.get_day_of_week(@day, devanagari: true),
88
+ nepali_month: NepaliDateConverter::Calendar.get_nepali_month(@m, devanagari: true),
89
+ week_day: num2nepali(@numDay)
90
+ }
91
+ else
92
+
93
+ {
94
+ year: @y,
95
+ month: @m,
96
+ date: @total_nDays,
97
+ day: NepaliDateConverter::Calendar.get_day_of_week(@day),
98
+ nepali_month: NepaliDateConverter::Calendar.get_nepali_month(@m),
99
+ week_day: @numDay
100
+ }
101
+ end
91
102
  end
92
103
  end
93
104
 
@@ -167,6 +178,18 @@ module NepaliDateConverter
167
178
  }
168
179
  end
169
180
  end
181
+
182
+ def self.to_english_date(yy, mm, dd)
183
+ date_hash = self.to_english(yy, mm, dd)
184
+ Date::strptime("#{date_hash[:year]}-#{date_hash[:month]}-#{date_hash[:date]}", "%Y-%m-%d")
185
+ end
170
186
 
187
+ # 1 -> '१'
188
+ # 2074 -> '२०७४'
189
+ def self.num2nepali(num)
190
+ num.to_s.split('').map do |digit|
191
+ ('0' .. '9').include?(digit) ? (2406 + digit.to_i).chr(Encoding::UTF_8) : digit
192
+ end.join('')
193
+ end
171
194
  end
172
195
  end
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_development_dependency "bundler", "~> 1.13"
34
- spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "bundler", "~> 2.3.5"
34
+ spec.add_development_dependency "rake", ">= 12.3.3"
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
36
36
  spec.add_development_dependency "pry", '~> 0.10.4'
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nepali_date_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pushpa Raj Badu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-20 00:00:00.000000000 Z
11
+ date: 2022-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: 2.3.5
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: 2.3.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -73,10 +73,11 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".circleci/config.yml"
76
77
  - ".gitignore"
77
78
  - ".rbenv-gemsets"
78
79
  - ".rspec"
79
- - ".travis.yml"
80
+ - ".ruby-version"
80
81
  - CODE_OF_CONDUCT.md
81
82
  - Gemfile
82
83
  - LICENSE.txt
@@ -107,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  - !ruby/object:Gem::Version
108
109
  version: '0'
109
110
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.4.5.1
111
+ rubygems_version: 3.2.15
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Ruby library to convert AD to BS and vice versa
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- sudo: false
2
-
3
- language: ruby
4
-
5
- rvm:
6
- - 2.1.10
7
- - 2.2.7
8
- - 2.3.4
9
- - 2.4.1
10
- - ruby-head