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 TimeControl extends Tag {
26:
27: public function getName() {
28: $parsed = Parser::parseClassName(get_class());
29: return $parsed['className'];
30: }
31:
32: /**
33: *
34: * @assert("?") === true
35: * @assert("-") === true
36: * @assert("32/45") === true
37: * @assert("40/9000") === true
38: * @assert("300") === true
39: * @assert("35+5") === true
40: * @assert("*35") === true
41: * @assert("-:40/9000:30/3000:15/30000:300") === true
42: * @assert("-:40/9000:30/3000:15/30000:*35") === true
43: * @assert("-:40/9000:*35:40/9000:300") === true
44: * @assert("32/45:300") === true
45: * @assert("?:-:40/9000:300:300:*35") === false
46: * @assert("123,45") === false
47: * @assert("22/35.-") === false
48: * @assert("??.??") === false
49: * @assert("?.-") === false
50: * @assert("asdf") === false
51: * @assert(2) === true
52: * @assert("a") === false
53: * @assert(NULL) === false
54: *
55: * @todo("300:300:*35:40/9000:-") === false
56: * @todo("00/300:?") === false
57: * @todo("00/300:-") === false
58: * @todo("-:40/9000:*35:40/9000:300") === false
59: * @todo("300:300:*35") === false
60: *
61: * @param mixed $data
62: * @return boolean returns if a data is valid
63: */
64: public function validate($data) {
65: if (!parent::validate($data)) {
66: return false;
67: }
68:
69: return preg_match_all("/^" . self::validPattern() . "$/", $data) === 1;
70: }
71:
72: /**
73: * Get the regex pattern of a valid FEN tag string
74: * @return string regex pattern of a valid SetUp tag string
75: */
76: static public function validPattern() {
77: return "(\?|-|\d+\/\d+|\*\d+|\d+\+\d+|\d+)(:(\?|-|\d+\/\d+|\d+\+\d+|\d+|\*\d+)){0,4}";
78: }
79:
80: }
81: