tareek 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/README.md +3 -2
- data/lib/tareek.rb +30 -2
- data/lib/tareek/version.rb +1 -1
- data/spec/tareek_spec.rb +44 -5
- metadata +12 -13
- data/lib/cool_dates.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDViYTJkOTNmYjUyNTcwNTE5NjBkOTM0ZmY0NWYzOGNkNjAwMzQ0NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OTIxNDg3ZDFjNTcxMzBjMmZmMzE2ZDdhOGEyMTA4MDBjZDBkNzhjMQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDg0ZDVjYzYwYzBjZDAyZTQyZGE4MjAyOTZkOGY5YjhiNjIzZjQ0ZTkwODdm
|
10
|
+
NDg2Yzc0Mzc0NjNjOTBjZjBhOGYyOTQxOTYxMWJjZmQwNWJkMmQ0NjQ0MmQz
|
11
|
+
OWI3ZDgxNDNlZGIzZmZjMDk1ODJjMDVjYmU1NmNhNzYxZDUyN2Y=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
M2ZmZjkwYzhlYmViMWQ5MTY0OTI3NmJmYTAyM2VlYjQyZjI0MTY5YTk3ZmNl
|
14
|
+
MDExOWFiZDNkYTQ1NGFmZTAyNDU0NjJlMTMwZmY4YmZmMTZjNzk5NjQ1NmFl
|
15
|
+
ZDc3ZTdhZDk5MDRkNWIyMWNlNDZjYzliYjBiNmIyZWRlYzgzMmE=
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#[Tareek](http://documentup.com/gemathon-warriors/tareek)
|
2
|
+
### The graceful date handler !
|
2
3
|
|
3
4
|
[![Gem Version](https://badge.fury.io/rb/tareek.png)](http://badge.fury.io/rb/tareek)
|
4
5
|
[![Build Status](https://travis-ci.org/gemathon-warriors/tareek.png?branch=master)](https://travis-ci.org/gemathon-warriors/tareek)
|
@@ -55,8 +56,8 @@ Or install it yourself as:
|
|
55
56
|
Tareek::Dates.time_at_day('1/12/2014') #=> "12:00 AM"
|
56
57
|
|
57
58
|
|
58
|
-
#### Returns omniture
|
59
|
-
Tareek::Dates.
|
59
|
+
#### Returns omniture formatted date with time
|
60
|
+
Tareek::Dates.omniture_formated_with_time('1/12/2014') #=> "12/01/2014 12:00:00 AM"
|
60
61
|
|
61
62
|
|
62
63
|
## Contributing
|
data/lib/tareek.rb
CHANGED
@@ -10,6 +10,9 @@ module Tareek
|
|
10
10
|
class Dates
|
11
11
|
class << self
|
12
12
|
|
13
|
+
DAYS_IN_A_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
14
|
+
MONTHS = [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct","Nov", "Dec"]
|
15
|
+
|
13
16
|
def get_middle_of_next_month_date(year, month)
|
14
17
|
(parse_date(month,year) + 45 * 24 * 60 * 60).to_date
|
15
18
|
end
|
@@ -56,7 +59,7 @@ module Tareek
|
|
56
59
|
convert_to_date(date).strftime('%I:%M %p')
|
57
60
|
end
|
58
61
|
|
59
|
-
def
|
62
|
+
def omniture_formatted_with_time(date)
|
60
63
|
convert_to_date(date).strftime('%m/%d/%Y %I:%M:%S %p')
|
61
64
|
end
|
62
65
|
|
@@ -64,7 +67,32 @@ module Tareek
|
|
64
67
|
(date.kind_of? Date) ? date : Date.parse(date)
|
65
68
|
end
|
66
69
|
|
67
|
-
|
70
|
+
def today_date_in_dd_mm_yy_format
|
71
|
+
Time.now.strftime('%d-%m-%Y')
|
72
|
+
end
|
68
73
|
|
74
|
+
def today_date_in_mm_dd_yy_format
|
75
|
+
Time.now.strftime('%m-%d-%Y')
|
76
|
+
end
|
77
|
+
|
78
|
+
def weekend?(day)
|
79
|
+
[0,6].include?(convert_to_date(day).wday)
|
80
|
+
end
|
81
|
+
|
82
|
+
def weekday?(day)
|
83
|
+
!(weekend?(day))
|
84
|
+
end
|
85
|
+
|
86
|
+
def days_in_a_month_of(month, year)
|
87
|
+
month = MONTHS.index(month)
|
88
|
+
return 29 if(month == 2 && Date.leap?(year.to_i))
|
89
|
+
DAYS_IN_A_MONTH[month]
|
90
|
+
end
|
91
|
+
|
92
|
+
def feb_month_of_28_days_for?(year)
|
93
|
+
days_in_a_month_of("Feb", year.to_i) == 28
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
69
97
|
end
|
70
98
|
end
|
data/lib/tareek/version.rb
CHANGED
data/spec/tareek_spec.rb
CHANGED
@@ -23,8 +23,8 @@ describe "Humanize Dates :: " do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should provide date for next specified weekday" do
|
26
|
-
|
27
|
-
|
26
|
+
offset = Date.today.sunday? ? 0 : 7
|
27
|
+
Tareek::Dates.date_of_next("Sunday").should == Tareek::Dates.convert_to_date('Sunday') + offset
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should return humanized date without day" do
|
@@ -42,9 +42,48 @@ describe "Humanize Dates :: " do
|
|
42
42
|
humanized_date.should == "12:00 AM"
|
43
43
|
end
|
44
44
|
|
45
|
-
it "should return omniture
|
46
|
-
|
47
|
-
|
45
|
+
it "should return omniture formatted date with time" do
|
46
|
+
Tareek::Dates.omniture_formatted_with_time('1/12/2014').should == "12/01/2014 12:00:00 AM"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should return today date in dd-mm-yyyy format" do
|
50
|
+
today_date = Tareek::Dates.today_date_in_dd_mm_yy_format
|
51
|
+
Time.now.strftime('%d-%m-%Y').should == today_date
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return today date in mm-dd-yyyy format" do
|
55
|
+
today_date = Tareek::Dates.today_date_in_mm_dd_yy_format
|
56
|
+
Time.now.strftime('%m-%d-%Y').should == today_date
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return true that '22-02-2014' is a weekend" do
|
60
|
+
weekend = Tareek::Dates.weekend?("22-02-2014")
|
61
|
+
weekend.should == true
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return true that '24-02-2014' is a weekday" do
|
65
|
+
weekday = Tareek::Dates.weekday?("24-02-2014")
|
66
|
+
weekday.should == true
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should return 29 days for Feb 2012" do
|
70
|
+
total_days = Tareek::Dates.days_in_a_month_of("Feb", 2012)
|
71
|
+
total_days.should == 29
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should return 28 days for Feb 2014" do
|
75
|
+
total_days = Tareek::Dates.days_in_a_month_of("Feb", 2014)
|
76
|
+
total_days.should == 28
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return fals that Feb 2012 is of 28 days" do
|
80
|
+
total_days = Tareek::Dates.feb_month_of_28_days_for?(2012)
|
81
|
+
total_days.should == false
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return true that Feb 2014 is of 28 days" do
|
85
|
+
total_days = Tareek::Dates.feb_month_of_28_days_for?(2014)
|
86
|
+
total_days.should == true
|
48
87
|
end
|
49
88
|
|
50
89
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tareek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikhil Nanjappa
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2014-02-
|
15
|
+
date: 2014-02-25 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|
@@ -32,56 +32,56 @@ dependencies:
|
|
32
32
|
name: rake
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
|
-
- - '>='
|
35
|
+
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- - '>='
|
42
|
+
- - ! '>='
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '0'
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: activesupport
|
47
47
|
requirement: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
|
-
- - '>='
|
49
|
+
- - ! '>='
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: 2.3.16
|
52
52
|
type: :development
|
53
53
|
prerelease: false
|
54
54
|
version_requirements: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
|
-
- - '>='
|
56
|
+
- - ! '>='
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: 2.3.16
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rspec
|
61
61
|
requirement: !ruby/object:Gem::Requirement
|
62
62
|
requirements:
|
63
|
-
- - '>='
|
63
|
+
- - ! '>='
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
68
|
version_requirements: !ruby/object:Gem::Requirement
|
69
69
|
requirements:
|
70
|
-
- - '>='
|
70
|
+
- - ! '>='
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '0'
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: coveralls
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
|
-
- - '>='
|
77
|
+
- - ! '>='
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
type: :development
|
81
81
|
prerelease: false
|
82
82
|
version_requirements: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- - '>='
|
84
|
+
- - ! '>='
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
description: It gives you dates like, middle of the month, middle of next month etc.
|
@@ -102,7 +102,6 @@ files:
|
|
102
102
|
- LICENSE.txt
|
103
103
|
- README.md
|
104
104
|
- Rakefile
|
105
|
-
- lib/cool_dates.rb
|
106
105
|
- lib/tareek.rb
|
107
106
|
- lib/tareek/version.rb
|
108
107
|
- spec/spec_helper.rb
|
@@ -118,12 +117,12 @@ require_paths:
|
|
118
117
|
- lib
|
119
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
119
|
requirements:
|
121
|
-
- - '>='
|
120
|
+
- - ! '>='
|
122
121
|
- !ruby/object:Gem::Version
|
123
122
|
version: '0'
|
124
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
124
|
requirements:
|
126
|
-
- - '>='
|
125
|
+
- - ! '>='
|
127
126
|
- !ruby/object:Gem::Version
|
128
127
|
version: '0'
|
129
128
|
requirements: []
|
data/lib/cool_dates.rb
DELETED
@@ -1,18 +0,0 @@
|
|
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
|