Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
*.swp
.DS_Store
.ruby-version
Gemfile.lock
coverage/
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-3.2.2
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gem 'astro-algo', :github => 'lessan/astro-algo'
gem "astro-algo", github: "lessan/astro-algo"

# Specify your gem's dependencies in bahai_date.gemspec
gemspec
55 changes: 55 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
GIT
remote: https://github.com/lessan/astro-algo.git
revision: 3613e6fe68597458f3f8079dfcc534c90112a287
specs:
astro-algo (0.0.1)

PATH
remote: .
specs:
bahai_date (1.4.1)
RubySunrise (~> 0.3)
astro-algo (~> 0)
tzinfo (~> 1.2)

GEM
remote: https://rubygems.org/
specs:
RubySunrise (0.3.3)
tzinfo
diff-lcs (1.5.0)
docile (1.4.0)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
thread_safe (0.3.6)
tzinfo (1.2.11)
thread_safe (~> 0.1)

PLATFORMS
arm64-darwin-22

DEPENDENCIES
astro-algo!
bahai_date!
rspec (~> 3)
simplecov (~> 0)

BUNDLED WITH
2.4.22
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
desc 'Open an irb session preloaded with this library'
desc "Open an irb session preloaded with this library"
task :console do
sh 'irb -rubygems -I lib -r bahai_date.rb'
sh "irb -rubygems -I lib -r bahai_date.rb"
end
33 changes: 16 additions & 17 deletions bahai_date.gemspec
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'bahai_date/version'
require "bahai_date/version"

Gem::Specification.new do |s|
s.name = 'bahai_date'
s.version = BahaiDate::VERSION
s.author = 'Lessan Vaezi'
s.email = 'lessan@gmail.com'
s.homepage = 'https://github.com/lessan/bahai-date'
s.summary = "Conversion between Gregorian and Baha'i (or Badi) calendars"
s.description = "Provides functionality to convert between the Gregorian and Baha'i calendar, as well as significant dates and occasions in the Baha'i calendar such as the new year and holy days"
s.licenses = ['Unlicense']
s.name = "bahai_date"
s.version = BahaiDate::VERSION
s.author = "Lessan Vaezi"
s.email = "lessan@gmail.com"
s.homepage = "https://github.com/lessan/bahai-date"
s.summary = "Conversion between Gregorian and Baha'i (or Badi) calendars"
s.description = "Provides functionality to convert between the Gregorian and Baha'i calendar, as well as significant dates and occasions in the Baha'i calendar such as the new year and holy days"
s.licenses = ["Unlicense"]

s.files = Dir['{bin,lib,spec}/**/*'] + %w(LICENSE.md README.md)
s.test_files = Dir['spec/**/*']
s.files = Dir["{bin,lib,spec}/**/*"] + %w[LICENSE.md README.md]

s.required_ruby_version = '>=2.0'
s.add_runtime_dependency 'tzinfo', '~> 1.2'
s.add_runtime_dependency 'RubySunrise', '~> 0.3'
s.add_runtime_dependency 'astro-algo', '~> 0'
s.add_development_dependency 'rspec', '~> 3'
s.add_development_dependency 'simplecov', '~> 0'
s.required_ruby_version = ">=2.0"
s.add_runtime_dependency "tzinfo", "~> 1.2"
s.add_runtime_dependency "RubySunrise", "~> 0.3"
s.add_runtime_dependency "astro-algo", "~> 0"
s.add_development_dependency "rspec", "~> 3"
s.add_development_dependency "simplecov", "~> 0"
end
22 changes: 11 additions & 11 deletions lib/bahai_date.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'date'
require 'bahai_date/version'
require 'bahai_date/logic'
require 'bahai_date/bahai_date'
require 'bahai_date/year'
require 'bahai_date/month'
require 'bahai_date/day'
require 'bahai_date/weekday'
require 'bahai_date/occasion'
require 'bahai_date/occasion_factory'
require 'bahai_date/year_calendar'
require "date"
require "bahai_date/version"
require "bahai_date/logic"
require "bahai_date/bahai_date"
require "bahai_date/year"
require "bahai_date/month"
require "bahai_date/day"
require "bahai_date/weekday"
require "bahai_date/occasion"
require "bahai_date/occasion_factory"
require "bahai_date/year_calendar"
14 changes: 7 additions & 7 deletions lib/bahai_date/bahai_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(params)
validate_ayyam_i_ha
@gregorian_date = to_gregorian
else
fail ArgumentError, 'Invalid arguments. Use a hash with :date or with :year, :month, and :day.'
fail ArgumentError, "Invalid arguments. Use a hash with :date or with :year, :month, and :day."
end
@weekday = Weekday.new(weekday_from_gregorian)
end
Expand All @@ -39,12 +39,12 @@ def short_format
"#{@day.number} #{@month} #{@year.bahai_era}"
end

def +(val)
self.class.new(date: @gregorian_date + val)
def +(other)
self.class.new(date: @gregorian_date + other)
end

def -(val)
self.class.new(date: @gregorian_date - val)
def -(other)
self.class.new(date: @gregorian_date - other)
end

private
Expand Down Expand Up @@ -84,7 +84,7 @@ def from_gregorian
day = days - (342 + ayyam_i_ha_days(year))
end
else
month, day = (days).divmod(19)
month, day = days.divmod(19)
month += 1
end
day += 1
Expand All @@ -93,7 +93,7 @@ def from_gregorian

def weekday_from_gregorian
# saturday (6 in ruby) is the first day of the week
@gregorian_date.wday == 6 ? 1 : @gregorian_date.wday + 2
(@gregorian_date.wday == 6) ? 1 : @gregorian_date.wday + 2
end

