date_calculator 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/date_calculator.rb +24 -15
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d503d8c0f2da58a88a287a127a8eb792057aa8ebce9921198ad680fbfe51e097
|
4
|
+
data.tar.gz: 8120aca4f0b8dd9dc15f7ae666c24509fb3db25893aac9245cb09b368b293a0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07c7792748ec644a3757f48ea51ea59327a4b3fa6f6970458453a7bea26100dee40b9b25ce0afd91abf1d9a9cf6b33d4bd7c8afe0b99c8190e6d6ffa12b9a174
|
7
|
+
data.tar.gz: 92aeb5d26ce07f2a3664bde5ba73f9244d1421643630f8c98a273ba0f0147304c188e129a3a6ffe6e06494e97827e6f2d25e0390a9c5bc67d84f32e56c5ba360
|
data/lib/date_calculator.rb
CHANGED
@@ -1,29 +1,38 @@
|
|
1
1
|
require 'date'
|
2
|
+
|
3
|
+
# Provides methods to calculate and manipulate dates.
|
2
4
|
class DateCalculator
|
5
|
+
# Calculates the number of days between two dates.
|
6
|
+
#
|
7
|
+
# @param date1 [Date] The first date.
|
8
|
+
# @param date2 [Date] The second date.
|
9
|
+
# @return [Integer] The number of days between the two dates.
|
3
10
|
def self.days_between(date1, date2)
|
4
|
-
(date2 - date1).to_i
|
5
|
-
|
11
|
+
(date2 - date1).to_i # Computes the difference between the two dates and converts it to an integer.
|
6
12
|
end
|
7
13
|
|
14
|
+
# Adds a specified number of days to a date.
|
15
|
+
#
|
16
|
+
# @param date [Date] The initial date.
|
17
|
+
# @param days [Integer] The number of days to add.
|
18
|
+
# @return [Date] The resulting date after adding the days.
|
8
19
|
def self.add_days(date, days)
|
9
|
-
days.times { date = date.next } #
|
10
|
-
date
|
20
|
+
days.times { date = date.next } # Iterates over the number of days and advances the date by one day at a time.
|
21
|
+
date # Returns the new date.
|
11
22
|
end
|
12
23
|
|
24
|
+
# Checks if a given date is a weekend.
|
25
|
+
#
|
26
|
+
# @param date [Date] The date to check.
|
27
|
+
# @return [Boolean] True if the date is Saturday or Sunday, otherwise false.
|
13
28
|
def self.is_weekend?(date)
|
14
|
-
date.saturday? || date.sunday? #
|
29
|
+
date.saturday? || date.sunday? # Checks if the date is a Saturday or Sunday.
|
15
30
|
end
|
16
31
|
|
32
|
+
# Returns the name of the current day of the week.
|
33
|
+
#
|
34
|
+
# @return [String] The name of the current day of the week (e.g., "Monday", "Tuesday").
|
17
35
|
def self.what_day_is_it_today?
|
18
|
-
Date.today.strftime("%A") #
|
36
|
+
Date.today.strftime("%A") # Returns the name of the current day of the week.
|
19
37
|
end
|
20
|
-
|
21
38
|
end
|
22
|
-
|
23
|
-
date1 = Date.new(2023, 9, 10)
|
24
|
-
date2 = Date.new(2023, 9, 17)
|
25
|
-
|
26
|
-
puts DateCalculator.days_between(date1, date2) # Saída: 7
|
27
|
-
puts DateCalculator.add_days(date1, 5) # Saída: 2023-09-15
|
28
|
-
puts DateCalculator.is_weekend?(date1) # Saída: false
|
29
|
-
puts DateCalculator.what_day_is_it_today? # Exemplo de saída: "Tuesday"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date_calculator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samns
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
62
|
+
version: '3.0'
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - ">="
|