bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

find option -newermt parses time in GMT-7 timezone


From: Denis Laplante
Subject: find option -newermt parses time in GMT-7 timezone
Date: Wed, 19 Dec 2012 16:20:52 -0800

The shell script below demonstrates that gnu "find" parses times for option 
-newermt in timezone GMT-7 (Indochina). 
I discovered this when looking for log files modified around reboot time, and 
getting nonsensical results.

The same result was found on Linux (Ubuntu) and MacOsX 10.8 (via MacPorts).
Sorry, I don't anticipate having time to get into the source code.

--      Denis Laplante

$ gfind --version
find (GNU findutils) 4.4.2

#!/bin/bash
# find-date-bug : any TZ offset other than "-7" shows that 
#  gnu find option -newermt is hard-wired for GMT-7 (Indochina)
#  Logic: with TZ set to avoid ambiguity, use touch to create test-file with 
known timestamp
#  then use option "-newermt" to see when "find" reports that file is newer 
than specified times.
#  If TZ is processed correctly, any TZ should report the same in local time.

USAGE="USE: $0 {GMT_HOURS_OFFSET} (ex: find-date-bug -7 shows sensible result)"
case $1 in '') echo "$USAGE"; exit 1 ;; esac

TZ="Etc/GMT${1}"; export TZ  # See other timezone names in /usr/share/zoneinfo/
date

DATE_TOUCH=2012'11'15"00"30 # yyyyMMddHHmm, quotes for readability
FIND_MOD_TIME_OPT=-newer'm't    # 'm': modify-time; 't': get time from string
FIND=gfind # On MacOsX, from www.gnu.org/software/findutils via MacPorts 
@4.4.2_1

TEST_FILE="test-file"

touch -t "${DATE_TOUCH}" "${TEST_FILE}"
/bin/echo -n "TZ=${TZ}(default) "; ls -l "${TEST_FILE}"

TIMES="
        2012-11-15t00:29
        2012-11-15t00:31
        2012-11-15t01:29
        2012-11-15t01:31
        2012-11-15t06:31
        2012-11-15t12:31
        2012-11-15t18:31
        2012-11-16t00:31
"

for T in ${TIMES}; do # 
    echo   "After  ${T} ? `${FIND} \"${TEST_FILE}\" ${FIND_MOD_TIME_OPT} ${T} 
-print `"
done

exit

# SAMPLE RESULTS
# $ sh ./find-date-bug.sh -7
# Thu Dec 20 06:45:55 GMT-7 2012
# TZ=Etc/GMT-7(default) -rw-r--r--  1 owner  group  0 Nov 15 00:30 test-file
# After  2012-11-15t00:29 ? test-file
# After  2012-11-15t00:31 ? 
# After  2012-11-15t01:29 ? 
# After  2012-11-15t01:31 ? 
# After  2012-11-15t06:31 ? 
# After  2012-11-15t12:31 ? 
# After  2012-11-15t18:31 ? 
# After  2012-11-16t00:31 ? 

# $ sh ./find-date-bug.sh -5
# Thu Dec 20 04:46:00 GMT-5 2012
# TZ=Etc/GMT-5(default) -rw-r--r--  1 owner  group  0 Nov 15 00:30 test-file
# After  2012-11-15t00:29 ? test-file
# After  2012-11-15t00:31 ? test-file
# After  2012-11-15t01:29 ? test-file
# After  2012-11-15t01:31 ? test-file
# After  2012-11-15t06:31 ? 
# After  2012-11-15t12:31 ? 
# After  2012-11-15t18:31 ? 
# After  2012-11-16t00:31 ? 

# $ sh ./find-date-bug.sh +8
# Wed Dec 19 15:46:17 GMT+8 2012
# TZ=Etc/GMT+8(default) -rw-r--r--  1 owner  group  0 Nov 15 00:30 test-file
# After  2012-11-15t00:29 ? test-file
# After  2012-11-15t00:31 ? test-file
# After  2012-11-15t01:29 ? test-file
# After  2012-11-15t01:31 ? test-file
# After  2012-11-15t06:31 ? test-file
# After  2012-11-15t12:31 ? test-file
# After  2012-11-15t18:31 ? 
# After  2012-11-16t00:31 ? 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]