nepali_date_converter 0.1.2
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 +7 -0
 - data/.gitignore +18 -0
 - data/.rbenv-gemsets +1 -0
 - data/.rspec +1 -0
 - data/.travis.yml +10 -0
 - data/CODE_OF_CONDUCT.md +74 -0
 - data/Gemfile +4 -0
 - data/LICENSE.txt +21 -0
 - data/README.md +59 -0
 - data/Rakefile +6 -0
 - data/bin/console +14 -0
 - data/bin/setup +8 -0
 - data/lib/nepali_date_converter.rb +172 -0
 - data/lib/nepali_date_converter/calendar.rb +175 -0
 - data/lib/nepali_date_converter/version.rb +3 -0
 - data/nepali_date_converter.gemspec +37 -0
 - metadata +115 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 573087bb82fd90adebc318bced35f6e4d6840ec1
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 040b2353c16310f815eec20c2a61fa08ac11655c
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a1f2bacf7ff6e798d817ff666f2cb48d628723611fedf47a48960ab7e814aa5c40845d3e3b17f11cfbe98c60f9f83b910bfeccae29402cc91ac22a69a532707d
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 677b17dd8251c0e09943ec649dc3c831fc30f00bdb24b7f6dbc22b7b788ff16e7fca3d2944bafd0c1763261d7135f26356bc8493200e9d58dd25041fcb7f0926
         
     | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rbenv-gemsets
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            -global
         
     | 
    
        data/.rspec
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --color
         
     | 
    
        data/.travis.yml
    ADDED
    
    
    
        data/CODE_OF_CONDUCT.md
    ADDED
    
    | 
         @@ -0,0 +1,74 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Contributor Covenant Code of Conduct
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            ## Our Pledge
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            In the interest of fostering an open and welcoming environment, we as
         
     | 
| 
      
 6 
     | 
    
         
            +
            contributors and maintainers pledge to making participation in our project and
         
     | 
| 
      
 7 
     | 
    
         
            +
            our community a harassment-free experience for everyone, regardless of age, body
         
     | 
| 
      
 8 
     | 
    
         
            +
            size, disability, ethnicity, gender identity and expression, level of experience,
         
     | 
| 
      
 9 
     | 
    
         
            +
            nationality, personal appearance, race, religion, or sexual identity and
         
     | 
| 
      
 10 
     | 
    
         
            +
            orientation.
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            ## Our Standards
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            Examples of behavior that contributes to creating a positive environment
         
     | 
| 
      
 15 
     | 
    
         
            +
            include:
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            * Using welcoming and inclusive language
         
     | 
| 
      
 18 
     | 
    
         
            +
            * Being respectful of differing viewpoints and experiences
         
     | 
| 
      
 19 
     | 
    
         
            +
            * Gracefully accepting constructive criticism
         
     | 
| 
      
 20 
     | 
    
         
            +
            * Focusing on what is best for the community
         
     | 
| 
      
 21 
     | 
    
         
            +
            * Showing empathy towards other community members
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            Examples of unacceptable behavior by participants include:
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            * The use of sexualized language or imagery and unwelcome sexual attention or
         
     | 
| 
      
 26 
     | 
    
         
            +
            advances
         
     | 
| 
      
 27 
     | 
    
         
            +
            * Trolling, insulting/derogatory comments, and personal or political attacks
         
     | 
| 
      
 28 
     | 
    
         
            +
            * Public or private harassment
         
     | 
| 
      
 29 
     | 
    
         
            +
            * Publishing others' private information, such as a physical or electronic
         
     | 
| 
      
 30 
     | 
    
         
            +
              address, without explicit permission
         
     | 
| 
      
 31 
     | 
    
         
            +
            * Other conduct which could reasonably be considered inappropriate in a
         
     | 
| 
      
 32 
     | 
    
         
            +
              professional setting
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            ## Our Responsibilities
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            Project maintainers are responsible for clarifying the standards of acceptable
         
     | 
| 
      
 37 
     | 
    
         
            +
            behavior and are expected to take appropriate and fair corrective action in
         
     | 
