tareek 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +19 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +5 -0
- data/lib/cool_dates.rb +18 -0
- data/lib/tareek/version.rb +3 -0
- data/lib/tareek.rb +70 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/tareek_spec.rb +50 -0
- data/tareek.gemspec +26 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a64181699fe266f2a1d96c9db1eb42d14b3991d8
|
4
|
+
data.tar.gz: 20771cd34a9a33a827eef34d04bb26c5bb6e0170
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 86f0bad725987451243139dda152d6dad191e44b8d8108b4b72fe58f1c0450e902c748ae0f42c0a7154eae98ba749ff3eb162454d955842fc87beb7997f5ea05
|
7
|
+
data.tar.gz: f5da552013dc1db019cad971f0a02f8309559dd9a9f0d7e8fc8d12fa2046f484cc0eb9158e572308f1455a7c6b00f8a3c99f612f48d34ed7ce5d3b604f5cac31
|
data/.coveralls.yml
ADDED
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ashish Upadhyay
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#[Tareek](http://documentup.com/gemathon-warriors/tareek)
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/tareek.png)](http://badge.fury.io/rb/tareek)
|
4
|
+
[![Build Status](https://travis-ci.org/gemathon-warriors/tareek.png?branch=master)](https://travis-ci.org/gemathon-warriors/tareek)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/gemathon-warriors/tareek.png)](https://codeclimate.com/github/gemathon-warriors/tareek)
|
6
|
+
[![Dependency Status](https://gemnasium.com/gemathon-warriors/tareek.png)](https://gemnasium.com/gemathon-warriors/tareek)
|
7
|
+
|
8
|
+
It gives you dates like, middle of the month, middle of next month etc.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'tareek'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install tareek
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
#### Returns middle date of next month of the specified year
|
27
|
+
Tareek::Dates.get_middle_of_next_month_date(2014,3) #=> "2014-04-15"
|
28
|
+
|
29
|
+
|
30
|
+
#### Returns middle date of past month of specified year
|
31
|
+
Tareek::Dates.get_middle_of_past_month_date(2014,3) #=> "2014-02-14"
|
32
|
+
|
33
|
+
|
34
|
+
#### Returns day of middle date of next month of the specified year
|
35
|
+
Tareek::Dates.day_middle_of_next_month_date(2014,3) #=> "Tuesday"
|
36
|
+
|
37
|
+
|
38
|
+
#### Returns day of the middle date of past month of specified year
|
39
|
+
Tareek::Dates.day_middle_of_past_month_date(2014,3) #=> "Friday"
|
40
|
+
|
41
|
+
|
42
|
+
#### Returns date for next specified weekday
|
43
|
+
Tareek::Dates.date_of_next("Sunday") ##=>> 'Sunday'
|
44
|
+
|
45
|
+
|
46
|
+
#### Returns humanized date without day
|
47
|
+
Tareek::Dates.humanize_without_day('1/12/2014') #=> "Dec 14"
|
48
|
+
|
49
|
+
|
50
|
+
#### Returns humanized date with day
|
51
|
+
Tareek::Dates.humanize_with_day('1/12/2014') #=> "01-Dec-14"
|
52
|
+
|
53
|
+
|
54
|
+
#### Returns time in the date
|
55
|
+
Tareek::Dates.time_at_day('1/12/2014') #=> "12:00 AM"
|
56
|
+
|
57
|
+
|
58
|
+
#### Returns omniture format with time
|
59
|
+
Tareek::Dates.omniture_format_with_time('1/12/2014') #=> "12/01/2014 12:00:00 AM"
|
60
|
+
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
1. Fork it ( http://github.com/<my-github-username>/tareek/fork )
|
65
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
66
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
67
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
68
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/cool_dates.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'time'
|
2
|
+
class CoolDates
|
3
|
+
def get_middle_of_next_month_date year, month
|
4
|
+
(Time.parse("1-#{month}-#{year} 0:1 UTC") + 45 * 24 * 60 * 60).to_date
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_middle_of_past_month_date year, month
|
8
|
+
(Time.parse("1-#{month}-#{year} 0:1 UTC") - 15 * 24 * 60 * 60).to_date
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.get_middle_of_next_month_date year, month
|
12
|
+
(Time.parse("1-#{month}-#{year} 0:1 UTC") + 45 * 24 * 60 * 60).to_date
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get_middle_of_past_month_date year, month
|
16
|
+
(Time.parse("1-#{month}-#{year} 0:1 UTC") - 15 * 24 * 60 * 60).to_date
|
17
|
+
end
|
18
|
+
end
|
data/lib/tareek.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require "tareek/version"
|
2
|
+
require 'active_support/version'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
if ActiveSupport::VERSION::MAJOR > 2
|
6
|
+
require 'active_support/core_ext/numeric'
|
7
|
+
end
|
8
|
+
|
9
|
+
module Tareek
|
10
|
+
class Dates
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def get_middle_of_next_month_date(year, month)
|
14
|
+
(parse_date(month,year) + 45 * 24 * 60 * 60).to_date
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_middle_of_past_month_date(year, month)
|
18
|
+
(parse_date(month,year) - 15 * 24 * 60 * 60).to_date
|
19
|
+
end
|
20
|
+
|
21
|
+
def day_middle_of_next_month_date(year, month)
|
22
|
+
day_on(get_middle_of_next_month_date(year, month))
|
23
|
+
end
|
24
|
+
|
25
|
+
def day_middle_of_past_month_date(year, month)
|
26
|
+
day_on(get_middle_of_past_month_date(year, month))
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_date(month,year)
|
30
|
+
Time.parse("1-#{month}-#{year} 0:1 UTC")
|
31
|
+
end
|
32
|
+
|
33
|
+
def date_of_next(day)
|
34
|
+
date = convert_to_date(day)
|
35
|
+
delta = date > Date.today ? 0 : 7
|
36
|
+
date + delta
|
37
|
+
end
|
38
|
+
|
39
|
+
def day_on(date)
|
40
|
+
convert_to_date(date).strftime("%A")
|
41
|
+
end
|
42
|
+
|
43
|
+
def humanize_without_day(date)
|
44
|
+
convert_to_date(date).strftime('%b %y')
|
45
|
+
end
|
46
|
+
|
47
|
+
def humanize_with_day(date)
|
48
|
+
convert_to_date(date).strftime('%d-%b-%y')
|
49
|
+
end
|
50
|
+
|
51
|
+
def humanize_with_day_and_full_year(date)
|
52
|
+
convert_to_date(date).strftime('%d %b %Y')
|
53
|
+
end
|
54
|
+
|
55
|
+
def time_at_day(date)
|
56
|
+
convert_to_date(date).strftime('%I:%M %p')
|
57
|
+
end
|
58
|
+
|
59
|
+
def omniture_format_with_time(date)
|
60
|
+
convert_to_date(date).strftime('%m/%d/%Y %I:%M:%S %p')
|
61
|
+
end
|
62
|
+
|
63
|
+
def convert_to_date(date)
|
64
|
+
(date.kind_of? Date) ? date : Date.parse(date)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
require 'tareek'
|
4
|
+
|
5
|
+
require 'coveralls'
|
6
|
+
Coveralls.wear!
|
7
|
+
|
8
|
+
|
9
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
10
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
11
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
12
|
+
# loaded once.
|
13
|
+
#
|
14
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
17
|
+
config.run_all_when_everything_filtered = true
|
18
|
+
# config.filter_run :focus
|
19
|
+
|
20
|
+
# Run specs in random order to surface order dependencies. If you find an
|
21
|
+
# order dependency and want to debug it, you can fix the order by providing
|
22
|
+
# the seed, which is printed after each run.
|
23
|
+
# --seed 1234
|
24
|
+
config.order = 'random'
|
25
|
+
end
|
data/spec/tareek_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Humanize Dates :: " do
|
4
|
+
|
5
|
+
it "should return middle date of next month of the specified year" do
|
6
|
+
middle_of_next_month = Tareek::Dates.get_middle_of_next_month_date(2014,3)
|
7
|
+
middle_of_next_month.to_s.should == "2014-04-15"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return middle date of past month of specified year" do
|
11
|
+
middle_of_past_month = Tareek::Dates.get_middle_of_past_month_date(2014,3)
|
12
|
+
middle_of_past_month.to_s.should == "2014-02-14"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return day of middle date of next month of the specified year" do
|
16
|
+
day_middle_of_next_month = Tareek::Dates.day_middle_of_next_month_date(2014,3)
|
17
|
+
day_middle_of_next_month.to_s.should == "Tuesday"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return day of the middle date of past month of specified year" do
|
21
|
+
day_middle_of_past_month = Tareek::Dates.day_middle_of_past_month_date(2014,3)
|
22
|
+
day_middle_of_past_month.to_s.should == "Friday"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should provide date for next specified weekday" do
|
26
|
+
pending "Dont know how to test this"
|
27
|
+
day_middle_of_past_month = Tareek::Dates.date_of_next("Sunday")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return humanized date without day" do
|
31
|
+
humanized_date = Tareek::Dates.humanize_without_day('1/12/2014')
|
32
|
+
humanized_date.should == "Dec 14"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return humanized date with day" do
|
36
|
+
humanized_date = Tareek::Dates.humanize_with_day('1/12/2014')
|
37
|
+
humanized_date.should == "01-Dec-14"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should return time in the date" do
|
41
|
+
humanized_date = Tareek::Dates.time_at_day('1/12/2014')
|
42
|
+
humanized_date.should == "12:00 AM"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return omniture format with time" do
|
46
|
+
humanized_date = Tareek::Dates.omniture_format_with_time('1/12/2014')
|
47
|
+
humanized_date.should == "12/01/2014 12:00:00 AM"
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/tareek.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tareek/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tareek"
|
8
|
+
spec.version = Tareek::VERSION
|
9
|
+
spec.authors = ["Nikhil Nanjappa", "Ashish Upadhyay", "Ankur Gera", "Gourav Tiwari", "Hrishita Vaish"]
|
10
|
+
spec.email = ["nikhil.nanjappa@tcs.com", "ashish.upadhyaye@gmail.com", "ankurgera@gmail.com", "gouravtiwari21@gmail.com", "vaish.hrishita@tcs.com"]
|
11
|
+
spec.summary = %q{Humanized Dates for use !}
|
12
|
+
spec.description = %q{It gives you dates like, middle of the month, middle of next month etc.}
|
13
|
+
spec.homepage = "https://github.com/gemathon-warriors/tareek"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "activesupport",'>= 2.3.16'
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'coveralls'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tareek
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nikhil Nanjappa
|
8
|
+
- Ashish Upadhyay
|
9
|
+
- Ankur Gera
|
10
|
+
- Gourav Tiwari
|
11
|
+
- Hrishita Vaish
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
date: 2014-02-22 00:00:00.000000000 Z
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: bundler
|
19
|
+
requirement: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '1.5'
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.5'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rake
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: activesupport
|
47
|
+
requirement: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 2.3.16
|
52
|
+
type: :development
|
53
|
+
prerelease: false
|
54
|
+
version_requirements: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 2.3.16
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rspec
|
61
|
+
requirement: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: coveralls
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
type: :development
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
description: It gives you dates like, middle of the month, middle of next month etc.
|
88
|
+
email:
|
89
|
+
- nikhil.nanjappa@tcs.com
|
90
|
+
- ashish.upadhyaye@gmail.com
|
91
|
+
- ankurgera@gmail.com
|
92
|
+
- gouravtiwari21@gmail.com
|
93
|
+
- vaish.hrishita@tcs.com
|
94
|
+
executables: []
|
95
|
+
extensions: []
|
96
|
+
extra_rdoc_files: []
|
97
|
+
files:
|
98
|
+
- .coveralls.yml
|
99
|
+
- .gitignore
|
100
|
+
- .travis.yml
|
101
|
+
- Gemfile
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- lib/cool_dates.rb
|
106
|
+
- lib/tareek.rb
|
107
|
+
- lib/tareek/version.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- spec/tareek_spec.rb
|
110
|
+
- tareek.gemspec
|
111
|
+
homepage: https://github.com/gemathon-warriors/tareek
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - '>='
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.2.2
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Humanized Dates for use !
|
135
|
+
test_files:
|
136
|
+
- spec/spec_helper.rb
|
137
|
+
- spec/tareek_spec.rb
|