質問編集履歴
1
現在行っているコードを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -39,3 +39,83 @@
|
|
39
39
|
|
40
40
|
|
41
41
|
```
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```Ruby
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
open(File.expand_path("/home/rails/sample/lasttime.txt"),"w"){|f| f.write DateTime.now.strftime("%F %T") }
|
50
|
+
|
51
|
+
# ↑で一度lasttime.txtに書き込み後下のrbファイルを実行
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
# regularly.rb
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
require 'date'
|
60
|
+
|
61
|
+
require 'active_support/all'
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
p DateTime.now.strftime('%F %T')
|
66
|
+
|
67
|
+
p DateTime.parse(open(File.expand_path("/home/rails/sample/lasttime.txt"),&:read))
|
68
|
+
|
69
|
+
p DateTime.now - DateTime.parse(open(File.expand_path("/home/rails/sample/lasttime.txt"),&:read))
|
70
|
+
|
71
|
+
p DateTime.parse(open(File.expand_path("/home/rails/sample/lasttime.txt"),&:read)) - DateTime.now
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
if DateTime.now - DateTime.parse(open(File.expand_path("/home/rails/sample/lasttime.txt"),&:read)) >= 1/1440r
|
78
|
+
|
79
|
+
p "1分以上経った"
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
else
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
p "1分以上経ってない"
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
# 実行結果
|
100
|
+
|
101
|
+
"2017-09-06 14:55:58"
|
102
|
+
|
103
|
+
Wed, 06 Sep 2017 13:48:17 +0000
|
104
|
+
|
105
|
+
(-28338402251309/86400000000000)
|
106
|
+
|
107
|
+
(2833840202837/8640000000000)
|
108
|
+
|
109
|
+
"1分以上経ってない"
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
計算値が常に0.33付近になってしまう。
|
114
|
+
|
115
|
+
またotn様にご教示いただいた計算順序だとマイナスがついてしまう。
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
```
|