Skip to content

Commit e801379

Browse files
committed
parameter sheet: accept H:mm style for UsageTimeLimit
1 parent 7c04d12 commit e801379

4 files changed

Lines changed: 42 additions & 17 deletions

File tree

‎docs/sources/BrowserGuardAdminGuide.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,8 @@ JSON の書式を意識せずに、機能ごとのシートの表へ設定値を
731731
* 編集するのは「値」列だけです。
732732
「内部パラメータ名」列は設定ファイルの項目名と対応しているため、変更すると出力できなくなります。
733733
* 有効・無効や動作の種類は、プルダウンから選択します。
734-
* 数値は 0 以上の整数で記入します。
734+
* 数値は 0 以上の整数で記入します。空欄にはできません。
735+
* 空欄のまま出力しようとすると、入力エラーになります。
735736
* 拡張子やプログラムの一覧などの表で行が足りない場合は、
736737
表の最終行で Tab キーを押すか、表内に行を挿入して増やします。
737738
* 空欄の行は出力時に読み飛ばされます。
@@ -1000,8 +1001,8 @@ JSON の書式を意識せずに、機能ごとのシートの表へ設定値を
10001001
| `Enabled` | 真偽値 | `false` | この機能を有効にする |
10011002
| `MaxContinuousMinutes` | 数値 | `0` | 連続して使用できる時間(分)。`0` は無制限 |
10021003
| `AllowedTimeRanges` | オブジェクトの配列 | `[]` | 使用を許可する時間帯。空の場合は時間帯では制限しない |
1003-
| `AllowedTimeRanges[].Start` | 文字列 | `""` | 開始時刻(`HH:mm`、24 時間表記の現地時刻) |
1004-
| `AllowedTimeRanges[].End` | 文字列 | `""` | 終了時刻(`HH:mm`、24 時間表記の現地時刻) |
1004+
| `AllowedTimeRanges[].Start` | 文字列 | `""` | 開始時刻(`H:mm` または `HH:mm`、24 時間表記の現地時刻) |
1005+
| `AllowedTimeRanges[].End` | 文字列 | `""` | 終了時刻(`H:mm` または `HH:mm`、24 時間表記の現地時刻) |
10051006
| `OnExceeded.Action` | 文字列 | `"WarnOnly"` | 超過時の動作。`WarnOnly` または `Terminate` |
10061007
| `OnExceeded.GraceSeconds` | 数値 | `60` | `Terminate` の場合に、警告してから終了するまでの猶予(秒) |
10071008
| `OnExceeded.ReWarnIntervalMinutes` | 数値 | `10` | 警告を出し直す間隔(分)。`0` の場合は繰り返さない |
@@ -1011,7 +1012,7 @@ JSON の書式を意識せずに、機能ごとのシートの表へ設定値を
10111012
* 終了が開始より**前**である場合、日をまたぐ指定と解釈されます。
10121013
`{ "Start": "22:00", "End": "02:00" }` は日をまたぐ 4 時間の時間帯です。
10131014
* 開始と終了が同じ場合は、終日を表します。
1014-
* `HH:mm` として読み取れない時間帯は無視されます。
1015+
* `H:mm` または `HH:mm` として読み取れない時間帯は無視されます。
10151016

10161017
### 超過時の動作
10171018

‎tools/parameter-sheet/ExportConfig.bas‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ Private Function CollectProblems() As Collection
302302
startText = TimeText(lo, CLng(r), 1)
303303
endText = TimeText(lo, CLng(r), 2)
304304
If Not IsHourMinute(startText) Or Not IsHourMinute(endText) Then
305-
problems.Add "・使用時間の制限: " & r & " 行目の時刻は HH:mm 形式で入力してください。"
305+
problems.Add "・使用時間の制限: " & r & " 行目の時刻は H:mm または HH:mm 形式で入力してください。"
306306
End If
307307
Next r
308308