| 
      
 38 
     | 
    
         
            +
            response to any instances of unacceptable behavior.
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            Project maintainers have the right and responsibility to remove, edit, or
         
     | 
| 
      
 41 
     | 
    
         
            +
            reject comments, commits, code, wiki edits, issues, and other contributions
         
     | 
| 
      
 42 
     | 
    
         
            +
            that are not aligned to this Code of Conduct, or to ban temporarily or
         
     | 
| 
      
 43 
     | 
    
         
            +
            permanently any contributor for other behaviors that they deem inappropriate,
         
     | 
| 
      
 44 
     | 
    
         
            +
            threatening, offensive, or harmful.
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            ## Scope
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            This Code of Conduct applies both within project spaces and in public spaces
         
     | 
| 
      
 49 
     | 
    
         
            +
            when an individual is representing the project or its community. Examples of
         
     | 
| 
      
 50 
     | 
    
         
            +
            representing a project or community include using an official project e-mail
         
     | 
| 
      
 51 
     | 
    
         
            +
            address, posting via an official social media account, or acting as an appointed
         
     | 
| 
      
 52 
     | 
    
         
            +
            representative at an online or offline event. Representation of a project may be
         
     | 
| 
      
 53 
     | 
    
         
            +
            further defined and clarified by project maintainers.
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            ## Enforcement
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            Instances of abusive, harassing, or otherwise unacceptable behavior may be
         
     | 
| 
      
 58 
     | 
    
         
            +
            reported by contacting the project team at pushparaj.badu@gmail.com. All
         
     | 
| 
      
 59 
     | 
    
         
            +
            complaints will be reviewed and investigated and will result in a response that
         
     | 
| 
      
 60 
     | 
    
         
            +
            is deemed necessary and appropriate to the circumstances. The project team is
         
     | 
| 
      
 61 
     | 
    
         
            +
            obligated to maintain confidentiality with regard to the reporter of an incident.
         
     | 
| 
      
 62 
     | 
    
         
            +
            Further details of specific enforcement policies may be posted separately.
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            Project maintainers who do not follow or enforce the Code of Conduct in good
         
     | 
| 
      
 65 
     | 
    
         
            +
            faith may face temporary or permanent repercussions as determined by other
         
     | 
| 
      
 66 
     | 
    
         
            +
            members of the project's leadership.
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
            ## Attribution
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
         
     | 
