DateUtils 0.3.1.1 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/date_utils.rb +13 -5
- metadata +41 -32
data/lib/date_utils.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
#--
|
4
4
|
# Copyright (c) 2007 Rene Paulokat
|
5
5
|
# This program is free software; you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
7
|
# the Free Software Foundation; either version 2 of the License, or
|
8
8
|
# (at your option) any later version.
|
9
9
|
#
|
@@ -358,8 +358,6 @@ module DateUtils
|
|
358
358
|
@num_days = 30 if [4,6,9,11].include?(@month)
|
359
359
|
( date.leap? ? (@num_days = 29) : (@num_days = 28) ) if @month == 2
|
360
360
|
@last_day = @first_day + ( @num_days - 1 )
|
361
|
-
# XXX instance-variable 'year' added.
|
362
|
-
@year = @date.year
|
363
361
|
end
|
364
362
|
|
365
363
|
end
|
@@ -381,6 +379,9 @@ module DateUtils
|
|
381
379
|
# last day of this year
|
382
380
|
attr_reader :last_day
|
383
381
|
|
382
|
+
# number of weeks in year
|
383
|
+
attr_reader :num_weeks
|
384
|
+
|
384
385
|
# create a new Year -instance with given Date
|
385
386
|
#
|
386
387
|
def initialize(date=nil)
|
@@ -392,6 +393,9 @@ module DateUtils
|
|
392
393
|
@date = date
|
393
394
|
@first_day = Date::parse("#{@year}-01-01")
|
394
395
|
@last_day = Date::parse("#{@year}-12-31")
|
396
|
+
# there are 53 weeks, if year ends on thursdays:
|
397
|
+
@num_weeks = @last_day.wday == 4 ? 53 : 52
|
398
|
+
|
395
399
|
end
|
396
400
|
|
397
401
|
# create a Year-instance
|
@@ -425,7 +429,7 @@ module DateUtils
|
|
425
429
|
arr = []
|
426
430
|
week = Week.new(d)
|
427
431
|
arr.push(week)
|
428
|
-
for i in 1
|
432
|
+
for i in 1..@num_weeks
|
429
433
|
week = week.next
|
430
434
|
arr.push(week)
|
431
435
|
end
|
@@ -435,7 +439,11 @@ module DateUtils
|
|
435
439
|
# returns Week 'num' of self
|
436
440
|
#
|
437
441
|
def get_week(num)
|
438
|
-
! num.kind_of?(Fixnum) || num >
|
442
|
+
if ! num.kind_of?(Fixnum) || num > @num_weeks
|
443
|
+
ArgumentError.new("invalid week-number 'num'")
|
444
|
+
else
|
445
|
+
( @num_weeks > 52 ) ? self.weeks[num-1] : self.weeks[num]
|
446
|
+
end
|
439
447
|
end
|
440
448
|
|
441
449
|
# returns Month 'num' of self
|
metadata
CHANGED
@@ -1,47 +1,56 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: DateUtils
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-11-04 00:00:00 +01:00
|
8
|
-
summary: Some handy utils to deal with Date
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: rene@so36.net
|
12
|
-
homepage: http://rcms.oopen.de
|
13
|
-
rubyforge_project:
|
14
|
-
description:
|
15
|
-
autorequire: date_utils
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: "0.4"
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Rene Paulokat
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
test_files: []
|
8
|
+
autorequire: date_utils
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
35
11
|
|
36
|
-
|
12
|
+
date: 2010-03-16 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
37
15
|
|
38
|
-
|
39
|
-
|
16
|
+
description:
|
17
|
+
email: rene@so36.net
|
40
18
|
executables: []
|
41
19
|
|
42
20
|
extensions: []
|
43
21
|
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- lib/date_utils.rb
|
26
|
+
- README
|
27
|
+
has_rdoc: true
|
28
|
+
homepage: http://labs.so36.net
|
29
|
+
licenses: []
|
30
|
+
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "0"
|
41
|
+
version:
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
44
48
|
requirements: []
|
45
49
|
|
46
|
-
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.3.5
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Some handy utils to deal with Date
|
55
|
+
test_files: []
|
47
56
|
|