@@ -314,7 +314,11 @@ Private Sub CheckLong(ByVal problems As Collection, ByVal tableName As String, _
314314
Dim v As Variant
315315

316316
v = ParamRaw(tableName, paramName)
317-
If Trim$(CStr(v & "")) = "" Then Exit Sub
317+
' 空欄は 0 として出力されてしまい、保持日数の 0 (無期限) のように意味が変わるため止める。
318+
If Trim$(CStr(v & "")) = "" Then
319+
problems.Add "・" & sheetLabel & ": " & paramName & " が空欄です。0 以上の整数を入力してください。"
320+
Exit Sub
321+
End If
318322

319323
If Not IsNumeric(v) Then
320324
problems.Add "・" & sheetLabel & ": " & paramName & " には数値を入力してください。"
@@ -324,16 +328,26 @@ Private Sub CheckLong(ByVal problems As Collection, ByVal tableName As String, _
324328
End Sub
325329

326330
Private Function IsHourMinute(ByVal s As String) As Boolean
331+
IsHourMinute = (NormalizeHourMinute(s) <> "")
332+
End Function
333+
334+
' H:mm または HH:mm を HH:mm に揃える。読めなければ空文字。
335+
' 時を 1 桁でも受け付けるのは、本体 (usage-time-limit.js の parseTimeOfDay) に合わせるため。
336+
Private Function NormalizeHourMinute(ByVal s As String) As String
337+
Dim p As Long
327338
Dim hourPart As String
328339
Dim minutePart As String
329340

330-
If Len(s) <> 5 Or Mid$(s, 3, 1) <> ":" Then Exit Function
341+
p = InStr(s, ":")
342+
If p = 0 Then Exit Function
331343

332-
hourPart = Left$(s, 2)
333-
minutePart = Right$(s, 2)
334-
If Not IsNumeric(hourPart) Or Not IsNumeric(minutePart) Then Exit Function
344+
hourPart = Left$(s, p - 1)
345+
minutePart = Mid$(s, p + 1)
346+
If Not (hourPart Like "#" Or hourPart Like "##") Then Exit Function
347+
If Not (minutePart Like "##") Then Exit Function
348+
If CLng(hourPart) > 23 Or CLng(minutePart) > 59 Then Exit Function
335349

336-
IsHourMinute = (CLng(hourPart) <= 23 And CLng(minutePart) <= 59)
350+
NormalizeHourMinute = Format$(CLng(hourPart), "00") & ":" & minutePart
337351
End Function
338352

339353

@@ -446,16 +460,18 @@ Private Function CellText(ByVal lo As ListObject, ByVal rowIndex As Long, ByVal
446460
End Function
447461

448462
' 時刻はシリアル値で入ることもあるので、どちらでも HH:mm に揃える。
463+
' 文字列の "0900" も IsNumeric は真を返すため、数値の型で入っているときだけ時刻として扱う。
449464
Private Function TimeText(ByVal lo As ListObject, ByVal rowIndex As Long, ByVal colIndex As Long) As String
450465
Dim v As Variant
451466

452467
v = lo.DataBodyRange.Cells(rowIndex, colIndex).Value
453468
If Trim$(CStr(v & "")) = "" Then Exit Function
454469

455-
If IsNumeric(v) Then
470+
If VarType(v) = vbDouble Or VarType(v) = vbDate Then
456471
TimeText = Format$(CDate(v), "hh:nn")
457472
Else
458473
TimeText = Trim$(CStr(v))
474+
If IsHourMinute(TimeText) Then TimeText = NormalizeHourMinute(TimeText)
459475
End If
460476
End Function
461477

‎tools/parameter-sheet/make-parameter-sheet.ps1‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ try {
230230
$row++
231231
foreach ($line in @(
232232
'・「値」列だけを編集してください。「内部パラメータ名」は JSON のキーと対応しており、変更すると出力できなくなります。',
233-
'・有効・無効はプルダウンから選びます。数値は 0 以上の整数です。',
233+
'・有効・無効はプルダウンから選びます。数値は 0 以上の整数で、空欄にはできません。',
234234
'・表の行が足りない場合は、表の最終行で Tab キーを押すか、表内で行を挿入して増やせます。',
235235
'・空欄の行は出力時に読み飛ばされるため、消し忘れの空行があっても問題ありません。')) {
236236
$ws.Cells($row, 1).Value2 = $line
@@ -431,7 +431,7 @@ try {
431431
$listRow = $row + 8
432432
Set-SectionLabel -Sheet $ws -Row $listRow -Column 1 -Text '利用を許可する時間帯'
433433
foreach ($line in @(
434-
'24 時間表記の HH:mm で記入します。1 行も書かなければ時間帯では制限しません。',
434+
'24 時間表記の H:mm または HH:mm で記入します (9:00 と 09:00 はどちらも可)。1 行も書かなければ時間帯では制限しません。',
435435
'終了が開始より後にならない場合は日をまたぐ指定です (22:00 - 02:00 なら 4 時間)。')) {
436436
$ws.Cells($listRow + 1, 1).Value2 = $line
437437
$ws.Cells($listRow + 1, 1).Font.Color = $COLOR_MUTED

‎tools/parameter-sheet/test-parameter-sheet.ps1‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ try {
113113
(Get-ParamCell $wb 'T_UsageTimeLimit' 'OnExceeded.Action').Value2 = 'ブラウザーを終了する'
114114

115115
$ranges = Get-Table $wb 'A_UsageTimeLimit_AllowedTimeRanges'
116-
$ranges.DataBodyRange.Cells(1, 1).Value2 = '09:00'
116+
$ranges.DataBodyRange.Cells(1, 1).Value2 = '9:00'
117117
$ranges.DataBodyRange.Cells(1, 2).Value2 = '12:00'
118118
$ranges.DataBodyRange.Cells(2, 1).Value2 = '22:00'
119119
$ranges.DataBodyRange.Cells(2, 2).Value2 = '02:00'
@@ -146,7 +146,7 @@ try {
146146

147147
Assert-Equal -Label 'OnExceeded.Action が内部値になる' -Expected 'Terminate' -Actual $config.UsageTimeLimit.OnExceeded.Action
148148
Assert-Equal -Label 'AllowedTimeRanges の件数' -Expected 2 -Actual $config.UsageTimeLimit.AllowedTimeRanges.Count
149-
Assert-Equal -Label 'AllowedTimeRanges[0].Start' -Expected '09:00' -Actual $config.UsageTimeLimit.AllowedTimeRanges[0].Start
149+
Assert-Equal -Label 'AllowedTimeRanges[0].Start (9:00 が 09:00 にそろう)' -Expected '09:00' -Actual $config.UsageTimeLimit.AllowedTimeRanges[0].Start
150150
Assert-Equal -Label 'AllowedTimeRanges[1].End (日をまたぐ)' -Expected '02:00' -Actual $config.UsageTimeLimit.AllowedTimeRanges[1].End
151151

152152
Assert-Equal -Label 'Programs の件数' -Expected 1 -Actual $config.StartupLauncher.Programs.Count
@@ -170,7 +170,15 @@ try {
170170

171171
$ranges.DataBodyRange.Cells(1, 1).Value2 = '9時'
172172
Assert-True -Label '時刻の書式が違えば止まる' -Condition ((Invoke-Macro $xl 'ValidationMessage') -match 'HH:mm')
173-
$ranges.DataBodyRange.Cells(1, 1).Value2 = '09:00'
173+
$ranges.DataBodyRange.Cells(1, 1).Value2 = '0900'
174+
Assert-True -Label '区切りのない 0900 も止まる' -Condition ((Invoke-Macro $xl 'ValidationMessage') -match 'HH:mm')
175+
$ranges.DataBodyRange.Cells(1, 1).Value2 = '9:00'
176+
Assert-Equal -Label '9:00 は入力チェックを通る' -Expected '' -Actual (Invoke-Macro $xl 'ValidationMessage')
177+
178+
(Get-ParamCell $wb 'T_NetLogger' 'LocalFile.MaxDays').Value2 = ''
179+
Assert-True -Label '数値の欄が空欄なら止まる' `
180+
-Condition ((Invoke-Macro $xl 'ValidationMessage') -match 'LocalFile.MaxDays が空欄')
181+
(Get-ParamCell $wb 'T_NetLogger' 'LocalFile.MaxDays').Value2 = 90
174182

175183
$programs.DataBodyRange.Cells(2, 2).Value2 = '--only-args'
176184
Assert-True -Label 'パスのない行があれば止まる' -Condition ((Invoke-Macro $xl 'ValidationMessage') -match '実行ファイルのパス')

0 commit comments

Comments
 (0)