| 
      
 71 
     | 
    
         
            +
            available at [http://contributor-covenant.org/version/1/4][version]
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
            [homepage]: http://contributor-covenant.org
         
     | 
| 
      
 74 
     | 
    
         
            +
            [version]: http://contributor-covenant.org/version/1/4/
         
     | 
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            The MIT License (MIT)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Copyright (c) 2017 Pushpa Raj Badu
         
     | 
| 
      
 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
         
     | 
| 
      
 13 
     | 
    
         
            +
            all 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
         
     | 
| 
      
 21 
     | 
    
         
            +
            THE SOFTWARE.
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,59 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            [](https://travis-ci.org/przbadu/nepali_date_converter)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # NepaliDateConverter
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            A ruby library to convert A.D (english) date to B.S (nepali) date and vice versa.
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            Add this line to your application's Gemfile:
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 12 
     | 
    
         
            +
            gem 'nepali_date_converter'
         
     | 
| 
      
 13 
     | 
    
         
            +
            ```
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            And then execute:
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                $ bundle
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            Or install it yourself as:
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                $ gem install nepali_date_converter
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            Convert A.D to B.S
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 28 
     | 
    
         
            +
            NepaliDateConverter::Convert.to_nepali(yyyy, mm, dd)
         
     | 
| 
      
 29 
     | 
    
         
            +
            ```
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            convert B.S to A.D
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 34 
     | 
    
         
            +
            NepaliDateConverter::Convert.to_english(yyyy, mm, dd)
         
     | 
| 
      
 35 
     | 
    
         
            +
            ```
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            ## TODO
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            * Add more specs
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            ## Gotcha
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            Till now, we can only convert date from 2000 to 2033 B.S (nepali date).
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            ## Development
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            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.
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            ## Contributing
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nepali_date_converter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            ## License
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/console
    ADDED
    
    | 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "bundler/setup"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "nepali_date_converter"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            # You can add fixtures and/or initialization code here to make experimenting
         
     | 
| 
      
 7 
     | 
    
         
            +
            # with your gem easier. You can also use a different console, if you like.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            # (If you use this, don't forget to add pry to your Gemfile!)
         
     | 
| 
      
 10 
     | 
    
         
            +
            # require "pry"
         
     | 
| 
      
 11 
     | 
    
         
            +
            # Pry.start
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            require "irb"
         
     | 
| 
      
 14 
     | 
    
         
            +
            IRB.start
         
     | 
    
        data/bin/setup
    ADDED
    
    
| 
         @@ -0,0 +1,172 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'nepali_date_converter/version'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'nepali_date_converter/calendar'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            module NepaliDateConverter
         
     | 
| 
      
 5 
     | 
    
         
            +
              class Convert
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                def self.to_nepali(yy, mm, dd)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  if NepaliDateConverter::Calendar.valid_english_date?(yy, mm, dd)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    @yy, @mm, @dd = yy, mm, dd
         
     | 
| 
      
 10 
     | 
    
         
            +
                    # english month data
         
     | 
| 
      
 11 
     | 
    
         
            +
                    @month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
         
     | 
| 
      
 12 
     | 
    
         
            +
                    # leap year data
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @lmonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                    @def_eyy = 1944
         
     | 
| 
      
 16 
     | 
    
         
            +
                    @def_nyy, @def_nmm, @def_ndd = 2000, 9, 17-1
         
     | 
| 
      
 17 
     | 
    
         
            +
                    # nepali date...
         
     | 
| 
      
 18 
     | 
    
         
            +
                    @total_eDays, @total_nDays, @a = 0, 0, 0
         
     | 
| 
      
 19 
     | 
    
         
            +
                    @day = 7 - 1
         
     | 
| 
      
 20 
     | 
    
         
            +
                    # initializations...
         
     | 
| 
      
 21 
     | 
    
         
            +
                    @m, @y, @i, @j, @numDay = 0, 0, 0, 0
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                    # count total no. of days in-terms of year
         
     | 
| 
      
 24 
     | 
    
         
            +
                    # total days for month
         
     | 
| 
      
 25 
     | 
    
         
            +
                    (@yy-@def_eyy).times do |i|
         
     | 
| 
      
 26 
     | 
    
         
            +
                      # calculation .... (english)
         
     | 
| 
      
 27 
     | 
    
         
            +
                      if NepaliDateConverter::Calendar.is_leap_year?(@def_eyy + i)
         
     | 
| 
      
 28 
     | 
    
         
            +
                        12.times do |j|
         
     | 
| 
      
 29 
     | 
    
         
            +
                          @total_eDays += @lmonth[j]
         
     | 
| 
      
 30 
     | 
    
         
            +
                        end
         
     | 
| 
      
 31 
     | 
    
         
            +
                      else
         
     | 
| 
      
 32 
     | 
    
         
            +
                        12.times do |j|
         
     | 
| 
      
 33 
     | 
    
         
            +
                          @total_eDays += @month[j]
         
     | 
| 
      
 34 
     | 
    
         
            +
                        end
         
     | 
| 
      
 35 
     | 
    
         
            +
                      end
         
     | 
| 
      
 36 
     | 
    
         
            +
                    end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                    # count total no. of days in-terms of month
         
     | 
| 
      
 39 
     | 
    
         
            +
                    (@mm-1).times do |i|
         
     | 
| 
      
 40 
     | 
    
         
            +
                      if NepaliDateConverter::Calendar.is_leap_year?(@yy)
         
     | 
| 
      
 41 
     | 
    
         
            +
                        @total_eDays += @lmonth[i]
         
     | 
| 
      
 42 
     | 
    
         
            +
                      else
         
     | 
| 
      
 43 
     | 
    
         
            +
                        @total_eDays += @month[i]
         
     | 
| 
      
 44 
     | 
    
         
            +
                      end
         
     | 
| 
      
 45 
     | 
    
         
            +
                    end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                    # count total no. of days in-terms of date
         
     | 
| 
      
 48 
     | 
    
         
            +
                    @total_eDays += @dd
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                    @j = @def_nmm
         
     | 
| 
      
 51 
     | 
    
         
            +
                    @total_nDays = @def_ndd
         
     | 
| 
      
 52 
     | 
    
         
            +
                    @m = @def_nmm
         
     | 
| 
      
 53 
     | 
    
         
            +
                    @y = @def_nyy
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                    # count nepali date from array
         
     | 
| 
      
 56 
     | 
    
         
            +
                    while @total_eDays != 0
         
     | 
| 
      
 57 
     | 
    
         
            +
                      @a = NepaliDateConverter::Calendar::BS_CALENDAR[@i][@j]
         
     | 
| 
      
 58 
     | 
    
         
            +
                      @total_nDays += 1   # count the days
         
     | 
| 
      
 59 
     | 
    
         
            +
                      @day += 1           # count the days interms of 7 days
         
     | 
| 
      
 60 
     | 
    
         
            +
                      if @total_nDays > @a
         
     | 
| 
      
 61 
     | 
    
         
            +
                        @m += 1
         
     | 
| 
      
 62 
     | 
    
         
            +
                        @total_nDays = 1
         
     | 
| 
      
 63 
     | 
    
         
            +
                        @j += 1
         
     | 
| 
      
 64 
     | 
    
         
            +
                      end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                      @day = 1 if @day > 7
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                      if @m > 12
         
     | 
| 
      
 69 
     | 
    
         
            +
                        @y += 1
         
     | 
| 
      
 70 
     | 
    
         
            +
                        @m = 1
         
     | 
| 
      
 71 
     | 
    
         
            +
                      end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                      if @j > 12
         
     | 
| 
      
 74 
     | 
    
         
            +
                        @j = 1
         
     | 
| 
      
 75 
     | 
    
         
            +
                        @i += 1
         
     | 
| 
      
 76 
     | 
    
         
            +
                      end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                      @total_eDays -= 1
         
     | 
| 
      
 79 
     | 
    
         
            +
                    end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 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 
     | 
    
         
            +
                    }
         
     | 
| 
      
 91 
     | 
    
         
            +
                  end
         
     | 
| 
      
 92 
     | 
    
         
            +
                end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                def self.to_english(yy, mm, dd)
         
     | 
| 
      
 95 
     | 
    
         
            +
                  @yy, @mm, @dd = yy, mm, dd
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                  # initialize english date
         
     | 
| 
      
 98 
     | 
    
         
            +
                  @def_eyy, @def_emm, @def_edd = 1943, 4, 14-1
         
     | 
| 
      
 99 
     | 
    
         
            +
                  # equivalent nepali date
         
     | 
| 
      
 100 
     | 
    
         
            +
                  @def_nyy, @def_nmm, @def_ndd = 2000, 1, 1
         
     | 
| 
      
 101 
     | 
    
         
            +
                  # initialization
         
     | 
| 
      
 102 
     | 
    
         
            +
                  @total_eDays, @total_nDays, @a = 0, 0, 0
         
     | 
| 
      
 103 
     | 
    
         
            +
                  @day=4-1
         
     | 
| 
      
 104 
     | 
    
         
            +
                  @m, @y, @i, @k, @numDay = 0, 0, 0, 0, 0
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
                  @month = [0,31,28,31,30,31,30,31,31,30,31,30,31]
         
     | 
| 
      
 107 
     | 
    
         
            +
                  @lmonth = [0,31,29,31,30,31,30,31,31,30,31,30,31]
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                  if NepaliDateConverter::Calendar.valid_nepali_date?(@yy, @mm, @dd)
         
     | 
| 
      
 110 
     | 
    
         
            +
                    # count total days in-terms of year
         
     | 
| 
      
 111 
     | 
    
         
            +
                    (@yy - @def_nyy).times do |i|
         
     | 
| 
      
 112 
     | 
    
         
            +
                      for j in (1..12)
         
     | 
| 
      
 113 
     | 
    
         
            +
                        @total_nDays += NepaliDateConverter::Calendar::BS_CALENDAR[@k][j]
         
     | 
| 
      
 114 
     | 
    
         
            +
                      end
         
     | 
| 
      
 115 
     | 
    
         
            +
                      @k += 1
         
     | 
| 
      
 116 
     | 
    
         
            +
                    end
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                    # count total days in-terms of month
         
     | 
| 
      
 119 
     | 
    
         
            +
                    for j in 1...@mm
         
     | 
| 
      
 120 
     | 
    
         
            +
                      @total_nDays += NepaliDateConverter::Calendar::BS_CALENDAR[@k][j]
         
     | 
| 
      
 121 
     | 
    
         
            +
                    end
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                    # count total days in-terms of date
         
     | 
| 
      
 124 
     | 
    
         
            +
                    @total_nDays += @dd
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                    # calculation of equivalent english date...
         
     | 
| 
      
 127 
     | 
    
         
            +
                    @total_eDays = @def_edd
         
     | 
| 
      
 128 
     | 
    
         
            +
                    @m = @def_emm
         
     | 
| 
      
 129 
     | 
    
         
            +
                    @y = @def_eyy
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
                    while @total_nDays != 0
         
     | 
| 
      
 132 
     | 
    
         
            +
                      if NepaliDateConverter::Calendar.is_leap_year?(@y)
         
     | 
| 
      
 133 
     | 
    
         
            +
                        @a = @lmonth[@m]
         
     | 
| 
      
 134 
     | 
    
         
            +
                      else
         
     | 
| 
      
 135 
     | 
    
         
            +
                        @a = @month[@m]
         
     | 
| 
      
 136 
     | 
    
         
            +
                      end
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
                      @total_eDays += 1
         
     | 
| 
      
 139 
     | 
    
         
            +
                      @day += 1
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                      if @total_eDays > @a
         
     | 
| 
      
 142 
     | 
    
         
            +
                        @m += 1
         
     | 
| 
      
 143 
     | 
    
         
            +
                        @total_eDays = 1
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
                        if @m > 12
         
     | 
| 
      
 146 
     | 
    
         
            +
                          @y += 1
         
     | 
| 
      
 147 
     | 
    
         
            +
                          @m = 1
         
     | 
| 
      
 148 
     | 
    
         
            +
                        end
         
     | 
| 
      
 149 
     | 
    
         
            +
                      end
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
                      if @day > 7
         
     | 
| 
      
 152 
     | 
    
         
            +
                        @day = 1
         
     | 
| 
      
 153 
     | 
    
         
            +
                      end
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                      @total_nDays -= 1
         
     | 
| 
      
 156 
     | 
    
         
            +
                    end
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                    @numDay = @day
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
                    {
         
     | 
| 
      
 161 
     | 
    
         
            +
                      year: @y,
         
     | 
| 
      
 162 
     | 
    
         
            +
                      month: @m,
         
     | 
| 
      
 163 
     | 
    
         
            +
                      date: @total_eDays,
         
     | 
| 
      
 164 
     | 
    
         
            +
                      day: NepaliDateConverter::Calendar.get_day_of_week(@day),
         
     | 
| 
      
 165 
     | 
    
         
            +
                      nepali_month: NepaliDateConverter::Calendar.get_english_month(@m),
         
     | 
| 
      
 166 
     | 
    
         
            +
                      week_day: @numDay
         
     | 
| 
      
 167 
     | 
    
         
            +
                    }
         
     | 
| 
      
 168 
     | 
    
         
            +
                  end
         
     | 
| 
      
 169 
     | 
    
         
            +
                end
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
              end
         
     | 
| 
      
 172 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,175 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'date'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module NepaliDateConverter
         
     | 
| 
      
 4 
     | 
    
         
            +
              class Calendar
         
     | 
| 
      
 5 
     | 
    
         
            +
                NEPALI_MONTHS = %w(Baishakh Jestha Ashad Shrawan Bhadra Ashwin Kartik Mangshir Poush Magh Falgun Chaitra)
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                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]
         
     | 
| 
      
 99 
     | 
    
         
            +
                ]
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 102 
     | 
    
         
            +
                  # Return english day of week
         
     | 
| 
      
 103 
     | 
    
         
            +
                  #
         
     | 
| 
      
 104 
     | 
    
         
            +
                  # Example:
         
     | 
| 
      
 105 
     | 
    
         
            +
                  #
         
     | 
| 
      
 106 
     | 
    
         
            +
                  #   get_day_of_week(1) # => Sunday
         
     | 
| 
      
 107 
     | 
    
         
            +
                  #   get_day_of_week(2) # => Monday
         
     | 
| 
      
 108 
     | 
    
         
            +
                  #
         
     | 
| 
      
 109 
     | 
    
         
            +
                  def get_day_of_week(idx)
         
     | 
| 
      
 110 
     | 
    
         
            +
                    Date::DAYNAMES[idx-1]
         
     | 
| 
      
 111 
     | 
    
         
            +
                  end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                  # Return english month name
         
     | 
| 
      
 114 
     | 
    
         
            +
                  #
         
     | 
| 
      
 115 
     | 
    
         
            +
                  # Example:
         
     | 
| 
      
 116 
     | 
    
         
            +
                  #
         
     | 
| 
      
 117 
     | 
    
         
            +
                  #    get_english_month(1) # => January
         
     | 
| 
      
 118 
     | 
    
         
            +
                  #    get_english_month(12) # => December
         
     | 
| 
      
 119 
     | 
    
         
            +
                  #
         
     | 
| 
      
 120 
     | 
    
         
            +
                  def get_english_month(idx)
         
     | 
| 
      
 121 
     | 
    
         
            +
                    Date::MONTHNAMES[idx]
         
     | 
| 
      
 122 
     | 
    
         
            +
                  end
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
                  # Return nepali month name
         
     | 
| 
      
 125 
     | 
    
         
            +
                  #
         
     | 
| 
      
 126 
     | 
    
         
            +
                  # Example:
         
     | 
| 
      
 127 
     | 
    
         
            +
                  #
         
     | 
| 
      
 128 
     | 
    
         
            +
                  #    get_nepali_month(1)    # => Baishakh
         
     | 
| 
      
 129 
     | 
    
         
            +
                  #    get_nepali_month(2)    # => Jestha
         
     | 
| 
      
 130 
     | 
    
         
            +
                  #
         
     | 
| 
      
 131 
     | 
    
         
            +
                  def get_nepali_month(idx)
         
     | 
| 
      
 132 
     | 
    
         
            +
                    NepaliDateConverter::Calendar::NEPALI_MONTHS[idx-1]
         
     | 
| 
      
 133 
     | 
    
         
            +
                  end
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
                  # Check if date range is in english date
         
     | 
| 
      
 136 
     | 
    
         
            +
                  #
         
     | 
| 
      
 137 
     | 
    
         
            +
                  #  is_in_range_eng(1944, 12, 31)  # => true
         
     | 
| 
      
 138 
     | 
    
         
            +
                  #
         
     | 
| 
      
 139 
     | 
    
         
            +
                  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)
         
     | 
| 
      
 143 
     | 
    
         
            +
                    true
         
     | 
| 
      
 144 
     | 
    
         
            +
                  end
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                  # check if date range is in nepali date
         
     | 
| 
      
 147 
     | 
    
         
            +
                  #
         
     | 
| 
      
 148 
     | 
    
         
            +
                  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)
         
     | 
| 
      
 152 
     | 
    
         
            +
                    true
         
     | 
| 
      
 153 
     | 
    
         
            +
                  end
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                  # Check if given year is leap year
         
     | 
| 
      
 156 
     | 
    
         
            +
                  #
         
     | 
| 
      
 157 
     | 
    
         
            +
                  def is_leap_year?(year)
         
     | 
| 
      
 158 
     | 
    
         
            +
                    # Date.leap?(year)
         
     | 
| 
      
 159 
     | 
    
         
            +
                    if year % 100 == 0
         
     | 
| 
      
 160 
     | 
    
         
            +
                      if year % 400 == 0
         
     | 
| 
      
 161 
     | 
    
         
            +
                        return true
         
     | 
| 
      
 162 
     | 
    
         
            +
                      else
         
     | 
| 
      
 163 
     | 
    
         
            +
                        return false
         
     | 
| 
      
 164 
     | 
    
         
            +
                      end
         
     | 
| 
      
 165 
     | 
    
         
            +
                    else
         
     | 
| 
      
 166 
     | 
    
         
            +
                      if year % 4 == 0
         
     | 
| 
      
 167 
     | 
    
         
            +
                        return true
         
     | 
| 
      
 168 
     | 
    
         
            +
                      else
         
     | 
| 
      
 169 
     | 
    
         
            +
                        return false
         
     | 
| 
      
 170 
     | 
    
         
            +
                      end
         
     | 
| 
      
 171 
     | 
    
         
            +
                    end
         
     | 
| 
      
 172 
     | 
    
         
            +
                  end
         
     | 
| 
      
 173 
     | 
    
         
            +
                end
         
     | 
| 
      
 174 
     | 
    
         
            +
              end
         
     | 
| 
      
 175 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,37 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # coding: utf-8
         
     | 
| 
      
 2 
     | 
    
         
            +
            lib = File.expand_path('../lib', __FILE__)
         
     | 
| 
      
 3 
     | 
    
         
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'nepali_date_converter/version'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            Gem::Specification.new do |spec|
         
     | 
| 
      
 7 
     | 
    
         
            +
              spec.name          = "nepali_date_converter"
         
     | 
| 
      
 8 
     | 
    
         
            +
              spec.version       = NepaliDateConverter::VERSION
         
     | 
| 
      
 9 
     | 
    
         
            +
              spec.authors       = ["Pushpa Raj Badu"]
         
     | 
| 
      
 10 
     | 
    
         
            +
              spec.email         = ["pushparaj.badu@gmail.com"]
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
              spec.summary       = %q{Ruby library to convert AD to BS and vice versa}
         
     | 
| 
      
 13 
     | 
    
         
            +
              spec.description   = %q{Ruby library to convert AD to BS and convert BS to AD}
         
     | 
| 
      
 14 
     | 
    
         
            +
              spec.homepage      = "https://github.com/przbadu/nepali_date_converter"
         
     | 
| 
      
 15 
     | 
    
         
            +
              spec.license       = "MIT"
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
         
     | 
| 
      
 18 
     | 
    
         
            +
              # to allow pushing to a single host or delete this section to allow pushing to any host.
         
     | 
| 
      
 19 
     | 
    
         
            +
              if spec.respond_to?(:metadata)
         
     | 
| 
      
 20 
     | 
    
         
            +
                # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
         
     | 
| 
      
 21 
     | 
    
         
            +
              else
         
     | 
| 
      
 22 
     | 
    
         
            +
                raise "RubyGems 2.0 or newer is required to protect against " \
         
     | 
| 
      
 23 
     | 
    
         
            +
                  "public gem pushes."
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              spec.files         = `git ls-files -z`.split("\x0").reject do |f|
         
     | 
| 
      
 27 
     | 
    
         
            +
                f.match(%r{^(test|spec|features)/})
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
              spec.bindir        = "exe"
         
     | 
| 
      
 30 
     | 
    
         
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         
     | 
| 
      
 31 
     | 
    
         
            +
              spec.require_paths = ["lib"]
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              spec.add_development_dependency "bundler", "~> 1.13"
         
     | 
| 
      
 34 
     | 
    
         
            +
              spec.add_development_dependency "rake", "~> 10.0"
         
     | 
| 
      
 35 
     | 
    
         
            +
              spec.add_development_dependency "rspec", "~> 3.0"
         
     | 
| 
      
 36 
     | 
    
         
            +
              spec.add_development_dependency "pry", '~> 0.10.4'
         
     | 
| 
      
 37 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,115 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: nepali_date_converter
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.2
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Pushpa Raj Badu
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: exe
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2017-06-16 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 13 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 14 
     | 
    
         
            +
              name: bundler
         
     | 
| 
      
 15 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 16 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 17 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 19 
     | 
    
         
            +
                    version: '1.13'
         
     | 
| 
      
 20 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 21 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 22 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 23 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 24 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 26 
     | 
    
         
            +
                    version: '1.13'
         
     | 
| 
      
 27 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 28 
     | 
    
         
            +
              name: rake
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: '10.0'
         
     | 
| 
      
 34 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 35 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 36 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 37 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 39 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                    version: '10.0'
         
     | 
| 
      
 41 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 42 
     | 
    
         
            +
              name: rspec
         
     | 
| 
      
 43 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 44 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 45 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 46 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 47 
     | 
    
         
            +
                    version: '3.0'
         
     | 
| 
      
 48 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 49 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 50 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 51 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 52 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 53 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 54 
     | 
    
         
            +
                    version: '3.0'
         
     | 
| 
      
 55 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 56 
     | 
    
         
            +
              name: pry
         
     | 
| 
      
 57 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 58 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 59 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 60 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 61 
     | 
    
         
            +
                    version: 0.10.4
         
     | 
| 
      
 62 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 63 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 64 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 65 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 66 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 67 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 68 
     | 
    
         
            +
                    version: 0.10.4
         
     | 
| 
      
 69 
     | 
    
         
            +
            description: Ruby library to convert AD to BS and convert BS to AD
         
     | 
| 
      
 70 
     | 
    
         
            +
            email:
         
     | 
| 
      
 71 
     | 
    
         
            +
            - pushparaj.badu@gmail.com
         
     | 
| 
      
 72 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 73 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 74 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 75 
     | 
    
         
            +
            files:
         
     | 
| 
      
 76 
     | 
    
         
            +
            - ".gitignore"
         
     | 
| 
      
 77 
     | 
    
         
            +
            - ".rbenv-gemsets"
         
     | 
| 
      
 78 
     | 
    
         
            +
            - ".rspec"
         
     | 
| 
      
 79 
     | 
    
         
            +
            - ".travis.yml"
         
     | 
| 
      
 80 
     | 
    
         
            +
            - CODE_OF_CONDUCT.md
         
     | 
| 
      
 81 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 82 
     | 
    
         
            +
            - LICENSE.txt
         
     | 
| 
      
 83 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 84 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 85 
     | 
    
         
            +
            - bin/console
         
     | 
| 
      
 86 
     | 
    
         
            +
            - bin/setup
         
     | 
| 
      
 87 
     | 
    
         
            +
            - lib/nepali_date_converter.rb
         
     | 
| 
      
 88 
     | 
    
         
            +
            - lib/nepali_date_converter/calendar.rb
         
     | 
| 
      
 89 
     | 
    
         
            +
            - lib/nepali_date_converter/version.rb
         
     | 
| 
      
 90 
     | 
    
         
            +
            - nepali_date_converter.gemspec
         
     | 
| 
      
 91 
     | 
    
         
            +
            homepage: https://github.com/przbadu/nepali_date_converter
         
     | 
| 
      
 92 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 93 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 94 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 95 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 96 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 97 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 98 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 99 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 100 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 101 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 102 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 103 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 104 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 105 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 106 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 107 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 108 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 109 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 110 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 111 
     | 
    
         
            +
            rubygems_version: 2.4.5.1
         
     | 
| 
      
 112 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 113 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 114 
     | 
    
         
            +
            summary: Ruby library to convert AD to BS and vice versa
         
     | 
| 
      
 115 
     | 
    
         
            +
            test_files: []
         
     |