ruby-changes:56348
From: Yusuke <ko1@a...>
Date: Tue, 2 Jul 2019 23:50:56 +0900 (JST)
Subject: [ruby-changes:56348] Yusuke Endoh: 649753b7f5 (master): Fix timezone issue for logger period's tests
https://git.ruby-lang.org/ruby.git/commit/?id=649753b7f5 From 649753b7f5410552c70931e32c193d83df3af97e Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Tue, 2 Jul 2019 15:45:13 +0100 Subject: Fix timezone issue for logger period's tests This is a retry of 181b966e7553ac53d034266a7cdc18664d080814. "Revert "Add a missing tests for Logger::Period module"" is also reverted. diff --git a/test/logger/test_logperiod.rb b/test/logger/test_logperiod.rb new file mode 100644 index 0000000..e3be0a6 --- /dev/null +++ b/test/logger/test_logperiod.rb @@ -0,0 +1,85 @@ https://github.com/ruby/ruby/blob/trunk/test/logger/test_logperiod.rb#L1 +# coding: US-ASCII +# frozen_string_literal: false +require 'test/unit' +require 'logger' +require 'time' + +class TestLogPeriod < Test::Unit::TestCase + def test_next_rotate_time + time = Time.parse("2019-07-18 13:52:02") + + daily_result = Logger::Period.next_rotate_time(time, 'daily') + next_day = Time.parse("2019-07-19 00:00:00") + assert_equal(next_day, daily_result) + + weekly_result = Logger::Period.next_rotate_time(time, 'weekly') + next_week = Time.parse("2019-07-21 00:00:00") + assert_equal(next_week, weekly_result) + + monthly_result = Logger::Period.next_rotate_time(time, 'monthly') + next_month = Time.parse("2019-08-1 00:00:00") + assert_equal(next_month, monthly_result) + + result = Logger::Period.next_rotate_time(time, 'invalid') + assert_equal(time, result) + end + + def test_next_rotate_time_extreme_cases + # First day of Month and Saturday + time = Time.parse("2018-07-01 00:00:00") + + daily_result = Logger::Period.next_rotate_time(time, 'daily') + next_day = Time.parse("2018-07-02 00:00:00") + assert_equal(next_day, daily_result) + + weekly_result = Logger::Period.next_rotate_time(time, 'weekly') + next_week = Time.parse("2018-07-08 00:00:00") + assert_equal(next_week, weekly_result) + + monthly_result = Logger::Period.next_rotate_time(time, 'monthly') + next_month = Time.parse("2018-08-1 00:00:00") + assert_equal(next_month, monthly_result) + + result = Logger::Period.next_rotate_time(time, 'invalid') + assert_equal(time, result) + end + + def test_previous_period_end + time = Time.parse("2019-07-18 13:52:02") + + daily_result = Logger::Period.previous_period_end(time, 'daily') + day_ago = Time.parse("2019-07-17 23:59:59") + assert_equal(day_ago, daily_result) + + weekly_result = Logger::Period.previous_period_end(time, 'weekly') + week_ago = Time.parse("2019-07-13 23:59:59") + assert_equal(week_ago, weekly_result) + + monthly_result = Logger::Period.previous_period_end(time, 'monthly') + month_ago = Time.parse("2019-06-30 23:59:59") + assert_equal(month_ago, monthly_result) + + result = Logger::Period.previous_period_end(time, 'invalid') + assert_equal(time, result) + end + + def test_previous_period_end_extreme_cases + # First day of Month and Saturday + time = Time.parse("2018-07-01 00:00:00") + + daily_result = Logger::Period.previous_period_end(time, 'daily') + day_ago = Time.parse("2018-06-30 23:59:59") + assert_equal(day_ago, daily_result) + + weekly_result = Logger::Period.previous_period_end(time, 'weekly') + week_ago = Time.parse("2018-06-30 23:59:59") + assert_equal(week_ago, weekly_result) + + monthly_result = Logger::Period.previous_period_end(time, 'monthly') + month_ago = Time.parse("2018-06-30 23:59:59") + assert_equal(month_ago, monthly_result) + + result = Logger::Period.previous_period_end(time, 'invalid') + assert_equal(time, result) + end +end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/