weekends 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c70cf6d890ee4e9e53a17816dd772e6ff273957
4
+ data.tar.gz: 5aae575a665953edd5edbe8bc588e1a689ee490b
5
+ SHA512:
6
+ metadata.gz: 8503d9d2a81a89c915665596f22af624c0c92454deadcac016c3ac21b1f86114d934725cfde2a7f20b98d27aa526f8df8e811f452b450fc476cdb36b43f9fa9c
7
+ data.tar.gz: 234b43a5926e486eef5967172b25ab4c10c84869957919b1a2e9f05a59152df0417d41da3efaa551da91e3499c4f57b899a1d07c31c045c859a7709c9e96cf7e
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.idea
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ Exclude:
4
+ - '**/Rakefile'
5
+ - '**/Gemfile'
6
+ - '**/weekends.gemspec'
7
+ Documentation:
8
+ Enabled: false
9
+ Metrics/BlockLength:
10
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.15.3
6
+ script:
7
+ - gem install rubocop
8
+ - rubocop
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 GeorgeGorbanev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # Weekends [![Build Status](https://travis-ci.org/GeorgeGorbanev/weekends.svg?branch=master)](https://travis-ci.org/GeorgeGorbanev/weekends)
2
+
3
+ This gem import class `Weekend` that help to identify weekend dates.
4
+
5
+ ## Usage
6
+
7
+ It is possible to pass `Time`, `Date`, `DateTime` or `ActiveSupport::TimeWithZone` to all methods and `Time` will be returned.
8
+
9
+ Class does't have `ActiveSupport` dependency, so Rails dependencies not required.
10
+
11
+ ### Nearest methods
12
+
13
+ This methods returns nearest weekends:
14
+
15
+ ```ruby
16
+ monday = Time.new(2017, 10, 2)
17
+
18
+ Weekend.nearest_saturday(monday)
19
+ # => 2017-10-07 00:00:00 +0300
20
+
21
+ Weekend.nearest_sunday(monday)
22
+ # => 2017-10-08 00:00:00 +0300
23
+
24
+ Weekend.nearest_full_weekends(monday)
25
+ # => 2017-10-07 00:00:00 +0300..2017-10-08 00:00:00 +0300
26
+
27
+ ```
28
+
29
+ If given weekend, methods will return next weekend:
30
+
31
+ ```ruby
32
+ saturday = Time.new(2017, 10, 7)
33
+
34
+ Weekend.nearest_saturday(saturday)
35
+ # => 2017-10-14 00:00:00 +0300
36
+
37
+ # ...
38
+
39
+ ```
40
+
41
+ ### On date
42
+
43
+ There is also basic method to check if date are weekend:
44
+
45
+ ```ruby
46
+ monday = Time.new(2017, 10, 2)
47
+ saturday = Time.new(2017, 10, 7)
48
+
49
+ Weekend.on_date?(monday)
50
+ # => false
51
+
52
+ Weekend.on_date?(saturday)
53
+ # => true
54
+ ```
55
+
56
+ ## Installation
57
+
58
+ Add this line to your application's Gemfile:
59
+
60
+ ```ruby
61
+ gem 'weekends'
62
+ ```
63
+
64
+ And then execute:
65
+
66
+ $ bundle
67
+
68
+ Or install it yourself as:
69
+
70
+ $ gem install weekends
71
+
72
+ ## TODO:
73
+
74
+ * add Rails optional monky patching, like `Date.today.weekend?` and `Date.today.nearest_sunday`;
75
+ * add getter of weekends on range of dates;
76
+ * add schedule with optionals weekend (for schedule not only 5/2, but 2/2, 2/3 or first weekday not monday).
77
+
78
+
79
+
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'weekend'
4
+ require 'irb'
5
+
6
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/weekend.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'weekends/version'
2
+ require 'weekends/nearest'
3
+ require 'weekends/on_date'
4
+
5
+ class Weekend
6
+ class << self
7
+ include Weekends::Nearest
8
+ include Weekends::OnDate
9
+ end
10
+ end
@@ -0,0 +1,29 @@
1
+ module Weekends
2
+ module Nearest
3
+ DAY = 86_400
4
+
5
+ def nearest_saturday(date)
6
+ wday = date.wday
7
+ diff = wday == 6 ? 7 : 6 - wday
8
+ date + diff * DAY
9
+ end
10
+
11
+ def nearest_sunday(date)
12
+ wday = date.wday
13
+ diff = wday == 7 ? 7 : 7 - wday
14
+ date + diff * DAY
15
+ end
16
+
17
+ def nearest_full_weekends(date)
18
+ if on_date?(date)
19
+ current_weekend_end = nearest_sunday(date)
20
+ next_saturday = nearest_saturday(current_weekend_end)
21
+ next_sunday = nearest_sunday(current_weekend_end)
22
+
23
+ next_saturday..next_sunday
24
+ else
25
+ nearest_saturday(date)..nearest_sunday(date)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module Weekends
2
+ module OnDate
3
+ def on_date?(date)
4
+ date.wday.zero? || date.wday == 6
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Weekends
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/weekends.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'weekends/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'weekends'
7
+ spec.version = Weekends::VERSION
8
+ spec.authors = ['GeorgeGorbanev']
9
+ spec.email = ['GeorgeGorbanev@gmail.com']
10
+
11
+ spec.summary = 'Weekend class with methods like #near and #today?'
12
+ spec.homepage = 'https://github.com/GeorgeGorbanev/weekends'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.15'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weekends
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - GeorgeGorbanev
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - GeorgeGorbanev@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/weekend.rb
73
+ - lib/weekends/nearest.rb
74
+ - lib/weekends/on_date.rb
75
+ - lib/weekends/version.rb
76
+ - weekends.gemspec
77
+ homepage: https://github.com/GeorgeGorbanev/weekends
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.6.10
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: 'Weekend class with methods like #near and #today?'
101
+ test_files: []