1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 dnl GNU General Public License for more details.
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
17 AT_BANNER([format guesser])
19 AT_SETUP([format guesser])
20 AT_DATA([format-guesser.txt], [dnl
43 "1,123" => COMMA5.0 # Is , is grouping or decimal? Assume grouping.
44 "1.123" => F5.3 # Ditto.
45 "1,12" => F4.2 # Not a group of 3, so last delim must be decimal.
46 "1.12" => F4.2 # Ditto.
47 "1,1234" => F6.4 # Not a group of 3, so last delim must be decimal.
48 "1.1234" => F6.4 # Ditto.
49 "$1.234" => DOLLAR6.3 # Dollar sign means decimal has to be '.'.
50 "$1,234" => DOLLAR6.0 # Ditto.
51 "1.234%" => PCT6.3 # Percent sign means decimal has to be '.'.
52 "1,234%" => PCT6.0 # Ditto.
53 "1,123.456" => COMMA9.3 # Both '.' and ',', so last delim must be decimal.
54 "1.123,456" => DOT9.3 # Ditto.
55 "1,123,456.45" => COMMA12.2 # Ditto.
56 "1.123.456,45" => DOT12.2 # Ditto.
57 "1,123,456" => COMMA9.0 # Ditto.
58 "1.123.456" => DOT9.0 # Ditto.
60 # Date and time formats.
61 "01-OCT-1978" => DATE11
62 "01-x-1978" => EDATE9 # Roman numeral for month.
64 "1-13-99" => ADATE7 (ADATE8)
66 "13-1-99" => EDATE7 (EDATE8)
67 "32-1-1" => SDATE6 (SDATE8)
78 "1-1-01 1:2" => A10 # Minute needs at least two digits.
79 "1-1-01 1:02" => DATETIME11.0 (DATETIME17.0)
80 "1-1-01 1:02:3" => A13 # Second needs at least two digits.
81 "1-1-01 1:02:03" => DATETIME20.0
82 "1-1-01 1:02:03.1" => DATETIME20.1 (DATETIME22.1)
83 "1-1-01 +1:02:03.1" => DATETIME20.1 (DATETIME22.1)
84 "1-1-01 -1:02:03.1" => DATETIME20.1 (DATETIME22.1)
87 "1:30" => TIME4.0 (TIME5.0)
93 "-1:30:15.5" => TIME10.1
94 "+1:30:15.75" => TIME11.2
95 "1 1:30" => DTIME6.0 (DTIME8.0)
96 "+1 1:30" => DTIME7.0 (DTIME8.0)
97 "-1 1:30" => DTIME7.0 (DTIME8.0)
101 "1:00:01.03" => TIME10.2 (TIME11.2)
102 "12 1:00:01.3" => DTIME12.1 (DTIME13.1)
106 "i" => A1 # Not detected as MONTH format.
111 "janaury" => MONTH7 # Only first three letters are significant.
121 "september" => MONTH9
128 "wedensday" => WKDAY9
134 # Ambiguous; bias in favor of more sensible DD/MM/YY format:
138 # Several ambiguous dates can be clarified by one unambiguous example:
139 "1/1/1978" "1/2/1978" "1/3/1978" "1/13/1978" => ADATE9 # MM/DD/YY
140 "01/01/01" "02/01/01" "03/01/01" "13/01/01" => EDATE8 # DD/MM/YY
141 "01/01/01" "02/01/01" "03/01/01" "2013/01/01" => SDATE10 # YY/MM/DD
143 AT_CHECK([[(echo "SET DECIMAL=DOT."
147 s,^\(.*\)=> \(.*\)$,DEBUG FORMAT GUESSER \1.,') \
148 < format-guesser.txt > format-guesser.sps]])
149 AT_CHECK([pspp --testing-mode -O format=csv format-guesser.sps],
151 AT_CHECK([[sed -e 's/#.*//
153 /^$/d' < format-guesser.txt > expout]])
154 AT_CHECK([cat stderr], [0], [expout])