world_time_in_ruby 0.0.0

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/world_time.rb +26 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6a0be3d4757d535c642372ae2cf22b7154b7eda729a574a98eb6ff0f24d3c9ea
4
+ data.tar.gz: 1a30024e519cc4be3014e6b6cbebd905246f88839bf2a1a95dd8221585f5e27d
5
+ SHA512:
6
+ metadata.gz: 0d1a6e4b0304f1af4eaa49673c1f394bc54e816adcb4f6ac6080b1afef73e0843979af9f44103968deeac75b0b069e76bfed94462c629933aad1d7703227e472
7
+ data.tar.gz: d20b138cb19c82b8d792445070eeea982f11853cea5037746d2760fc54594e7e49c3ff8e719b09838b8a590cd0a6339f688f36e8b5d7f212ac5e64d363e7164c
data/lib/world_time.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'date'
4
+
5
+ class WorldTime
6
+ WORLD_TIME_URL = "http://worldtimeapi.org/api/timezone".freeze
7
+
8
+ def self.timezones(search: nil)
9
+ response = Net::HTTP.get_response(URI(WORLD_TIME_URL))
10
+ body = JSON.parse(response.body)
11
+ if search
12
+ body.filter { |item| item.include?(search)}
13
+ else
14
+ body
15
+ end
16
+ end
17
+
18
+ def self.current_time_for_area(area)
19
+ url_with_area = WORLD_TIME_URL + "/#{area}"
20
+ response = Net::HTTP.get_response(URI(url_with_area))
21
+ body = JSON.parse(response.body)
22
+ date = DateTime.parse(body["datetime"])
23
+ date.strftime('%I:%M:%S %p')
24
+ end
25
+ end
26
+
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: world_time_in_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Anshuman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-06-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Gives the current time anywhere in the world
14
+ email: indigotech@tutorials.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/world_time.rb
20
+ homepage: https://rubygems.org/gems/world_time_ruby
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.2.3
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Gives the current time anywhere in the world
43
+ test_files: []