monkey-patch 0.0.14 → 0.0.15
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/monkey-patch/time.rb +61 -7
- metadata +2 -3
data/lib/monkey-patch/time.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# Copyright © 2013-2014, Christopher Mark Gore,
|
2
4
|
# Soli Deo Gloria,
|
3
5
|
# All rights reserved.
|
4
6
|
#
|
5
|
-
#
|
7
|
+
# 2317 South River Road, Saint Charles, Missouri 63303 USA.
|
6
8
|
# Web: http://cgore.com
|
7
9
|
# Email: cgore@cgore.com
|
8
10
|
#
|
@@ -10,15 +12,15 @@
|
|
10
12
|
# modification, are permitted provided that the following conditions are met:
|
11
13
|
#
|
12
14
|
# * Redistributions of source code must retain the above copyright
|
13
|
-
#
|
15
|
+
# notice, this list of conditions and the following disclaimer.
|
14
16
|
#
|
15
17
|
# * Redistributions in binary form must reproduce the above copyright
|
16
|
-
#
|
17
|
-
#
|
18
|
+
# notice, this list of conditions and the following disclaimer in the
|
19
|
+
# documentation and/or other materials provided with the distribution.
|
18
20
|
#
|
19
21
|
# * Neither the name of Christopher Mark Gore nor the names of other
|
20
|
-
#
|
21
|
-
#
|
22
|
+
# contributors may be used to endorse or promote products derived from
|
23
|
+
# this software without specific prior written permission.
|
22
24
|
#
|
23
25
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
26
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
@@ -35,6 +37,58 @@
|
|
35
37
|
require 'active_support/core_ext'
|
36
38
|
|
37
39
|
class Time
|
40
|
+
def start_of_second
|
41
|
+
Time.parse strftime "%Y-%m-%d %H:%M:%S %z"
|
42
|
+
end
|
43
|
+
|
44
|
+
def start_of_minute
|
45
|
+
Time.parse strftime "%Y-%m-%d %H:%M:00 %z"
|
46
|
+
end
|
47
|
+
|
48
|
+
def start_of_half_hour
|
49
|
+
if min < 30
|
50
|
+
Time.parse strftime "%Y-%m-%d %H:00:00 %z"
|
51
|
+
else
|
52
|
+
Time.parse strftime "%Y-%m-%d %H:30:00 %z"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def start_of_hour
|
57
|
+
Time.parse strftime "%Y-%m-%d %H:00:00 %z"
|
58
|
+
end
|
59
|
+
|
60
|
+
def start_of_half_day
|
61
|
+
if hour < 12
|
62
|
+
Time.parse strftime "%Y-%m-%d 00:00:00 %z"
|
63
|
+
else
|
64
|
+
Time.parse strftime "%Y-%m-%d 12:00:00 %z"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def start_of_day
|
69
|
+
Time.parse strftime "%Y-%m-%d 00:00:00 %z"
|
70
|
+
end
|
71
|
+
|
72
|
+
def start_of_week
|
73
|
+
start_of_day - wday.days
|
74
|
+
end
|
75
|
+
|
76
|
+
def start_of_month
|
77
|
+
Time.parse strftime "%Y-%m-01 00:00:00 %z"
|
78
|
+
end
|
79
|
+
|
80
|
+
def start_of_year
|
81
|
+
Time.parse strftime "%Y-01-01 00:00:00 %z"
|
82
|
+
end
|
83
|
+
|
84
|
+
def start_of_decade
|
85
|
+
Time.parse strftime "#{year - year % 10}-01-01 00:00:00 %z"
|
86
|
+
end
|
87
|
+
|
88
|
+
def start_of_century
|
89
|
+
Time.parse strftime "#{year - year % 100}-01-01 00:00:00 %z"
|
90
|
+
end
|
91
|
+
|
38
92
|
class << self
|
39
93
|
%w(commercial england gregorian italy jd jisx0301 julian ld mjd ordinal today yesterday)
|
40
94
|
.each do |method|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monkey-patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -65,4 +65,3 @@ signing_key:
|
|
65
65
|
specification_version: 3
|
66
66
|
summary: A simple library with common monkey patches for the standard Ruby classes.
|
67
67
|
test_files: []
|
68
|
-
has_rdoc:
|