vietnamese_holiday 0.1.8

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b45387188ea14073261a64cf4edb64a2ae099db474468fbe38c49e3f65d90da5
4
+ data.tar.gz: 2ec7ccd48cdc58c30966491fe15c2bc62dda67eddb0b154ee4f16ab514198f4d
5
+ SHA512:
6
+ metadata.gz: 8d9b1acc74c00d954d56d470ed840c56a2123d9cecb42351e6e3aacb3d4857d47778764b2acb739bba3c0acfbff2da5719282604e9869f094d05c761c2f042ec
7
+ data.tar.gz: 5e6be13310a2e72b59fc67f794e84767a32555a94a881792d6f3eccc7b3d1e5c54e7485b04c57b81280e8a26d57f82aecf2f31878dd4fdd30b0408d1d645f575
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-04-07
4
+
5
+ - Initial release
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # VietnameseHoliday
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vietnamese_holiday`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vietnamese_holiday. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/vietnamese_holiday/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## Code of Conduct
34
+
35
+ Everyone interacting in the VietnameseHoliday project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/vietnamese_holiday/blob/main/CODE_OF_CONDUCT.md).
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "vietnamese_holiday"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VietnameseHoliday
4
+ # The calculate utils
5
+ module Utils
6
+ def self.solar_holiday_names
7
+ {
8
+ '1-1': 'Tết Dương lịch',
9
+ '4-30': 'Ngày giải phóng miền Nam',
10
+ '5-1': 'Ngày Quốc tế Lao động',
11
+ '2-9': 'Ngày Quốc Khánh'
12
+ }
13
+ end
14
+
15
+ def self.lunar_holiday_names
16
+ {
17
+ '1-1': 'Tết nguyên Đán',
18
+ '1-2': 'Tết nguyên Đán',
19
+ '1-3': 'Tết nguyên Đán',
20
+ '3-10': 'Giỗ tổ Hùng Vương'
21
+ }
22
+ end
23
+
24
+ def self.lunar_date(date)
25
+ date = date.to_date if date.is_a? String
26
+ LunarCalendar.at_lunar(date.year, date.month, date.day)
27
+ end
28
+
29
+ def self.check(date)
30
+ solar_date = Date.parse(date)
31
+
32
+ return true if solar_holiday_names.key?(solar_date.strftime('%-m-%-d').to_sym)
33
+
34
+ ldate = lunar_date(solar_date)
35
+ return true if lunar_holiday_names.key?("#{ldate.month}-#{ldate.day}".to_sym)
36
+
37
+ false
38
+ end
39
+
40
+ def self.name(date)
41
+ [].tap do |result|
42
+ solar_date = Date.parse(date)
43
+ key = solar_date.strftime('%-m-%-d').to_sym
44
+ result << solar_holiday_names[key] if solar_holiday_names.key?(key)
45
+
46
+ ldate = lunar_date(solar_date)
47
+ key = "#{ldate.month}-#{ldate.day}".to_sym
48
+ result << lunar_holiday_names[key] if lunar_holiday_names.key?(key)
49
+ end
50
+ end
51
+
52
+ def self.holidays(dates)
53
+ return [] if dates.count.zero?
54
+
55
+ solar_holidays(dates) + lunar_holidays(dates)
56
+ end
57
+
58
+ def self.solar_holidays(dates)
59
+ solar_year = dates.first.year
60
+
61
+ [].tap do |result|
62
+ date_keys = dates.map { _1.strftime('%-m-%-d').to_sym }
63
+ common_keys = date_keys & solar_holiday_names.keys
64
+ common_keys.each do |key|
65
+ result << {
66
+ date: "#{solar_year}-#{key.to_s}".to_date,
67
+ name: solar_holiday_names[key]
68
+ }
69
+ end
70
+ end
71
+ end
72
+
73
+ def self.lunar_holidays(dates)
74
+ [].tap do |result|
75
+ date_by_lunars = dates.map do |date|
76
+ ldate = lunar_date(date)
77
+ ["#{ldate.month}-#{ldate.day}", date]
78
+ end.to_h
79
+
80
+ common_keys = date_by_lunars.keys & lunar_holiday_names.keys.map { _1.to_s }
81
+ common_keys.each do |key|
82
+ result << {
83
+ date: date_by_lunars[key],
84
+ name: lunar_holiday_names[key.to_sym]
85
+ }
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module VietnameseHoliday
4
+ VERSION = "0.1.8"
5
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'vietnamese_holiday/version'
4
+ require_relative 'vietnamese_holiday/utils'
5
+ require 'lunar_calendar'
6
+
7
+ # The Vietnamese Holiday
8
+ module VietnameseHoliday
9
+ class Error < StandardError; end
10
+
11
+ def self.lunar_date(date)
12
+ Utils.lunar_date(date)
13
+ end
14
+
15
+ def self.check(date)
16
+ Utils.check(date)
17
+ end
18
+
19
+ def self.name(date)
20
+ Utils.name(date)
21
+ end
22
+
23
+ def self.in_month(year, month)
24
+ Utils.holidays(Date.new(year, month).all_month)
25
+ end
26
+
27
+ def self.in_year(year)
28
+ Utils.holidays(Date.new(year).all_year)
29
+ end
30
+
31
+ def self.between(from_date, to_date)
32
+ [].tap do |result|
33
+ date_by_years = (Date.parse(from_date)..Date.parse(to_date)).group_by(&:year)
34
+ date_by_years.each_value do |value|
35
+ result.concat(Utils.holidays(value))
36
+ end
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vietnamese_holiday
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.8
5
+ platform: ruby
6
+ authors:
7
+ - Thanh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lunar_calendar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ description: This library provides a list of public holidays in Vietnam during the
28
+ year. Including solar and lunar holidays.
29
+ email:
30
+ - thanhbk150@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - CHANGELOG.md
36
+ - README.md
37
+ - bin/console
38
+ - bin/setup
39
+ - lib/vietnamese_holiday.rb
40
+ - lib/vietnamese_holiday/utils.rb
41
+ - lib/vietnamese_holiday/version.rb
42
+ homepage: https://github.com/thanhbk150/vietnamese_holiday
43
+ licenses: []
44
+ metadata:
45
+ allowed_push_host: https://rubygems.org/
46
+ homepage_uri: https://github.com/thanhbk150/vietnamese_holiday
47
+ source_code_uri: https://github.com/thanhbk150/vietnamese_holiday
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 2.6.0
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.2.33
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: This library provides a list of public holidays in Vietnam during the year.
67
+ test_files: []