def days_from_nawruz
Expand Down
8 changes: 4 additions & 4 deletions lib/bahai_date/day.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module BahaiDate
class Day
TITLES = %w(Baha Jalal Jamal Azamat Nur Rahmat Kalimat Kamal Asma Izzat Mashiyyat Ilm Qudrat Qawl Masail Sharaf Sultan Mulk Ala)
TITLES_HTML = %w(Bahá Jalál Jamál ‘Aẓamat Núr Raḥmat Kalimát Kamál Asmá’ ‘Izzat Ma<u>sh</u>íyyat ‘Ilm Qudrat Qawl Masá’il <u>Sh</u>araf Sulṭán Mulk ‘Alá’)
TITLES_EN = %w(Splendour Glory Beauty Grandeur Light Mercy Words Perfection Names Might Will Knowledge Power Speech Questions Honour Sovereignty Dominion Loftiness)
TITLES = %w[Baha Jalal Jamal Azamat Nur Rahmat Kalimat Kamal Asma Izzat Mashiyyat Ilm Qudrat Qawl Masail Sharaf Sultan Mulk Ala]
TITLES_HTML = %w[Bahá Jalál Jamál ‘Aẓamat Núr Raḥmat Kalimát Kamál Asmá’ ‘Izzat Ma<u>sh</u>íyyat ‘Ilm Qudrat Qawl Masá’il <u>Sh</u>araf Sulṭán Mulk ‘Alá’]
TITLES_EN = %w[Splendour Glory Beauty Grandeur Light Mercy Words Perfection Names Might Will Knowledge Power Speech Questions Honour Sovereignty Dominion Loftiness]

attr_reader :number
attr_accessor :occasions, :weekday
Expand Down Expand Up @@ -36,7 +36,7 @@ def title_index

def validate(number_arg)
number = number_arg.to_i
return if (1..19).include? number
return if (1..19).cover? number
fail ArgumentError, "'#{number}' is not a valid day. Please use 1 to 19."
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/bahai_date/logic.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'bundler/setup'
require 'tzinfo'
require 'solareventcalculator'
require 'astro-algo'
require "bundler/setup"
require "tzinfo"
require "solareventcalculator"
require "astro-algo"

module BahaiDate
class Logic
Expand All @@ -16,8 +16,8 @@ class Logic
# Latitude: 35° 41' 45.9996", Longitude: 51° 25' 23.0016"
# Converted to decimal using:
# http://transition.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html
TEHRAN_LAT = BigDecimal.new('35.696111')
TEHRAN_LONG = BigDecimal.new('51.423056')
TEHRAN_LAT = BigDecimal("35.696111")
TEHRAN_LONG = BigDecimal("51.423056")

# *** Azimuth (for determining sunset times) ***
# Source: http://www.timeanddate.com/astronomy/about-sun-calculator.html
Expand All @@ -27,7 +27,7 @@ class Logic
AZIMUTH = 90.833333

def initialize
@tz = TZInfo::Timezone.get('Asia/Tehran')
@tz = TZInfo::Timezone.get("Asia/Tehran")
end

def self.nawruz_for(year)
Expand Down Expand Up @@ -100,7 +100,7 @@ def bahai_era_to_gregorian_year(year)
private

def localize(time)
(@tz.utc_to_local(time)).to_time
@tz.utc_to_local(time).to_time
end

def increment_if_after_sunset(time)
Expand Down
8 changes: 4 additions & 4 deletions lib/bahai_date/month.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module BahaiDate
class Month
TITLES = %w(Baha Jalal Jamal Azamat Nur Rahmat Kalimat Kamal Asma Izzat Mashiyyat Ilm Qudrat Qawl Masail Sharaf Sultan Mulk Ala Ayyam-i-Ha)
TITLES_HTML = %w(Bahá Jalál Jamál ‘Aẓamat Núr Raḥmat Kalimát Kamál Asmá’ ‘Izzat Ma<u>sh</u>íyyat ‘Ilm Qudrat Qawl Masá’il <u>Sh</u>araf Sulṭán Mulk ‘Alá’ Ayyám-i-Há)
TITLES_EN = %w(Splendour Glory Beauty Grandeur Light Mercy Words Perfection Names Might Will Knowledge Power Speech Questions Honour Sovereignty Dominion Loftiness Ayyam-i-Ha)
TITLES = %w[Baha Jalal Jamal Azamat Nur Rahmat Kalimat Kamal Asma Izzat Mashiyyat Ilm Qudrat Qawl Masail Sharaf Sultan Mulk Ala Ayyam-i-Ha]
TITLES_HTML = %w[Bahá Jalál Jamál ‘Aẓamat Núr Raḥmat Kalimát Kamál Asmá’ ‘Izzat Ma<u>sh</u>íyyat ‘Ilm Qudrat Qawl Masá’il <u>Sh</u>araf Sulṭán Mulk ‘Alá’ Ayyám-i-Há]
TITLES_EN = %w[Splendour Glory Beauty Grandeur Light Mercy Words Perfection Names Might Will Knowledge Power Speech Questions Honour Sovereignty Dominion Loftiness Ayyam-i-Ha]

attr_reader :number, :days

Expand Down Expand Up @@ -45,7 +45,7 @@ def title_index

def validate(number_arg)
number = number_arg.to_i
return if (1..19).include?(number) || number == -1
return if (1..19).cover?(number) || number == -1
fail ArgumentError, "'#{number}' is not a valid month. Please use 1 to 19 or -1 for Ayyam-i-Ha."
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/bahai_date/occasion.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module BahaiDate
class Occasion
attr_reader :type,
:work_suspended,
:title,
:short_title,
:title_html,
:short_title_html
:work_suspended,
:title,
:short_title,
:title_html,
:short_title_html
alias_method :work_suspended?, :work_suspended

def initialize(opts = {})
Expand Down
Loading