birthday_calculator 0.0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/birthday_calculator.rb +60 -0
  3. metadata +57 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 48e69fe5b091bd622a4e1e1c7957a8881f2be0f5de3edf80e3e29c9cccea8228
4
+ data.tar.gz: aa7f9f3e8a74b488109ae84b757121c23f4a7f3b18f4d4e0b1ee7f8634940470
5
+ SHA512:
6
+ metadata.gz: b88d4968a35760346dc2f50ab9d83ab09f29fa42182f68976587e4a5ee95731a3532428e95506a7372dbd555927a2feacc6cfe570e54f838d5da27e6b245c10e
7
+ data.tar.gz: eebdbe9d4d7e61e087ec61440ba89036a0e7f495845b4c23df3a08645d07368e54eb025f6800611b13bf54b3b6f4eeec7db8d47be509c42f332536a9c6b0fa97
@@ -0,0 +1,60 @@
1
+ require 'time'
2
+ require 'date'
3
+ require 'active_support/all'
4
+
5
+ class BirthdayCalculator
6
+ def initialize(date)
7
+ @date = date
8
+ end
9
+
10
+ def days_to_next_birthday
11
+ birthday_date =
12
+ if @date.is_a?(DateTime)
13
+ @date
14
+ else
15
+ DateTime.parse(@date)
16
+ end
17
+
18
+ current_date = DateTime.now
19
+
20
+ current_birthday = modify_date(current_date.year,
21
+ birthday_date.month,
22
+ birthday_date.day,
23
+ birthday_date.hour,
24
+ birthday_date.min,
25
+ birthday_date.sec)
26
+
27
+ time_left =
28
+ if current_birthday - current_date >= 0
29
+ current_birthday.utc - current_date.utc - Time.now.utc_offset
30
+ else
31
+ modify_date(current_date.year + 1,
32
+ current_birthday.month,
33
+ current_birthday.day,
34
+ current_birthday.hour,
35
+ current_birthday.min,
36
+ current_birthday.sec).utc - current_date.utc - Time.now.utc_offset
37
+ end
38
+
39
+ mm, ss = time_left.divmod(60)
40
+ hh, mm = mm.divmod(60)
41
+ dd, hh = hh.divmod(24)
42
+
43
+ puts "It's left #{dd} days, #{hh} hours and #{mm} minutes to your birthday!"
44
+ return "It's left #{dd} days, #{hh} hours and #{mm} minutes to your birthday!"
45
+ end
46
+
47
+ def modify_date(year, month, day, hour, min, sec)
48
+ begin
49
+ DateTime.new(year, month, day, hour, min, sec)
50
+ rescue ArgumentError
51
+ for i in 1..4
52
+ begin
53
+ return DateTime.new(year + i, month, day, hour, min, sec)
54
+ rescue ArgumentError
55
+ next
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: birthday_calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Uliana Dzoba
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.7'
27
+ description:
28
+ email: ulianadzoba@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/birthday_calculator.rb
34
+ homepage: https://rubygems.org/gems/birthday_calculator
35
+ licenses:
36
+ - MIT
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.1.2
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Calculate days left yo your birthday
57
+ test_files: []