Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72046

Re: os.stat and time zones

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.021
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'true,': 0.05; 'attributes': 0.09; 'cc:addr:python-list': 0.11; 'question.': 0.14; 'windows': 0.15; '"to': 0.16; 'dependent.': 0.16; 'epoch': 0.16; 'field).': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'silly': 0.16; 'simpson': 0.16; 'time"': 0.16; 'unix,': 0.16; 'utc': 0.16; 'utc.': 0.16; 'wrote:': 0.18; 'module': 0.19; 'dependent': 0.19; 'starts': 0.20; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'cheers,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'resolution': 0.29; 'returned': 0.30; 'see,': 0.30; 'gives': 0.31; 'code': 0.31; 'file': 0.32; 'probably': 0.32; 'says': 0.33; 'beginning': 0.33; 'subject:time': 0.33; 'common': 0.35; 'something': 0.35; 'etc': 0.35; 'but': 0.35; 'skip:> 10': 0.36; 'useful': 0.36; 'example,': 0.37; 'january': 0.37; 'seconds': 0.37; 'operating': 0.37; 'two': 0.37; 'skip:o 20': 0.38; 'itself': 0.39; 'system.': 0.39; 'called': 0.40; 'lower': 0.61; 'range': 0.61; 'content-disposition:inline': 0.62; 'field': 0.63; 'more': 0.64; 'different': 0.65; 'here': 0.66; 'between': 0.67; 'close': 0.67; 'presented': 0.69; 'friendly': 0.72; 'friends': 0.81; 'fat': 0.84; 'greenwich': 0.84; 'nagy': 0.84; 'received:192.168.15': 0.84; 'resolution,': 0.84; 'differences': 0.93
Date Mon, 26 May 2014 12:47:04 +1000
From Cameron Simpson <cs@zip.com.au>
To Nagy László Zsolt <gandalf@shopzeus.com>
Subject Re: os.stat and time zones
MIME-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Disposition inline
Content-Transfer-Encoding 8bit
In-Reply-To <5381D85E.8010502@shopzeus.com>
User-Agent Mutt/1.5.21 (2010-09-15)
References <5381D85E.8010502@shopzeus.com>
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10328.1401072433.18130.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1401072433 news.xs4all.nl 2863 [2001:888:2000:d::a6]:51100
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72046

Show key headers only | View raw


On 25May2014 13:47, Nagy László Zsolt <gandalf@shopzeus.com> wrote:
>This might be a silly question. Documentation of os.stat:
>
>>The exact meaning and resolution of the st_atime, st_mtime, and 
>>st_ctime attributes depend on the operating system and the file 
>>system. For example, on Windows systems using the FAT or FAT32 file 
>>systems, st_mtime has 2-second resolution, and st_atime has only 
>>1-day resolution. See your operating system documentation for 
>>details.
>So it says that the meaning is platform dependent.
>
>But here is something interesting. Supposedly, os.stat(fpath).st_mtime 
>and os.path.getmtime(path) return the same thing. The documentation of 
>os.path.getmtime says that it "returns the number of seconds since the 
>epoch". And the time module says that "To find out what the epoch is, 
>look at gmtime(0)". And the documentation of gmtime says that it 
>converts the given value to a struct_time *that is in UTC*.
>
>If the above are true, then as far as I can see, the meaning of 
>st_mtime is NOT platform dependent. It always means the number of 
>seconds elapsed since the epoch in UTC.

You have conflated two things here.

The "offset since the epoch" is a number of seconds since a (platform 
dependent) epoch: the "start of time" for the OS time counters on that system.

It has _nothing_ to do with UTC.

As far as st_atime and friends go, the epoch itself is platform dependent and 
so is the resolution (FAT filesystems having lower precision than might seem 
sane, probably to get a longer time range from a small field).

The field names come from POSIX, which comes from UNIX. The .st_atime etc field 
names are still presented on Windows to make code more portable. But Windows 
has a different epoch (UNIX time starts at the beginning of 1 January 1970; 
that is its "epoch").

The gmtime() function takes the platform dependent offset-from-epoch and gives 
you a struct_time, which has human friendly date and hours/minutes/etc fields.  
These necessarily must be in a timezone, and UTC is a common frame of reference 
and the zone returned by gmtime() ("gmt" means GMT, Greenwich Mean Time, which 
is close to a synonym for UTC).

Between Windows and UNIX, the differences are the resolution and the epoch.

UTC is not platform dependent and not called so by the doco. That also makes it 
a useful zone to pass around in some contexts.

Cheers,
Cameron Simpson <cs@zip.com.au>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: os.stat and time zones Cameron Simpson <cs@zip.com.au> - 2014-05-26 12:47 +1000

csiph-web