3

I have ls installed on my Windows XP computer. It came with msysgit. I've had it a while and it turns out I use it quite a lot even in the DOS prompt. More than dir.

The thing is that it gives me time stamps with one hour offset. See the date for gcc.exe, ls says 15:01, dir says 16:01:

C:\MinGW\bin>ls --full-time gcc.exe
-rwxr-xr-x    1 gaf      Administ    90112 Thu Apr 24 15:01:53 2008 gcc.exe

C:\MinGW\bin>dir gcc.exe
 Volymen i enhet C har ingen etikett.
 Volymens serienummer är 644A-83A3

 Innehåll i katalogen C:\MinGW\bin

2008-04-24  16:01            90 112 gcc.exe
               1 fil(er)              90 112 byte
           0 katalog(er)  104 458 203 136 byte ledigt

(sorry for the strange language)

I can tell that it is ls that is doing it wrong, I checked that with newly created files.

It's quite disturbing, any suggestion on how I can solve that?


EDIT: more info added after njd's answer.

Changing the env variable TZ does have effect. I live in Sweden, where time is CET in winter, CEST in summer. I tested both UTC, CET, and CEST, and reached strange (for me) results:

C:\Program\Git\bin>set TZ=UTC

C:\Program\Git\bin>.\date
Mon Feb 15 12:53:26 GMT 2010

C:\Program\Git\bin>set TZ=CET

C:\Program\Git\bin>.\date
Mon Feb 15 12:53:50 GMT 2010

C:\Program\Git\bin>set TZ=CEST

C:\Program\Git\bin>.\date
Mon Feb 15 12:53:59 GMT 2010

C:\Program\Git\bin>set TZ=CET+1

C:\Program\Git\bin>.\date
Mon Feb 15 11:54:27 CET 2010

C:\Program\Git\bin>set TZ=CET-1

C:\Program\Git\bin>.\date
Mon Feb 15 13:54:35 CET 2010

Setting TZ to CET or CEST has no effect. The date displayed is still GMT. It seems that the string CET alone has no effect. Is it only a string for displaying, and is only taken into account if there is a explicit offset.

C:\Program\Git\bin>set TZ=FOO-1

C:\Program\Git\bin>.\date
Mon Feb 15 14:00:29 FOO 2010

C:\Program\Git\bin>set TZ=BAR-1

C:\Program\Git\bin>.\date
Mon Feb 15 14:00:42 BAR 2010

So it seems.

-1 has the correct effect. But Sweden's time is UTC+1: CET on wikipedia

Is there a mismatch in the convention, -1 in TZ is UTC+1?

If I want to let the OS decide if it's summer or winter as indicated in njd's reply, I can omit the start and end time. I suppose the correct string is TZ=CET-1CEST-2, is that correct?

I am not sure what windows does in summertime. If it updates the clock itself, the string above will not work. If it updates the offset only, then this might work. More insights?

2
  • The link in my answer (to the GNU libc TZ-Variable page) states: ...The offset specifies the time value one must add to the local time to get a Coordinated Universal Time value. ... This is positive if the local time zone is west of the Prime Meridian and negative if it is east.
    – njd
    Commented Feb 16, 2010 at 9:50
  • Agreed. The page says also that if nothing is specified for the summer time, 1 hour ahead of standard is assumed. CET-1CEST must be enough (if the OS deals with the switching dates).
    – Gauthier
    Commented Feb 16, 2010 at 12:47

1 Answer 1

4

It looks like the ls command doesn't know enough about European time-zomes and the dates when CEST is in effect.

I'm guessing the 16:01 reported by DIR was 16:01 CEST, but the ls command hasn't applied the extra hour for daylight saving.

I'm not sure how msysgit (or just msys) stores timezone information: in Solaris, there are zoneinfo files for this.

If there's some way of communicating to your msysgit tools when the daylight saving begins and ends, then your ls command could get it right.

Maybe this page offers a clue.
Try playing around with environment settings like

SET TZ=CET+1CEST,M3.5.0/2,M10.5.0/2

which states that CEST begins on the last Sunday (day 0) of March at 2am, and ends on the last Sunday of October at 2am. That should give you something to work with.

(Normally, it would be enough to state the timezone and DST timezone only: "CET+1CEST" and rely on the OS to know what the relevant dates should be. But here we are setting the dates explicitly.)

I can see the something similar happening in reverse with MSys on my system:
A file reported by the DIR command (and Windows Explorer) as written on 2008-04-18 at 12:19 (which should have been BST: GMT+1) is shown by MSys ls as 13:19:06.

If I play around with the timezone dates and SET TZ as though DST did not begin until the end of April, I can change this to match DIR's output.

But as far as I know, the EU-wide rule on Summer-time is that it begins on the last Sunday of March (M3.5.0/2) and ends on the last Sunday of October (M10.5.0/2).

So when I type (in an MSys shell, or in Cygwin, or in Unix):

TZ=GMT0BST,M3.5.0/2,M10.5.0/2 ls --full-time foo

I should see the correct time, with DST applied. In fact I see 13:19, just the same as when I don't set the timezone at all.

Which makes me wonder if MSys and msysgit are getting it right, and Windows is getting it wrong.

5
  • Thanks for the update. I am currently playing with the TZ environment variable, but I am not sure whether git\bin\date.exe uses it. "export" does not work in my DOS prompt. I think CEST should take care of changing to summertime automatically?
    – Gauthier
    Commented Feb 15, 2010 at 11:46
  • Sorry, I was thinking of POSIX/Bash syntax. I've corrected my answer, and added a note about the start/end dates.
    – njd
    Commented Feb 15, 2010 at 12:10
  • I think this is sorted out now. I'll see in Mars if the change is working. I wonder about the OS knowing the relevant days of change, I have not read it anywhere else? Thanks a lot!
    – Gauthier
    Commented Feb 16, 2010 at 6:44
  • For the record: the change to summer time went smooth!
    – Gauthier
    Commented Mar 29, 2010 at 12:49
  • I had problem when using Cygwin and starting DOS window from there, and then started Ruby on Rails application. Cygwin is setting TZ in a bad way for RoR so the solution for me was to just unset TZ before starting RoR.
    – 244an
    Commented May 23, 2019 at 9:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .