extended_date 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.
- data/lib/extended_date.rb +33 -0
- metadata +64 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
class Date
|
4
|
+
def self.month_first(dat, day)
|
5
|
+
parsed_date = Date.parse(dat.to_s)
|
6
|
+
parsed_date.month_first(day)
|
7
|
+
end
|
8
|
+
|
9
|
+
def beginning_of_month
|
10
|
+
Date.parse(self.strftime("%Y-%m-1"))
|
11
|
+
end
|
12
|
+
|
13
|
+
def month_first(day)
|
14
|
+
req_wday = case
|
15
|
+
when ["sunday", "0"].include?(day.to_s.downcase) then 0
|
16
|
+
when ["monday", "1"].include?(day.to_s.downcase) then 1
|
17
|
+
when ["tuesday", "2"].include?(day.to_s.downcase) then 2
|
18
|
+
when ["wednesday", "3"].include?(day.to_s.downcase) then 3
|
19
|
+
when ["thursday", "4"].include?(day.to_s.downcase) then 4
|
20
|
+
when ["friday", "5"].include?(day.to_s.downcase) then 5
|
21
|
+
when ["saturday", "6"].include?(day.to_s.downcase) then 6
|
22
|
+
else "Unknown"
|
23
|
+
end
|
24
|
+
|
25
|
+
if req_wday == "Unknown"
|
26
|
+
result = "Invalid Input"
|
27
|
+
else
|
28
|
+
req_days = (req_wday - beginning_of_month.wday)
|
29
|
+
req_days = ((req_days>=0) ? req_days : (7+req_days))
|
30
|
+
result = beginning_of_month + req_days
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: extended_date
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- PremNagalla
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-16 00:00:00 +05:30
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: "Date Class extended to get first days of month using, month_first method like, \n\n\
|
22
|
+
\tDate.month_first(Date.today, 0) or\n\n\
|
23
|
+
\tDate.today.month_first('Sunday') "
|
24
|
+
email: prem.nagalla@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- lib/extended_date.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://rubygems.org/gems/extended_date
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.6
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Date Class extended to get first days of month using, month_first method
|
63
|
+
test_files: []
|
64
|
+
|