FAQ
Is there someway to write the following line even better with the
ability to detect daylight saving time by itself so i don't have to
alter the line manually when time changes?


lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
'%y-%m-%d %H:%M:%S' ) # MySQL datetime format


Thanks.

Search Discussions

  • Mark Lawrence at Nov 8, 2013 at 9:29 pm

    On 08/11/2013 21:11, ????? ??????????? wrote:
    Is there someway to write the following line even better with the
    ability to detect daylight saving time by itself so i don't have to
    alter the line manually when time changes?

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    Thanks.

    http://stackoverflow.com/questions/19774709/use-python-to-find-out-if-a-timezone-currently-in-daylight-savings-time


    --
    Python is the second best programming language in the world.
    But the best has yet to be invented. Christian Tismer


    Mark Lawrence
  • Νίκος Αλεξόπουλος at Nov 8, 2013 at 10:01 pm

    ???? 8/11/2013 11:29 ??, ?/? Mark Lawrence ??????:
    On 08/11/2013 21:11, ????? ??????????? wrote:
    Is there someway to write the following line even better with the
    ability to detect daylight saving time by itself so i don't have to
    alter the line manually when time changes?

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    Thanks.
    http://stackoverflow.com/questions/19774709/use-python-to-find-out-if-a-timezone-currently-in-daylight-savings-time



    I saw the link and i'm wondering if it can be written in 1-liner.
    Don't get me wrong but i had the lastvisit calculated on 1 statement and
    i want to retain it this way.


    Is it possible?
  • Joel Goldstick at Nov 8, 2013 at 10:06 pm
    rurpy? can you help?

    On Fri, Nov 8, 2013 at 5:01 PM, ????? ??????????? wrote:
    ???? 8/11/2013 11:29 ??, ?/? Mark Lawrence ??????:
    On 08/11/2013 21:11, ????? ??????????? wrote:

    Is there someway to write the following line even better with the
    ability to detect daylight saving time by itself so i don't have to
    alter the line manually when time changes?

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    Thanks.


    http://stackoverflow.com/questions/19774709/use-python-to-find-out-if-a-timezone-currently-in-daylight-savings-time

    I saw the link and i'm wondering if it can be written in 1-liner.
    Don't get me wrong but i had the lastvisit calculated on 1 statement and i
    want to retain it this way.

    Is it possible?
    --
    https://mail.python.org/mailman/listinfo/python-list





    --
    Joel Goldstick
    http://joelgoldstick.com
  • Mark Lawrence at Nov 8, 2013 at 10:18 pm

    On 08/11/2013 22:01, ????? ??????????? wrote:
    ???? 8/11/2013 11:29 ??, ?/? Mark Lawrence ??????:
    On 08/11/2013 21:11, ????? ??????????? wrote:
    Is there someway to write the following line even better with the
    ability to detect daylight saving time by itself so i don't have to
    alter the line manually when time changes?

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    Thanks.
    http://stackoverflow.com/questions/19774709/use-python-to-find-out-if-a-timezone-currently-in-daylight-savings-time
    I saw the link and i'm wondering if it can be written in 1-liner.
    Don't get me wrong but i had the lastvisit calculated on 1 statement and
    i want to retain it this way.

    Is it possible?

    Yes, but I'll leave you to work out how to do it, on the grounds that I
    have a very, very strong suspicion about the way this thread is going to go.


    --
    Python is the second best programming language in the world.
    But the best has yet to be invented. Christian Tismer


    Mark Lawrence
  • Grant Edwards at Nov 8, 2013 at 10:29 pm

    On 2013-11-08, ?????????? ?????????????????????? wrote:


    Is there someway to [...]
    http://stackoverflow.com/[...]
    I saw the link and i'm wondering if it can be written in 1-liner.
    Don't get me wrong but i had the lastvisit calculated on 1 statement
    and i want to retain it this way.

    It's that global newline shortage again. Just because a few people
    get killed in a newline mine they all go on strike...


    --
    Grant Edwards grant.b.edwards Yow! Mary Tyler Moore's
                                       at SEVENTH HUSBAND is wearing
                                   gmail.com my DACRON TANK TOP in a
                                                        cheap hotel in HONOLULU!
  • Chris Angelico at Nov 8, 2013 at 10:39 pm

    On Sat, Nov 9, 2013 at 9:29 AM, Grant Edwards wrote:
    It's that global newline shortage again. Just because a few people
    get killed in a newline mine they all go on strike...

    It's a conspiracy! The government kills a few miners (with their
    contrail mind-control stuffo) to push the price of newlines up, then
    taxes us to the hilt and claims it's to fund development of artificial
    newlines in labs! I tell you, man, those artificial newlines may LOOK
    the same, but mark my words, one day they're all gonna rise up and
    murder us in their sleep...


    ChrisA
    been up all night and is starting to get stupid
  • Gene Heskett at Nov 9, 2013 at 3:39 pm

    On Saturday 09 November 2013 10:33:57 Chris Angelico did opine:

    On Sat, Nov 9, 2013 at 9:29 AM, Grant Edwards wrote:
    It's that global newline shortage again. Just because a few people
    get killed in a newline mine they all go on strike...
    It's a conspiracy! The government kills a few miners (with their
    contrail mind-control stuffo) to push the price of newlines up, then
    taxes us to the hilt and claims it's to fund development of artificial
    newlines in labs! I tell you, man, those artificial newlines may LOOK
    the same, but mark my words, one day they're all gonna rise up and
    murder us in their sleep...

    ChrisA
    been up all night and is starting to get stupid

    Ya know, folks like Nick would have me signing off. Fortunately there are
    kill files. But the backscatter he creates I am still forced to read, or
    more usually skip.


    This list recently has been far more about venting because GG is broken, or
    Nicks un-teachability than about real code, by a large margin.


    Then one of you frustrated standup comics comes along, and gives me a VBG,
    and its suddenly all worth it. Thank You Chris.


    Cheers, Gene
    --
    "There are four boxes to be used in defense of liberty:
      soap, ballot, jury, and ammo. Please use in that order."
    -Ed Howdershelt (Author)


    Hark, the Herald Tribune sings,
    Advertising wondrous things.


    Angels we have heard on High
    Tell us to go out and Buy.
       -- Tom Lehrer
    A pen in the hand of this president is far more
    dangerous than 200 million guns in the hands of
              law-abiding citizens.
  • Chris Angelico at Nov 9, 2013 at 10:25 pm

    On Sun, Nov 10, 2013 at 2:39 AM, Gene Heskett wrote:
    Ya know, folks like Nick would have me signing off. Fortunately there are
    kill files. But the backscatter he creates I am still forced to read, or
    more usually skip.

    Then one of you frustrated standup comics comes along, and gives me a VBG,
    and its suddenly all worth it. Thank You Chris.

    :) Don't just thank me, Grant and Roy were key to it too - and the
    whole "there's no shortage of newlines" thing started with Steven
    D'Aprano (I think), and it's a ripe field for harvest :)


    But hey. If you're going to have to read backscatter, may as well make
    it funny...


    ChrisA
  • Gene Heskett at Nov 10, 2013 at 12:55 am

    On Saturday 09 November 2013 19:52:52 Chris Angelico did opine:

    On Sun, Nov 10, 2013 at 2:39 AM, Gene Heskett wrote:
    Ya know, folks like Nick would have me signing off. Fortunately there
    are kill files. But the backscatter he creates I am still forced to
    read, or more usually skip.

    Then one of you frustrated standup comics comes along, and gives me a
    VBG, and its suddenly all worth it. Thank You Chris.
    :
    :) Don't just thank me, Grant and Roy were key to it too - and the

    whole "there's no shortage of newlines" thing started with Steven
    D'Aprano (I think), and it's a ripe field for harvest :)

    And likely not fully gleaned yet. :) To all of you, thats some of the
    better creative writing I've read in my 79 years. ;-)

    But hey. If you're going to have to read backscatter, may as well make
    it funny...

    Precisely.

    ChrisA



    Cheers, Gene
    --
    "There are four boxes to be used in defense of liberty:
      soap, ballot, jury, and ammo. Please use in that order."
    -Ed Howdershelt (Author)


    A Difficulty for Every Solution.
       -- Motto of the Federal Civil Service
    A pen in the hand of this president is far more
    dangerous than 200 million guns in the hands of
              law-abiding citizens.
  • Chris Angelico at Nov 10, 2013 at 8:47 am

    On Sun, Nov 10, 2013 at 11:55 AM, Gene Heskett wrote:
    On Saturday 09 November 2013 19:52:52 Chris Angelico did opine:
    :) Don't just thank me, Grant and Roy were key to it too - and the
    whole "there's no shortage of newlines" thing started with Steven
    D'Aprano (I think), and it's a ripe field for harvest :)
    And likely not fully gleaned yet. :) To all of you, thats some of the
    better creative writing I've read in my 79 years. ;-)

    Are you going to have a newyear after next year and start over with
    Year 1 again?


    ChrisA
  • Gene Heskett at Nov 10, 2013 at 9:13 am

    On Sunday 10 November 2013 04:06:06 Chris Angelico did opine:

    On Sun, Nov 10, 2013 at 11:55 AM, Gene Heskett wrote:
    On Saturday 09 November 2013 19:52:52 Chris Angelico did opine:
    :) Don't just thank me, Grant and Roy were key to it too - and the

    whole "there's no shortage of newlines" thing started with Steven
    D'Aprano (I think), and it's a ripe field for harvest :)
    And likely not fully gleaned yet. :) To all of you, thats some of the
    better creative writing I've read in my 79 years. ;-)
    Are you going to have a newyear after next year and start over with
    Year 1 again?
    Nah. I tried to put it off as long as I could, but times arrow, dammit,
    only points forward. I might as well get used to it. From that famous
    line about death and taxes, taxes will of course outlive me. Being a DM-II,
    I of course haven't a shred of warranty left. Just up to pee and check on
    that falling satellite, I could fall over walking the 20 feet back to bed,
    but I'm going to do it anyway... ;-)

    ChrisA



    Cheers, Gene
    --
    "There are four boxes to be used in defense of liberty:
      soap, ballot, jury, and ammo. Please use in that order."
    -Ed Howdershelt (Author)


    $100 invested at 7% interest for 100 years will become $100,000, at
    which time it will be worth absolutely nothing.
       -- Lazarus Long, "Time Enough for Love"
    A pen in the hand of this president is far more
    dangerous than 200 million guns in the hands of
              law-abiding citizens.
  • Roy Smith at Nov 9, 2013 at 3:30 pm
    In article <mailman.2300.1384009442.18130.python-list@python.org>,
      Chris Angelico wrote:

    On Sat, Nov 9, 2013 at 9:29 AM, Grant Edwards wrote:
    It's that global newline shortage again. Just because a few people
    get killed in a newline mine they all go on strike...
    It's a conspiracy! The government kills a few miners (with their
    contrail mind-control stuffo) to push the price of newlines up, then
    taxes us to the hilt and claims it's to fund development of artificial
    newlines in labs! I tell you, man, those artificial newlines may LOOK
    the same, but mark my words, one day they're all gonna rise up and
    murder us in their sleep...

    I only use organic, free-range, fair-traded newlines in my code. Have
    you ever seen what happens on those big commercial whitespace farms?
    The newlines are kept in justified lines, smashed up against the right
    margin so close they can't even move, and forced to eat recycled EBCDIC
    punctuation!
  • Denis McMahon at Nov 8, 2013 at 10:49 pm

    On Sat, 09 Nov 2013 00:01:37 +0200, ????? ??????????? wrote:


    I saw the link and i'm wondering if it can be written in 1-liner.

    Yes, but you have to rewrite all your code in perl to do this.


    --
    Denis McMahon, denismfmcmahon at gmail.com
  • Νίκος Αλεξόπουλος at Nov 8, 2013 at 11:02 pm

    ???? 9/11/2013 12:49 ??, ?/? Denis McMahon ??????:
    On Sat, 09 Nov 2013 00:01:37 +0200, ????? ??????????? wrote:

    I saw the link and i'm wondering if it can be written in 1-liner.
    Yes, but you have to rewrite all your code in perl to do this.



    Please tell me and as a git i will provide you with 2 good pdfs i just
    found:


    You can see them at my website if you click the blue download button.


    The 1st is a Linux Bile and the 2nd is WebHosting for Dummies.
  • Robert Kern at Nov 8, 2013 at 11:23 pm

    On 2013-11-08 23:02, ????? ??????????? wrote:
    ???? 9/11/2013 12:49 ??, ?/? Denis McMahon ??????:
    On Sat, 09 Nov 2013 00:01:37 +0200, ????? ??????????? wrote:

    I saw the link and i'm wondering if it can be written in 1-liner.
    Yes, but you have to rewrite all your code in perl to do this.

    Please tell me and as a git i will provide you with 2 good pdfs i just found:

    You can see them at my website if you click the blue download button.

    The 1st is a Linux Bile and the 2nd is WebHosting for Dummies.

    Please do not advertise your piracy site here. It is not welcome in this forum.


    --
    Robert Kern


    "I have come to believe that the whole world is an enigma, a harmless enigma
       that is made terrible by our own mad attempt to interpret it as though it had
       an underlying truth."
        -- Umberto Eco
  • Chris Angelico at Nov 8, 2013 at 11:30 pm

    On Sat, Nov 9, 2013 at 10:02 AM, ????? ??????????? wrote:
    ???? 9/11/2013 12:49 ??, ?/? Denis McMahon ??????:
    On Sat, 09 Nov 2013 00:01:37 +0200, ????? ??????????? wrote:

    I saw the link and i'm wondering if it can be written in 1-liner.

    Yes, but you have to rewrite all your code in perl to do this.

    Please tell me and as a git i will provide you with 2 good pdfs i just
    found:

    You can see them at my website if you click the blue download button.

    The 1st is a Linux Bile and the 2nd is WebHosting for Dummies.

    Interesting. Your idea of a "gift" (quite different from a "git",
    which is grammatically valid in your usage, though not what you
    intended) is to offer something you stole AND which you're already
    giving away to anyone who comes to your web site. This is your
    incentive to us to write your code for you.


    Actually, I think offering people free stolen bile for dummies is a
    great business model. Nobody else is trying that!


    If you want to offer something tempting, it's most likely going to be
    money, and quite a bit of it, as stated in another thread. Plus,
    you'll actually have to respect someone's design choices. Good luck on
    that.


    ChrisA
  • Mark Lawrence at Nov 9, 2013 at 12:12 am

    On 08/11/2013 23:02, ????? ??????????? wrote:
    ???? 9/11/2013 12:49 ??, ?/? Denis McMahon ??????:
    On Sat, 09 Nov 2013 00:01:37 +0200, ????? ??????????? wrote:

    I saw the link and i'm wondering if it can be written in 1-liner.
    Yes, but you have to rewrite all your code in perl to do this.

    Please tell me and as a git i will provide you with 2 good pdfs i just
    found:

    You can see them at my website if you click the blue download button.

    The 1st is a Linux Bile and the 2nd is WebHosting for Dummies.

    http://www.cockneyrhymingslang.co.uk/slang/tea_leaf


    --
    Python is the second best programming language in the world.
    But the best has yet to be invented. Christian Tismer


    Mark Lawrence
  • Mark Lawrence at Nov 9, 2013 at 12:45 pm

    On 08/11/2013 23:02, ????? ??????????? wrote:
    ???? 9/11/2013 12:49 ??, ?/? Denis McMahon ??????:
    On Sat, 09 Nov 2013 00:01:37 +0200, ????? ??????????? wrote:

    I saw the link and i'm wondering if it can be written in 1-liner.
    Yes, but you have to rewrite all your code in perl to do this.

    Please tell me and as a git i will provide you with 2 good pdfs i just
    found:

    You can see them at my website if you click the blue download button.

    The 1st is a Linux Bile and the 2nd is WebHosting for Dummies.

    Why is Web Security for Dummies missing?


    --
    Python is the second best programming language in the world.
    But the best has yet to be invented. Christian Tismer


    Mark Lawrence
  • Chris Angelico at Nov 9, 2013 at 12:52 pm

    On Sat, Nov 9, 2013 at 11:45 PM, Mark Lawrence wrote:
    Why is Web Security for Dummies missing?

    Because a Dummy can host a web (all you have to do is invite a spider
    into your house and let it do the work), but he won't be able to make
    it secure.


    Or, more succinctly: Because it isn't.


    ChrisA
  • Νίκος Αλεξόπουλος at Nov 9, 2013 at 1:43 pm

    ???? 9/11/2013 2:45 ??, ?/? Mark Lawrence ??????:
    On 08/11/2013 23:02, ????? ??????????? wrote:
    ???? 9/11/2013 12:49 ??, ?/? Denis McMahon ??????:
    On Sat, 09 Nov 2013 00:01:37 +0200, ????? ??????????? wrote:

    I saw the link and i'm wondering if it can be written in 1-liner.
    Yes, but you have to rewrite all your code in perl to do this.

    Please tell me and as a git i will provide you with 2 good pdfs i just
    found:

    You can see them at my website if you click the blue download button.

    The 1st is a Linux Bile and the 2nd is WebHosting for Dummies.
    Why is Web Security for Dummies missing?



    It's not missing.
    Its there, check again.
    Just click on the Blue download button and select it from the list of
    buttons.
  • Unknown at Nov 10, 2013 at 12:52 pm

    On Sat, 09 Nov 2013 15:43:53 +0200, ????? ??????????? wrote:


    ???? 9/11/2013 2:45 ??, ?/? Mark Lawrence ??????:
    On 08/11/2013 23:02, ????? ??????????? wrote:
    ???? 9/11/2013 12:49 ??, ?/? Denis McMahon ??????:
    On Sat, 09 Nov 2013 00:01:37 +0200, ????? ??????????? wrote:

    I saw the link and i'm wondering if it can be written in 1-liner.
    Yes, but you have to rewrite all your code in perl to do this.
    Please tell me and as a git i will provide you with 2 good pdfs i just
    found:

    You can see them at my website if you click the blue download button.

    The 1st is a Linux Bile and the 2nd is WebHosting for Dummies.
    Why is Web Security for Dummies missing?
    It's not missing.
    Its there, check again.
    Just click on the Blue download button and select it from the list of
    buttons.

    Try Reading IT!
  • Rurpy at Nov 11, 2013 at 10:49 pm

    On Friday, November 8, 2013 3:06:33 PM UTC-7, Joel Goldstick wrote:
    rurpy? can you help?

    No, sorry. For your future reference, if there is a
    question I can help with (have the technical knowledge,
    haven't seen a good answer yet, have time, etc) I will
    post my attempt at an answer.


    So lack of such a response is a pretty good clue that
    I can't help at the current time, and there is no need
    to ping me explicitly.


    I do appreciate your "genuine" concern for Nikos and
    that he gets a good answer though.
  • Joel Goldstick at Nov 11, 2013 at 11:18 pm

    On Mon, Nov 11, 2013 at 5:49 PM, wrote:
    On Friday, November 8, 2013 3:06:33 PM UTC-7, Joel Goldstick wrote:
    rurpy? can you help?
    No, sorry. For your future reference, if there is a
    question I can help with (have the technical knowledge,
    haven't seen a good answer yet, have time, etc) I will
    post my attempt at an answer.

    So lack of such a response is a pretty good clue that
    I can't help at the current time, and there is no need
    to ping me explicitly.

    I guess the word ping can make sense as to bring attention to a
    particular person. I believed I responded on the mailing list.
    I do appreciate your "genuine" concern for Nikos and
    that he gets a good answer though.

    So, since you don't like to be emailed directly, (I'm guessing), I
    will respond here.


    Its nice that an occasional participant sticks up and sees the bright
    of side of that particular OP. My answer was an attempt at humor,
    specifically for you Rurpy, since after your splendid defense of the
    OP, he returned to the pattern of asking a question, getting a good
    answer, then replying with a reply like "no, I want a one liner".
    Then, starting a new thread and asking the same question again.


    I don't think the idea of a mailing list or news group is to spoon
    feed anyone code. That is what you pay someone to do. If you want
    advice and guidance, its polite to try to learn from it, and move the
    conversation forward.


    have a nice day
  • Νίκος Αλεξόπουλος at Nov 11, 2013 at 9:57 am

    ???? 8/11/2013 11:11 ??, ?/? ????? ??????????? ??????:
    Is there someway to write the following line even better with the
    ability to detect daylight saving time by itself so i don't have to
    alter the line manually when time changes?

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    Thanks.



    Someone has an idea what to add to this line to automatically adjust
    itself if DST happens?
  • Joel Goldstick at Nov 11, 2013 at 1:41 pm

    On Mon, Nov 11, 2013 at 4:57 AM, ????? ??????????? wrote:
    ???? 8/11/2013 11:11 ??, ?/? ????? ??????????? ??????:
    Is there someway to write the following line even better with the
    ability to detect daylight saving time by itself so i don't have to
    alter the line manually when time changes?

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    Thanks.


    Someone has an idea what to add to this line to automatically adjust itself

    Three days ago Mark Lawrence pointed you to a stack overflow answer to
    your question. While it didn't suit your demand for a single line
    answer, it could easily be made into a function which returned the
    string format that you requested. You've been around long enough to
    try to work that out for yourself. If you yourself had returned with
    a one liner to perform what Mark showed you, I can imagine a lot of
    people would be impressed at your dedication!


    I think you are oversimplifying the problem. I recall that you server
    is in Germany, and you are in Greece. If these are two different time
    zones, I am guessing that the German time will be given. Also, any
    linux user who runs package updates regularly (thinking Ubuntu)
    realizes that some file that starts with tz gets changed quite often.
    This is because time zones are set by governments, and the date of
    change from standard to daylight time can be differently, depending
    upon the location and the governing body.


    I pose this question to you:


    Why not display UTC? If it is so important to you to display local
    time, why do you think that your host's local time is something that
    is useful for a visitor? Daylight savings time is more complicated
    that you have suggested
    if DST happens?

    If you insist upon displaying the local time of your server, you
    should not be hardcoding in a 2 hour difference. Let the python
    library figure out the delta by giving the country code
  • Roy Smith at Nov 11, 2013 at 2:14 pm
    In article <mailman.2377.1384177268.18130.python-list@python.org>,
      Joel Goldstick wrote:

    Why not display UTC? If it is so important to you to display local
    time, why do you think that your host's local time is something that
    is useful for a visitor?

    In general, it makes sense to run servers (and log everything) in UTC,
    and display local time to your users. The idea is to do the conversion
    (in both directions) as close to the user as possible (which, for a web
    application, means a little piece of javascript right in the browser).


    It seems like extra work, but, trust me, it will preserve your sanity
    eventually.


    We've got a data supplier who (for reasons I cannot fathom), runs their
    network in local time. Every time we talk to them about problems, it's
    a mess just trying to figure out what time we're talking about. We say,
    "we saw a latency spike at 2243 UTC, what caused that?", and then we
    play 20-questions trying to figure out if that's 1443 PDT, or 1543 PST,
    or who knows what. Further complicated by them occasionally asking us
    off-the-wall questions like, "Is that UTC daylight savings time?"
  • Chris Angelico at Nov 11, 2013 at 2:25 pm

    On Tue, Nov 12, 2013 at 1:14 AM, Roy Smith wrote:
    We've got a data supplier who (for reasons I cannot fathom), runs their
    network in local time. Every time we talk to them about problems, it's
    a mess just trying to figure out what time we're talking about. We say,
    "we saw a latency spike at 2243 UTC, what caused that?", and then we
    play 20-questions trying to figure out if that's 1443 PDT, or 1543 PST,
    or who knows what. Further complicated by them occasionally asking us
    off-the-wall questions like, "Is that UTC daylight savings time?"

    UGH. Yes. I get the same thing from some of the US players in my
    Dungeons & Dragons campaign. To avoid the hassles of international
    times, everything's scheduled in UTC; the Aussies, the Europeans, and
    _some of_ the Americans an handle it, but there are a few who keep
    asking me crazy questions about DST and UTC. I'm like... no, there is
    no daylight time! Just look at the current UTC time and see how that
    compares! There's even a command in-game that shows current UTC time.


    Fortunately, those people are in the minority. Most of the players can
    handle the time conversions.


    ChrisA
  • Joel Goldstick at Nov 11, 2013 at 2:36 pm
    So this is a physics joke. The engineers and physicists at the
    conference went to dinner. They ordered wine with dinner. The wait
    person asked: "Would you like the small liter, or the large liter?"






    --
    Joel Goldstick
    http://joelgoldstick.com
  • Chris Angelico at Nov 12, 2013 at 2:02 am

    On Tue, Nov 12, 2013 at 12:59 PM, Dennis Lee Bieber wrote:
    Of course, I'm spoiled... My /watch/ has a dial for UTC, along with one
    for 24-hour indication (one hand, range 1 to 24)

    Heh. Mine doesn't, so I bought myself a second watch and set it to
    UTC. So my left hand has local time (changes at DST breaks, changes
    when I travel internationally), and my right hand has UTC (never
    changes).


    ChrisA
  • Chris Angelico at Nov 13, 2013 at 12:40 am

    On Wed, Nov 13, 2013 at 11:30 AM, Dennis Lee Bieber wrote:
    On Tue, 12 Nov 2013 13:02:58 +1100, Chris Angelico <rosuav@gmail.com>
    declaimed the following:
    On Tue, Nov 12, 2013 at 12:59 PM, Dennis Lee Bieber
    wrote:
    Of course, I'm spoiled... My /watch/ has a dial for UTC, along with one
    for 24-hour indication (one hand, range 1 to 24)
    Heh. Mine doesn't, so I bought myself a second watch and set it to
    UTC. So my left hand has local time (changes at DST breaks, changes
    when I travel internationally), and my right hand has UTC (never
    changes).

    http://www.amazon.com/Citizen-JY0000-53E-Skyhawk-Eco-Drive-Watch/dp/B000ZPMYQI

    Only watch I've ever heard of having a recall... The radio synch logic
    fell apart a few years back, and lost a day. As a result mine now has a
    mark from a small center punch on the back to identify it as having had its
    firmware redone.

    I recall the sales lady's blunder... After persuading me on this model
    (it was replacing an earlier Citizen Navi-Hawk as I recall) she tried to
    sell me a battery replacement service plan -- for a watch that charges via
    solar panel!

    My UTC watch is an Eco-Drive too, but without radio sync, and much
    simpler all round than yours. And roughly half the price, and that
    counting the Amazon price not the list price. I don't think I could
    justify to myself spending $650 on a second watch!!


    If only more people would start "thinking UTC", all sorts of
    synchronization problems would vanish.


    ChrisA
  • Denis McMahon at Nov 11, 2013 at 7:19 pm

    On Mon, 11 Nov 2013 11:57:36 +0200, ????? ??????????? wrote:


    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format
    Someone has an idea what to add to this line to automatically adjust
    itself if DST happens?

    Yes, but the scarcity of universal whitespace is preventing me from
    posting it.


    --
    Denis McMahon, denismfmcmahon at gmail.com
  • Ethan Furman at Nov 11, 2013 at 7:39 pm

    On 11/11/2013 11:19 AM, Denis McMahon wrote:
    On Mon, 11 Nov 2013 11:57:36 +0200, ????? ??????????? wrote:

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format
    Someone has an idea what to add to this line to automatically adjust
    itself if DST happens?
    Yes, but the scarcity of universal whitespace is preventing me from
    posting it.

    Boy, are you in luck! I just happen to have a whole heap of marked down ascii white-space at bargain basement prices!


    --
    ~Ethan~
  • Grant Edwards at Nov 11, 2013 at 8:45 pm

    On 2013-11-11, Ethan Furman wrote:
    On 11/11/2013 11:19 AM, Denis McMahon wrote:
    On Mon, 11 Nov 2013 11:57:36 +0200, ?????????? ?????????????????????? wrote:

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format
    Someone has an idea what to add to this line to automatically adjust
    itself if DST happens?
    Yes, but the scarcity of universal whitespace is preventing me from
    posting it.
    Boy, are you in luck! I just happen to have a whole heap of marked
    down ascii white-space at bargain basement prices!

    Careful, a lot of the cheap imported whitespace was made with toxic
    lead carbonate instead of the non-toxic titatium oxide that should be
    used...


    --
    Grant Edwards grant.b.edwards Yow! I'd like MY data-base
                                       at JULIENNED and stir-fried!
                                   gmail.com
  • Mm0fmf at Nov 11, 2013 at 11:21 pm

    On 11/11/2013 19:39, Ethan Furman wrote:
    On 11/11/2013 11:19 AM, Denis McMahon wrote:
    On Mon, 11 Nov 2013 11:57:36 +0200, ????? ??????????? wrote:

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format
    Someone has an idea what to add to this line to automatically adjust
    itself if DST happens?
    Yes, but the scarcity of universal whitespace is preventing me from
    posting it.
    Boy, are you in luck! I just happen to have a whole heap of marked down
    ascii white-space at bargain basement prices!

    Is that metric or imperial whitespace?


    You need metric whitespace for programs written in Europe.
  • Mark Lawrence at Nov 11, 2013 at 11:48 pm

    On 11/11/2013 23:21, mm0fmf wrote:
    On 11/11/2013 19:39, Ethan Furman wrote:
    On 11/11/2013 11:19 AM, Denis McMahon wrote:
    On Mon, 11 Nov 2013 11:57:36 +0200, ????? ??????????? wrote:

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format
    Someone has an idea what to add to this line to automatically adjust
    itself if DST happens?
    Yes, but the scarcity of universal whitespace is preventing me from
    posting it.
    Boy, are you in luck! I just happen to have a whole heap of marked down
    ascii white-space at bargain basement prices!
    Is that metric or imperial whitespace?

    You need metric whitespace for programs written in Europe.

    Except for the UK, our multi-national approach means that both imperial
    and metric whitespace are acceptable.




    --
    Python is the second best programming language in the world.
    But the best has yet to be invented. Christian Tismer


    Mark Lawrence
  • Grant Edwards at Nov 12, 2013 at 4:49 am

    On 2013-11-11, Mark Lawrence wrote:
    On 11/11/2013 23:21, mm0fmf wrote:
    On 11/11/2013 19:39, Ethan Furman wrote:
    On 11/11/2013 11:19 AM, Denis McMahon wrote:
    On Mon, 11 Nov 2013 11:57:36 +0200, ?????????? ?????????????????????? wrote:

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format
    Someone has an idea what to add to this line to automatically adjust
    itself if DST happens?
    Yes, but the scarcity of universal whitespace is preventing me from
    posting it.
    Boy, are you in luck! I just happen to have a whole heap of marked down
    ascii white-space at bargain basement prices!
    Is that metric or imperial whitespace?

    You need metric whitespace for programs written in Europe.
    Except for the UK, our multi-national approach means that both imperial
    and metric whitespace are acceptable.

    Don't forget that there are also some differences between American and
    Imperial whitespace. Since it's ASCII whitespace, you should probably
    assume American...


    --
    Grant
  • Alex23 at Nov 12, 2013 at 7:25 am

    On 12/11/2013 2:49 PM, Grant Edwards wrote:
    Don't forget that there are also some differences between American and
    Imperial whitespace. Since it's ASCII whitespace, you should probably
    assume American...
    sys.getsizeof(' ')
    34
    sys.getsizeof(u' ')
    52


    bad by design
  • Chris Angelico at Nov 12, 2013 at 7:35 am

    On Tue, Nov 12, 2013 at 6:25 PM, alex23 wrote:
    On 12/11/2013 2:49 PM, Grant Edwards wrote:

    Don't forget that there are also some differences between American and
    Imperial whitespace. Since it's ASCII whitespace, you should probably
    assume American...
    sys.getsizeof(' ')
    34
    sys.getsizeof(u' ')
    52

    bad by design

    Yeah, but the proper way to delimit whitespace is with parentheses,
    not quotes. Look:

    sys.getsizeof(( ))
    28


    ChrisA
  • Mark Lawrence at Nov 12, 2013 at 9:20 am

    On 12/11/2013 07:25, alex23 wrote:
    On 12/11/2013 2:49 PM, Grant Edwards wrote:
    Don't forget that there are also some differences between American and
    Imperial whitespace. Since it's ASCII whitespace, you should probably
    assume American...
    sys.getsizeof(' ')
    34
    sys.getsizeof(u' ')
    52

    bad by design

    Don't you start :)


    --
    Python is the second best programming language in the world.
    But the best has yet to be invented. Christian Tismer


    Mark Lawrence
  • Roy Smith at Nov 12, 2013 at 2:18 pm
    In article <l5sc04$3vd$1 at reader1.panix.com>,
      Grant Edwards wrote:

    On 2013-11-11, Mark Lawrence wrote:
    On 11/11/2013 23:21, mm0fmf wrote:
    On 11/11/2013 19:39, Ethan Furman wrote:
    On 11/11/2013 11:19 AM, Denis McMahon wrote:
    On Mon, 11 Nov 2013 11:57:36 +0200, ?????????? ??????????????????????
    wrote:
    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format
    Someone has an idea what to add to this line to automatically adjust
    itself if DST happens?
    Yes, but the scarcity of universal whitespace is preventing me from
    posting it.
    Boy, are you in luck! I just happen to have a whole heap of marked down
    ascii white-space at bargain basement prices!
    Is that metric or imperial whitespace?

    You need metric whitespace for programs written in Europe.
    Except for the UK, our multi-national approach means that both imperial
    and metric whitespace are acceptable.
    Don't forget that there are also some differences between American and
    Imperial whitespace. Since it's ASCII whitespace, you should probably
    assume American...

    And don't assume that the whitespace you find in a red state is the same
    as you'll find in a blue state.
  • Ferrous Cranus at Nov 12, 2013 at 10:15 am

    ???? 8/11/2013 11:11 ??, ?/? ????? ??????????? ??????:
    Is there someway to write the following line even better with the
    ability to detect daylight saving time by itself so i don't have to
    alter the line manually when time changes?

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    Thanks.



    Example:


    #check if date entered as intented, format it properly for MySQL
    lastvisit = datetime.strptime(lastvisit, '%d %m %Y').strftime('%Y-%m-%d')


    The above code gets the datetime string in a specific way and then
    convert it to another format. All happens in one line clear and simple.


    Now, in the following statement there shopuld be some way to check for
    daylight saving time so i would aboiut add +2 in winter or +3 for greek
    summer time.


    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format


    I think + timedelta(hours=2) should be substituted with something else
    but i don't with what.
  • Andy Lawton at Nov 12, 2013 at 12:47 pm
    Firstly , I should clarify I have no idea how to program python, I joined
    this mailing list in anticipation of learning soon. And thought I'd have a
    go playing around with your code and code given to you (worst possible
    place to start, I'm sure)


    But from the answers already given to you, this seems to work and as you
    requested, in reality, this keeps your code to 1 line...


    I'm sure this is wrong, and isn't what you want, but hey, Correct working
    code doesn't seem to matter to you anyway...


    (I think "Europe/Kiev" is Greece but I don't know)


    from datetime import datetime, time, timedelta
    import time
    import pytz


    def is_dst(zonename):
         tz = pytz.timezone(zonename)
         now = pytz.utc.localize(datetime.utcnow())
         return now.astimezone(tz).dst() != timedelta(0)


    def dst_greece():
         if is_dst("Europe/Kiev") :
             diff = 2
         else:
             diff = 3
         return diff


    lastvisit = (datetime.utcnow() +timedelta(hours=dst_greece())).strftime(
    '%y-%m-%d %H:%M:%S' )




    On 12 November 2013 10:15, Ferrous Cranus wrote:

    ???? 8/11/2013 11:11 ??, ?/? ????? ??????????? ??????:
    Is there someway to write the following line even better with the

    ability to detect daylight saving time by itself so i don't have to
    alter the line manually when time changes?

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    Thanks.

    Example:

    #check if date entered as intented, format it properly for MySQL
    lastvisit = datetime.strptime(lastvisit, '%d %m %Y').strftime('%Y-%m-%d')

    The above code gets the datetime string in a specific way and then convert
    it to another format. All happens in one line clear and simple.

    Now, in the following statement there shopuld be some way to check for
    daylight saving time so i would aboiut add +2 in winter or +3 for greek
    summer time.


    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime( '%y-%m-%d
    %H:%M:%S' ) # MySQL datetime format

    I think + timedelta(hours=2) should be substituted with something else but
    i don't with what.
    --
    https://mail.python.org/mailman/listinfo/python-list
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20131112/9f4f0333/attachment-0001.html>
  • Ferrous Cranus at Nov 12, 2013 at 1:32 pm

    ???? 12/11/2013 2:47 ??, ?/? Andy Lawton ??????:
    Firstly , I should clarify I have no idea how to program python, I
    joined this mailing list in anticipation of learning soon. And
    thought I'd have a go playing around with your code and code given to
    you (worst possible place to start, I'm sure)

    But from the answers already given to you, this seems to work and as you
    requested, in reality, this keeps your code to 1 line...

    I'm sure this is wrong, and isn't what you want, but hey, Correct
    working code doesn't seem to matter to you anyway...

    (I think "Europe/Kiev" is Greece but I don't know)

    from datetime import datetime, time, timedelta
    import time
    import pytz

    def is_dst(zonename):
    tz = pytz.timezone(zonename)
    now = pytz.utc.localize(datetime.utcnow())
    return now.astimezone(tz).dst() != timedelta(0)

    def dst_greece():
    if is_dst("Europe/Kiev") :
    diff = 2
    else:
    diff = 3
    return diff

    lastvisit = (datetime.utcnow() +timedelta(hours=dst_greece())).strftime(
    '%y-%m-%d %H:%M:%S' )


    On 12 November 2013 10:15, Ferrous Cranus <nikos.gr33k at gmail.com
    wrote:

    ???? 8/11/2013 11:11 ??, ?/? ????? ??????????? ??????:

    Is there someway to write the following line even better with the

    ability to detect daylight saving time by itself so i don't have to
    alter the line manually when time changes?

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    Thanks.



    Example:

    #check if date entered as intented, format it properly for MySQL
    lastvisit = datetime.strptime(lastvisit, '%d %m
    %Y').strftime('%Y-%m-%d')

    The above code gets the datetime string in a specific way and then
    convert it to another format. All happens in one line clear and simple.

    Now, in the following statement there shopuld be some way to check
    for daylight saving time so i would aboiut add +2 in winter or +3
    for greek summer time.


    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    I think + timedelta(hours=2) should be substituted with something
    else but i don't with what.
    --
    https://mail.python.org/__mailman/listinfo/python-list
    <https://mail.python.org/mailman/listinfo/python-list>



    this requires a function to be declared while i just want just an
    argument inside timedelta( ) that will automatically detect DST or not.


    No function declaration but instead something like:
    lastvisit = ( datetime.utcnow() + timedelta( some_arg_here_that_can
    detect greece's_DST_or_not) ).strftime) '%y-%m-%d %H:%M:%S' )
         # MySQL datetime format
  • Joel Goldstick at Nov 12, 2013 at 2:03 pm

    On Tue, Nov 12, 2013 at 8:32 AM, Ferrous Cranus wrote:
    ???? 12/11/2013 2:47 ??, ?/? Andy Lawton ??????:
    Firstly , I should clarify I have no idea how to program python, I
    joined this mailing list in anticipation of learning soon. And
    thought I'd have a go playing around with your code and code given to
    you (worst possible place to start, I'm sure)

    But from the answers already given to you, this seems to work and as you
    requested, in reality, this keeps your code to 1 line...

    I'm sure this is wrong, and isn't what you want, but hey, Correct
    working code doesn't seem to matter to you anyway...

    (I think "Europe/Kiev" is Greece but I don't know)

    from datetime import datetime, time, timedelta
    import time
    import pytz

    def is_dst(zonename):
    tz = pytz.timezone(zonename)
    now = pytz.utc.localize(datetime.utcnow())
    return now.astimezone(tz).dst() != timedelta(0)

    def dst_greece():
    if is_dst("Europe/Kiev") :
    diff = 2
    else:
    diff = 3
    return diff

    lastvisit = (datetime.utcnow() +timedelta(hours=dst_greece())).strftime(
    '%y-%m-%d %H:%M:%S' )


    On 12 November 2013 10:15, Ferrous Cranus <nikos.gr33k at gmail.com
    wrote:

    ???? 8/11/2013 11:11 ??, ?/? ????? ??????????? ??????:

    Is there someway to write the following line even better with the

    ability to detect daylight saving time by itself so i don't have
    to
    alter the line manually when time changes?

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    Thanks.



    Example:

    #check if date entered as intented, format it properly for MySQL
    lastvisit = datetime.strptime(lastvisit, '%d %m
    %Y').strftime('%Y-%m-%d')

    The above code gets the datetime string in a specific way and then
    convert it to another format. All happens in one line clear and
    simple.

    Now, in the following statement there shopuld be some way to check
    for daylight saving time so i would aboiut add +2 in winter or +3
    for greek summer time.


    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    I think + timedelta(hours=2) should be substituted with something
    else but i don't with what.
    --
    https://mail.python.org/__mailman/listinfo/python-list
    <https://mail.python.org/mailman/listinfo/python-list>

    this requires a function to be declared while i just want just an argument
    inside timedelta( ) that will automatically detect DST or not.

    No function declaration but instead something like:
    lastvisit = ( datetime.utcnow() + timedelta( some_arg_here_that_can detect
    greece's_DST_or_not) ).strftime) '%y-%m-%d %H:%M:%S' ) # MySQL
    datetime format



    --
    https://mail.python.org/mailman/listinfo/python-list

    I think that is a great solution. What would happen if you just did this:
    lastvisit2 = (datetime.now()).strftime('%y-%m-%d %H:%M:%S' )


    Why don't you try it out and see what you find?


    (PS, this was pointed out to me by a pro, so I did a little reading in
    the python docs and took Andy's excellent code and added a couple of
    lines to test.)


    I switched to my local timezone "US/Eastern" to test. My machine is
    running Ubuntu. It seems to know that it is in the Eastern US. If
    your server knows where it lives, then this should work for you also.
    If it is set to a different timezone, I'm not sure I could help you,
    but I'm sure someone could. You even might ask your host if this is
    possible.


    ----------------------
    #! /usr/bin/env python


    from datetime import datetime, time, timedelta
    import time
    import pytz


    def is_dst(zonename):
          tz = pytz.timezone(zonename)
          now = pytz.utc.localize(datetime.utcnow())
          return now.astimezone(tz).dst() != timedelta(0)


    def dst_greece():
          #if is_dst("Europe/Kiev") :
          if is_dst("US/Eastern") :
              diff = -6
          else:
              diff = -5
          return diff


    lastvisit = (datetime.utcnow()
    +timedelta(hours=dst_greece())).strftime('%y-%m-%d %H:%M:%S' )


    lastvisit2 = (datetime.now()).strftime('%y-%m-%d %H:%M:%S' )


    print lastvisit
    print lastvisit2


    ----------------------




    --
    Joel Goldstick
    http://joelgoldstick.com
  • Ferrous Cranus at Nov 12, 2013 at 2:12 pm

    ???? 12/11/2013 4:03 ??, ?/? Joel Goldstick ??????:
    On Tue, Nov 12, 2013 at 8:32 AM, Ferrous Cranus wrote:
    ???? 12/11/2013 2:47 ??, ?/? Andy Lawton ??????:
    Firstly , I should clarify I have no idea how to program python, I
    joined this mailing list in anticipation of learning soon. And
    thought I'd have a go playing around with your code and code given to
    you (worst possible place to start, I'm sure)

    But from the answers already given to you, this seems to work and as you
    requested, in reality, this keeps your code to 1 line...

    I'm sure this is wrong, and isn't what you want, but hey, Correct
    working code doesn't seem to matter to you anyway...

    (I think "Europe/Kiev" is Greece but I don't know)

    from datetime import datetime, time, timedelta
    import time
    import pytz

    def is_dst(zonename):
    tz = pytz.timezone(zonename)
    now = pytz.utc.localize(datetime.utcnow())
    return now.astimezone(tz).dst() != timedelta(0)

    def dst_greece():
    if is_dst("Europe/Kiev") :
    diff = 2
    else:
    diff = 3
    return diff

    lastvisit = (datetime.utcnow() +timedelta(hours=dst_greece())).strftime(
    '%y-%m-%d %H:%M:%S' )


    On 12 November 2013 10:15, Ferrous Cranus <nikos.gr33k at gmail.com
    wrote:

    ???? 8/11/2013 11:11 ??, ?/? ????? ??????????? ??????:

    Is there someway to write the following line even better with the

    ability to detect daylight saving time by itself so i don't have
    to
    alter the line manually when time changes?

    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    Thanks.



    Example:

    #check if date entered as intented, format it properly for MySQL
    lastvisit = datetime.strptime(lastvisit, '%d %m
    %Y').strftime('%Y-%m-%d')

    The above code gets the datetime string in a specific way and then
    convert it to another format. All happens in one line clear and
    simple.

    Now, in the following statement there shopuld be some way to check
    for daylight saving time so i would aboiut add +2 in winter or +3
    for greek summer time.


    lastvisit = ( datetime.utcnow() + timedelta(hours=2) ).strftime(
    '%y-%m-%d %H:%M:%S' ) # MySQL datetime format

    I think + timedelta(hours=2) should be substituted with something
    else but i don't with what.
    --
    https://mail.python.org/__mailman/listinfo/python-list
    <https://mail.python.org/mailman/listinfo/python-list>

    this requires a function to be declared while i just want just an argument
    inside timedelta( ) that will automatically detect DST or not.

    No function declaration but instead something like:
    lastvisit = ( datetime.utcnow() + timedelta( some_arg_here_that_can detect
    greece's_DST_or_not) ).strftime) '%y-%m-%d %H:%M:%S' ) # MySQL
    datetime format



    --
    https://mail.python.org/mailman/listinfo/python-list
    I think that is a great solution. What would happen if you just did this:
    lastvisit2 = (datetime.now()).strftime('%y-%m-%d %H:%M:%S' )

    Why don't you try it out and see what you find?

    (PS, this was pointed out to me by a pro, so I did a little reading in
    the python docs and took Andy's excellent code and added a couple of
    lines to test.)

    I switched to my local timezone "US/Eastern" to test. My machine is
    running Ubuntu. It seems to know that it is in the Eastern US. If
    your server knows where it lives, then this should work for you also.
    If it is set to a different timezone, I'm not sure I could help you,
    but I'm sure someone could. You even might ask your host if this is
    possible.

    ----------------------
    #! /usr/bin/env python

    from datetime import datetime, time, timedelta
    import time
    import pytz

    def is_dst(zonename):
    tz = pytz.timezone(zonename)
    now = pytz.utc.localize(datetime.utcnow())
    return now.astimezone(tz).dst() != timedelta(0)

    def dst_greece():
    #if is_dst("Europe/Kiev") :
    if is_dst("US/Eastern") :
    diff = -6
    else:
    diff = -5
    return diff

    lastvisit = (datetime.utcnow()
    +timedelta(hours=dst_greece())).strftime('%y-%m-%d %H:%M:%S' )

    lastvisit2 = (datetime.now()).strftime('%y-%m-%d %H:%M:%S' )

    print lastvisit
    print lastvisit2

    ----------------------



    Joel i must thank you for your help.


    I cannot believe it was so simple.


    lastvisit = ( datetime.now() ).strftime('%y-%m-%d %H:%M:%S') # MySQL
    datetime format




    Tnhe server is self aware of its location so why use utcnow() +
    timedelte( some_digit_here ) when you can just use just now()


    Great solution, no need for function declaration and importing of new
    pytz modules.


    Simple and straightforward, Thank you!
  • Chris Angelico at Nov 12, 2013 at 2:57 pm

    On Wed, Nov 13, 2013 at 1:12 AM, Ferrous Cranus wrote:
    Joel i must thank you for your help.

    I cannot believe it was so simple.

    Tnhe server is self aware of its location so why use utcnow() + timedelte(
    some_digit_here ) when you can just use just now()

    Did you ever go and look at the docs, like you were advised to?


    Next time you have a problem, go read the docs. You never know, you
    might discover something!


    ChrisA
  • Ferrous Cranus at Nov 12, 2013 at 3:24 pm

    ???? 12/11/2013 4:57 ??, ?/? Chris Angelico ??????:
    On Wed, Nov 13, 2013 at 1:12 AM, Ferrous Cranus wrote:
    Joel i must thank you for your help.

    I cannot believe it was so simple.

    Tnhe server is self aware of its location so why use utcnow() + timedelte(
    some_digit_here ) when you can just use just now()
    Did you ever go and look at the docs, like you were advised to?

    Next time you have a problem, go read the docs. You never know, you
    might discover something!

    ChrisA



    But what of the server was in California and i live in Greece?


    How would datetime.now() work then?


    now() would return the time fo the server not my local time, so if i
    change servers and the server isn't located to the same timezone as i'am
    locally, wouldn't that raise a problem?
  • Tim Chase at Nov 12, 2013 at 3:54 pm

    On 2013-11-12 17:24, Ferrous Cranus wrote:
    But what of the server was in California and i live in Greece?

    How would datetime.now() work then?

    Best practices say to move the value from local time to UTC as soon
    as possible, then store/use the UTC time internally for all
    operations. Only when it's about to be presented to the user should
    you convert it back to local time if you need to.


    -tkc
  • Ferrous Cranus at Nov 12, 2013 at 3:57 pm

    ???? 12/11/2013 5:54 ??, ?/? Tim Chase ??????:
    On 2013-11-12 17:24, Ferrous Cranus wrote:
    But what of the server was in California and i live in Greece?

    How would datetime.now() work then?
    Best practices say to move the value from local time to UTC as soon
    as possible, then store/use the UTC time internally for all
    operations. Only when it's about to be presented to the user should
    you convert it back to local time if you need to.

    -tkc




    or perhaps by confiruing the timezone of the server to use Greece's
    TimeZone by issuing a linux command?
  • Tim Chase at Nov 12, 2013 at 4:12 pm

    On 2013-11-12 17:57, Ferrous Cranus wrote:
    Best practices say to move the value from local time to UTC as
    soon as possible, then store/use the UTC time internally for all
    operations. Only when it's about to be presented to the user
    should you convert it back to local time if you need to.
    or perhaps by confiruing the timezone of the server to use Greece's
    TimeZone by issuing a linux command?

    Regardless of the server's configured TZ, best practice still says to
    normalize everything to UTC (ESPECIALLY if Greece uses the
    abomination of DST that we suffer here in the US) as soon as
    possible and keep it that way for as long as possible.


    -tkc

Related Discussions

People

Translate

site design / logo © 2022 Grokbase