1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/logger.rb: refactored to include Logger::Period.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46086 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2014-05-24 23:54:17 +00:00
parent 602f7b5d82
commit cc0ca767f5
2 changed files with 43 additions and 43 deletions

View file

@ -1,3 +1,7 @@
Sun May 25 08:43:16 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* lib/logger.rb: refactored to include Logger::Period.
Sun May 25 06:50:19 2014 Zachary Scott <e@zzak.io>
* vm_eval.c: [DOC] Improve instance_eval description when given a

View file

@ -530,9 +530,48 @@ private
end
end
module Period
module_function
SiD = 24 * 60 * 60
def next_rotate_time(now, shift_age)
case shift_age
when /^daily$/
t = Time.mktime(now.year, now.month, now.mday) + SiD
when /^weekly$/
t = Time.mktime(now.year, now.month, now.mday) + SiD * (7 - now.wday)
when /^monthly$/
t = Time.mktime(now.year, now.month, 1) + SiD * 31
mday = (1 if t.mday > 1)
else
return now
end
if mday or t.hour.nonzero? or t.min.nonzero? or t.sec.nonzero?
t = Time.mktime(t.year, t.month, mday || (t.mday + (t.hour > 12 ? 1 : 0)))
end
t
end
def previous_period_end(now, shift_age)
case shift_age
when /^daily$/
t = Time.mktime(now.year, now.month, now.mday) - SiD / 2
when /^weekly$/
t = Time.mktime(now.year, now.month, now.mday) - (SiD * (now.wday + 1) + SiD / 2)
when /^monthly$/
t = Time.mktime(now.year, now.month, 1) - SiD / 2
else
return now
end
Time.mktime(t.year, t.month, t.mday, 23, 59, 59)
end
end
# Device used for logging messages.
class LogDevice
include Period
attr_reader :dev
attr_reader :filename
@ -700,49 +739,6 @@ private
end
end
module Period
module_function
SiD = 24 * 60 * 60
def next_rotate_time(now, shift_age)
case shift_age
when /^daily$/
t = Time.mktime(now.year, now.month, now.mday) + SiD
when /^weekly$/
t = Time.mktime(now.year, now.month, now.mday) + SiD * (7 - now.wday)
when /^monthly$/
t = Time.mktime(now.year, now.month, 1) + SiD * 31
mday = (1 if t.mday > 1)
else
return now
end
if mday or t.hour.nonzero? or t.min.nonzero? or t.sec.nonzero?
t = Time.mktime(t.year, t.month, mday || (t.mday + (t.hour > 12 ? 1 : 0)))
end
t
end
def previous_period_end(now, shift_age)
case shift_age
when /^daily$/
t = Time.mktime(now.year, now.month, now.mday) - SiD / 2
when /^weekly$/
t = Time.mktime(now.year, now.month, now.mday) - (SiD * (now.wday + 1) + SiD / 2)
when /^monthly$/
t = Time.mktime(now.year, now.month, 1) - SiD / 2
else
return now
end
Time.mktime(t.year, t.month, t.mday, 23, 59, 59)
end
end
class LogDevice
include Period
end
#
# == Description
#