3

I am writing a simple bash script for computing time and date by adding seconds onto a random date that I give. It worked fine so far but going from 2016-03-13 00:00:00 to 2016-03-13 03:00:00 skips 2016-03-13 02:00:00.

Verions of bash that I've tried are 4.4.23(1)-release and 5.3.8(1)-release, and they both gave me the same results.

The command below

date -d "2016-03-13 00:00:00 7199 seconds" +%Y-%m-%d-%H-%M-%S

gives

2016-03-13-01-59-59

which is correct. But with

date -d "2016-03-13 00:00:00 7200 seconds" +%Y-%m-%d-%H-%M-%S

I get

2016-03-13-03-00-00

which is supposed to be

2016-03-13-02-00-00

Am I missing something here?

7
  • 9
    Congratulations. You have discovered daylight saving time. Commented Dec 11 at 1:49
  • Oh no.... how do I disable daylight saving time? Commented Dec 11 at 1:56
  • 4
    You don't disable it. The computer is right and you're wrong. On that date 3am was two hours after midnight. Commented Dec 11 at 2:23
  • 3
    @Redshoe Yes, since UTC doesn't use DST TZ=UTC date -d "2016-03-13 00:00:00 7200 seconds" +%Y-%m-%d-%H-%M-%S should work Commented Dec 11 at 2:32
  • 1
    Voted to reopen (I noticed this was closed for not being reproducible - and it is about timezones - it is 100% reproducible given a DST timezone where the skip happens) Commented Dec 12 at 20:46

1 Answer 1

4

Since the UTC timezone doesn't use daylight savings time (which is what messes this up), this will work:

TZ=UTC date -d "2016-03-13 00:00:00 7200 seconds" +%Y-%m-%d-%H-%M-%S
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.