-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathtime_on_earth.10m.rb
executable file
·40 lines (31 loc) · 1.23 KB
/
time_on_earth.10m.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env ruby
# <bitbar.title>Your time on earth</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Tim Regener</bitbar.author>
# <bitbar.author.github>timlapluie</bitbar.author.github>
# <bitbar.desc>Displays the time you are already living.</bitbar.desc>
# <bitbar.image>http://i.imgur.com/EzUARsL.png</bitbar.image>
# <bitbar.dependencies>ruby</bitbar.dependencies>
# --------------------- #
# EDIT THESE VARIABLES. #
# --------------------- #
# Add your Birthday here
# Format: 'YYYY-MM-DD [hh:mm (optional)] [UTC Offset (optional)]'
BIRTHDAY = '1988-01-12 11:42 +01:00'
# -------------------------------------------------------- #
# DON'T EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU'RE DOING. #
# -------------------------------------------------------- #
require 'date'
birth_time = DateTime.parse(BIRTHDAY)
time_now = DateTime.now
delta = time_now - birth_time
days = delta.to_i
hours = (delta * 24)
minutes = (hours % 1) * 60
seconds = (minutes % 1) * 60
def format_int(number)
number.to_i.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
end
puts "#{format_int(days)} days on 🌍"
puts '---'
puts "Impressive! That's #{format_int(hours)} hours, #{format_int(minutes)} minutes, #{format_int(seconds)} seconds."