1: <?php
2:
3: /*
4: * Copyright (c) 2016 Geraldo B. Landre
5: *
6: * See the file LICENSE for copying permission.
7: */
8:
9: namespace pgn\tags;
10:
11: use utils\Parser;
12:
13: /**
14: * Description of Time:
15: *
16: * This uses a time-of-day value in the form "HH:MM:SS"; similar to the Date tag
17: * except that it denotes the local clock time (hours, minutes, and seconds) of
18: * the start of the game. Note that colons, not periods, are used for field
19: * separators for the Time tag value. The value is taken from the local time
20: * corresponding to the location given in the Site tag pair.
21: *
22: * @see pgn_standard.txt
23: * @author Geraldo
24: */
25: class Time extends Tag {
26:
27: public function getName() {
28: $parsed = Parser::parseClassName(get_class());
29: return $parsed['className'];
30: }
31:
32: /**
33: *
34: * @assert("00:00:00") === true
35: * @assert("00.00.00") === false
36: * @assert("19:33:15") === true
37: * @assert("20:50:09") === true
38: * @assert("23:59:59") === true
39: * @assert("-1:33:15") === false
40: * @assert("00:-1:15") === false
41: * @assert("00:00:-1") === false
42: * @assert("24:00:00") === false
43: * @assert("19:60:00") === false
44: * @assert("19:59:60") === false
45: * @assert(2) === false
46: * @assert("a") === false
47: * @assert(NULL) === false
48: *
49: * @param mixed $data
50: * @return boolean returns if a data is valid
51: */
52: public function validate($data) {
53: if (!parent::validate($data)) {
54: return false;
55: }
56:
57: return preg_match_all("/^" . self::validPattern() . "$/", $data) === 1;
58: }
59:
60: /**
61: * Get the regex pattern of a valid FEN tag string
62: * @return string regex pattern of a valid SetUp tag string
63: */
64: static public function validPattern() {
65: return "([0-1][0-9]|2[0-3])(:[0-5][0-9]){2}";
66: }
67:
68: }
69: