Re: datetime question

2013-11-12 Thread MRAB

On 13/11/2013 00:37, Dennis Lee Bieber wrote:

On Wed, 13 Nov 2013 09:42:38 +1100, Chris Angelico 
declaimed the following:



Plus, they switch clocks at 2am all the time, not at 2am forward and
3am backward.


2AM is the time at which US switches occur also, in either direction.


The difference compared with the EU is that they switch according to
local time, so different US time zones switch at different UTC times.


Unfortunately, my radio controlled clocks tend to synchronize between 1
and 2 AM, and those that automatically do daylight vs normal switching
(three Oregon Scientific) miss the broadcast of the change. My watch and a
LaCrosse unit require manual toggling between the two.


Good thing I don't run a store... I'd annoy my customers by changing
the store hours instead 



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


Re: datetime question

2013-11-12 Thread Roy Smith
In article ,
 Alister  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.
> > 
> > -tkc
> 
> & it is probably best converted to local time client side (as has already 
> been suggested) you may end up with a situation where the server is in 
> the USA & your user is in Portugal.

Or, your server is in California, your user is in Portugal, and he 
prefers to keep his laptop on New York time.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 11:30 AM, Dennis Lee Bieber
 wrote:
> On Tue, 12 Nov 2013 13:02:58 +1100, Chris Angelico 
> 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-JY-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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Chris Angelico
On Wed, Nov 13, 2013 at 6:14 AM, Joel Goldstick
 wrote:
> In the US, the state of Indiana is really weird.  Three separate time
> zone areas, that don't all flip in the same way.  See this for TZ
> hell:  http://en.wikipedia.org/wiki/Indiana_time_zones

Timezones are one of the most interesting [1] things in the world.
Ireland doesn't move clocks forward for summer time, they move them
backward for winter time... I swear, when I first heard that, I
thought it was just one of those Irish jokes with no basis, but it is
true...

https://en.wikipedia.org/wiki/Time_in_the_Republic_of_Ireland

Plus, they switch clocks at 2am all the time, not at 2am forward and
3am backward.

ChrisA

[1] Define "interesting".
http://www.imdb.com/title/tt0379786/quotes?item=qt0433039
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Denis McMahon
On Tue, 12 Nov 2013 17:57:55 +0200, Ferrous Cranus wrote:

> or perhaps by confiruing the timezone of the server to use Greece's
> TimeZone by issuing a linux command?

If you have that degreee of control over the server, yes, but UTC is 
always safer, because if you need to move your server to a different site 
(eg disaster recovery) UTC is still UTC.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Denis McMahon
On Tue, 12 Nov 2013 12:47:58 +, Andy Lawton wrote:

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

I suspect Nick is really in a coding sweatshop in "Asia/Mumbai"

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Joel Goldstick
On Tue, Nov 12, 2013 at 2:09 PM, MRAB  wrote:
> On 12/11/2013 16:12, Tim Chase wrote:
>>
>> 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.
>>
> FTR, the countries in the EU all change at the same (UTC) time.
> --
> https://mail.python.org/mailman/listinfo/python-list

In the US, the state of Indiana is really weird.  Three separate time
zone areas, that don't all flip in the same way.  See this for TZ
hell:  http://en.wikipedia.org/wiki/Indiana_time_zones

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread MRAB

On 12/11/2013 16:12, Tim Chase wrote:

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.


FTR, the countries in the EU all change at the same (UTC) time.
--
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Mark Lawrence

On 12/11/2013 16:12, Tim Chase wrote:


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




Why oh why do I have an image of people at Bletchley Park trying to 
switch Colossus from GMT to DOUBLE British Summer Time and back again?


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

Mark Lawrence

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


Re: datetime question

2013-11-12 Thread Alister
On Tue, 12 Nov 2013 09:54:44 -0600, Tim Chase wrote:

> 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

& it is probably best converted to local time client side (as has already 
been suggested) you may end up with a situation where the server is in 
the USA & your user is in Portugal.
how i you going to identify the users time zone server side(clue you cant 
at least not reliably).

whatever solution you take it is better written as a function rather than 
a single line of code so it can be re-used, you are almost certainly 
going to want this in more than one place


complicated one-liners may "look cool" to show of your programming skills 
but in the real world they are a maintenance nightmare & are probably 
best avoided.


-- 
The plot was designed in a light vein that somehow became varicose.
-- David Lardner
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread William Ray Wing
On Nov 12, 2013, at 10:57 AM, Ferrous Cranus  wrote:

> Στις 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?
> -- 
> 

Thus totally screwing all the other users/sites hosted on that server? Thus 
totally screwing up all the housekeeping and maintenance OS tasks that are run 
by chron jobs?

Shakes head in dismay...

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


Re: datetime question

2013-11-12 Thread Tim Chase
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


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


Re: datetime question

2013-11-12 Thread Ferrous Cranus

Στις 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?

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


Re: datetime question

2013-11-12 Thread 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



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


Re: datetime question

2013-11-12 Thread Ferrous Cranus

Στις 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?

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


Re: datetime question

2013-11-12 Thread 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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Roy Smith
In article ,
 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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Ferrous Cranus

Στις 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 mailto:nikos.gr...@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
 





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!
--
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread 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 > > 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
>> 
>>
>>
>
>
> 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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-12 Thread Ferrous Cranus

Στις 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 mailto:nikos.gr...@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






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


Re: datetime question

2013-11-12 Thread 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  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


Re: datetime question

2013-11-12 Thread Ferrous Cranus

Στις 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


Re: datetime question

2013-11-12 Thread Mark Lawrence

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

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


Re: datetime question

2013-11-11 Thread Chris Angelico
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread alex23

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
--
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread Grant Edwards
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



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


Re: datetime question

2013-11-11 Thread Chris Angelico
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread Mark Lawrence

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

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


Re: datetime question

2013-11-11 Thread mm0fmf

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.



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


Re: datetime question

2013-11-11 Thread Joel Goldstick
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
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread rurpy
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread Grant Edwards
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.edwardsYow! I'd like MY data-base
  at   JULIENNED and stir-fried!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread Ethan Furman

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~
--
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread Denis McMahon
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, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread Joel Goldstick
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread Chris Angelico
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread Roy Smith
In article ,
 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?"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread Joel Goldstick
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
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-11 Thread Νίκος Αλεξόπουλος

Στις 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?

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


Re: datetime question

2013-11-10 Thread unknown
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!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-10 Thread Gene Heskett
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-10 Thread Chris Angelico
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-10 Thread Gene Heskett
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-09 Thread Chris Angelico
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-09 Thread Gene Heskett
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.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-09 Thread Roy Smith
In article ,
 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!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-09 Thread Chris Angelico
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-09 Thread Νίκος Αλεξόπουλος

Στις 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.

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


Re: datetime question

2013-11-09 Thread Chris Angelico
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-09 Thread 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?

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

Mark Lawrence

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


Re: datetime question

2013-11-08 Thread 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.


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

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


Re: datetime question

2013-11-08 Thread Chris Angelico
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-08 Thread Robert Kern

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

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


Re: datetime question

2013-11-08 Thread Νίκος Αλεξόπουλος

Στις 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.
--
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-08 Thread 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.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-08 Thread Grant Edwards
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.edwardsYow! Mary Tyler Moore's
  at   SEVENTH HUSBAND is wearing
  gmail.commy DACRON TANK TOP in a
   cheap hotel in HONOLULU!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-08 Thread Mark Lawrence

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

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


Re: datetime question

2013-11-08 Thread Joel Goldstick
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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2013-11-08 Thread Νίκος Αλεξόπουλος

Στις 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


Re: datetime question

2013-11-08 Thread 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

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

Mark Lawrence

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


Re: datetime question

2009-10-31 Thread Ben Finney
Albert Hopkins  writes:

> No, I meant "cleaning up the standard library in spite of
> incompatibilities" was one of the goals of Python3 (PEP 3108).

Ah, okay. That PEP is “Standard Library Reorganization”
http://www.python.org/dev/peps/pep-3108/>, and is specifically
about removing or renaming modules to “clean up” the library.

I don't think it applies to this conversation, which is not about
renaming nor removing modules.

> Personally I don't see anything wrong with the modules, but that was
> my question to the person who said they should all be integrated but
> wasn't because of incompatibilities.

The changes I'm suggesting would be necessary are to the behaviour of
the ‘time’, ‘datetime’, and ‘calendar’ modules: the types they consume
and produce would be unified. They're not now, which would represent an
incompatible API change, not covered by PEP 3108 nor any Python 2→3 PEP
to my knowledge.

-- 
 \ “Alternative explanations are always welcome in science, if |
  `\   they are better and explain more. Alternative explanations that |
_o__) explain nothing are not welcome.” —Victor J. Stenger, 2001-11-05 |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2009-10-31 Thread Victor Subervi
Thanks, Rami, that will work.
V

On Sat, Oct 31, 2009 at 4:54 AM, Albert Hopkins wrote:

> On Sat, 2009-10-31 at 20:34 +1100, Ben Finney wrote:
> > Fixing ‘time’, ‘datetime’, and ‘calendar’ was the reason for Python 3?
> > No, it wasn't.
> >
> > Or perhaps you mean that any backward-incompatible change was a reason
> > to have Python 3? Even more firmly no. The extent of changes was
> > severely limited to make the transition from Python 2 to Python 3 as
> > painless as feasible, while still meeting the goals of Python 3.
>
> No, I meant "cleaning up the standard library in spite of
> incompatibilities" was one of the goals of Python3 (PEP 3108).
> Personally I don't see anything wrong with the modules, but that was my
> question to the person who said they should all be integrated but wasn't
> because of incompatibilities.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2009-10-31 Thread Albert Hopkins
On Sat, 2009-10-31 at 20:34 +1100, Ben Finney wrote:
> Fixing ‘time’, ‘datetime’, and ‘calendar’ was the reason for Python 3?
> No, it wasn't.
> 
> Or perhaps you mean that any backward-incompatible change was a reason
> to have Python 3? Even more firmly no. The extent of changes was
> severely limited to make the transition from Python 2 to Python 3 as
> painless as feasible, while still meeting the goals of Python 3. 

No, I meant "cleaning up the standard library in spite of
incompatibilities" was one of the goals of Python3 (PEP 3108).
Personally I don't see anything wrong with the modules, but that was my
question to the person who said they should all be integrated but wasn't
because of incompatibilities.

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


Re: datetime question

2009-10-31 Thread Ben Finney
Albert Hopkins  writes:

> On Sat, 2009-10-31 at 10:08 +1100, Ben Finney wrote:
> > Yes, it would be nice if the ‘time’, ‘datetime’, and ‘calendar’
> > modules were all much more unified and consumed a common set of
> > primitive date+time types. It's a wart, and fixing it would
> > (unfortunately) probably require backward-incompatible API changes.
>
> But, supposedly, that's why we had Python3.

Fixing ‘time’, ‘datetime’, and ‘calendar’ was the reason for Python 3?
No, it wasn't.

Or perhaps you mean that any backward-incompatible change was a reason
to have Python 3? Even more firmly no. The extent of changes was
severely limited to make the transition from Python 2 to Python 3 as
painless as feasible, while still meeting the goals of Python 3.

-- 
 \“Odious ideas are not entitled to hide from criticism behind |
  `\  the human shield of their believers' feelings.” —Richard |
_o__) Stallman |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2009-10-31 Thread Albert Hopkins
On Sat, 2009-10-31 at 10:08 +1100, Ben Finney wrote:
> The ‘datetime’ module focusses on individual date+time values (and the
> periods between them, with the ‘timedelta’ type).
> 
> For querying the properties of the calendar, use the ‘calendar’
> module.
> 
> Yes, it would be nice if the ‘time’, ‘datetime’, and ‘calendar’
> modules
> were all much more unified and consumed a common set of primitive
> date+time types. It's a wart, and fixing it would (unfortunately)
> probably require backward-incompatible API changes.
> 

But, supposedly, that's why we had Python3.

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


Re: datetime question

2009-10-30 Thread Ben Finney
Victor Subervi  writes:

> What I need to calculate is the length of days in the given month. How
> do I do that?

The ‘datetime’ module focusses on individual date+time values (and the
periods between them, with the ‘timedelta’ type).

For querying the properties of the calendar, use the ‘calendar’ module.

Yes, it would be nice if the ‘time’, ‘datetime’, and ‘calendar’ modules
were all much more unified and consumed a common set of primitive
date+time types. It's a wart, and fixing it would (unfortunately)
probably require backward-incompatible API changes.

-- 
 \“Simplicity is prerequisite for reliability.” —Edsger W. |
  `\  Dijkstra |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2009-10-30 Thread Rami Chowdhury
On Fri, 30 Oct 2009 13:03:32 -0700, Victor Subervi  
 wrote:



Hi;
I have this code:

today = datetime.date.today()
day = today.day
mo = today.month
yr = today.year

Works great. What I need to calculate is the length of days in the
given month. How do I do that?
TIA,
Victor



Off the top of my head:
You could calculate it fairly easily by subtracting a datetime object  
representing the first of this month from a datetime object representing  
the first of next month; that'd give you a timedelta object with the  
number of days.


Alternatively, of course, you could look up the number of days in the  
current month using the calendar module ;-)




--
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor

408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
--
http://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2009-03-06 Thread Chris Rebert
On Fri, Mar 6, 2009 at 7:24 AM,   wrote:
> Just curious if this is the best way to get the first 3 letters of the 
> current month?
>
 import datetime

 d = datetime.date.today()
 m = d.strftime("%B")[:3].upper()
 m
> 'MAR'

I believe you want the lowercase version, "%b" (Locale’s abbreviated
month name):

>>> import datetime
>>> datetime.date.today().strftime("%b")
'Mar'

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Datetime question

2006-08-03 Thread Rama
Ah, true. Sorry. I got thrown by the ouput after the line got executed and assumed it was the value of a.
 
thanks,
Rama
 
On 03/08/06, Simon Brunning <[EMAIL PROTECTED]> wrote:
On 8/3/06, Rama <[EMAIL PROTECTED]> wrote:
> Just curious why when> I call id(a) I get the same id after I call the replace method.In your example, you called a's replace() method, but did nothing withthe new datetime object that it returned. The original object, a,
naturally still has the same ID, but it also still has the same value.--Cheers,Simon B,[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Datetime question

2006-08-03 Thread Simon Brunning
On 8/3/06, Rama <[EMAIL PROTECTED]> wrote:
> Just curious why when
> I call id(a) I get the same id after I call the replace method.

In your example, you called a's replace() method, but did nothing with
the new datetime object that it returned. The original object, a,
naturally still has the same ID, but it also still has the same value.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Datetime question

2006-08-03 Thread Rama
datetime objects are immutable. You can't change the value of anexisting datetime object, only create a new one.

 
 
Um.. then how do I get the same ID when I call the replace method?
 
 
>>> a = datetime.datetime(2006, 8, 12, 10, 13, 56, 609000)>>> b = a + datetime.timedelta(days=-2, hours=-4)>>
>>> id(a)21838592>>> id(b) 21836312>>> a.replace(day=a.day + 1)datetime.datetime(2006, 8, 13, 10, 13, 56, 609000)>>> id(a)21838592>>>

 
thanks,
Rama 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Datetime question

2006-08-03 Thread Simon Brunning
On 8/3/06, Rama <[EMAIL PROTECTED]> wrote:
> But wont this create a new object? Whereas if you want to modify the same
> object, should we not be using replace? Or does it not matter in the global
> picture?

datetime objects are immutable. You can't change the value of an
existing datetime object, only create a new one.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Datetime question

2006-08-03 Thread Rama

> In a datetime object I would like to change days and hours.you'd been pointed to the resources yesterday - please read manuals
carefully!a = datetime.datetime(2006, 8, 12, 10, 13, 56, 609000)b = a + datetime.timedelta(days=-2, hours=-4)
 

   
But wont this create a new object? Whereas if you want to modify the same object, should we not be using replace? Or does it not matter in the global picture?
 
>>> a = datetime.datetime(2006, 8, 12, 10, 13, 56, 609000)>>> b = a + datetime.timedelta(days=-2, hours=-4)> id(a)21838592>>> id(b)
21836312>>> a.replace(day=a.day + 1)datetime.datetime(2006, 8, 13, 10, 13, 56, 609000)>>> id(a)21838592>>>
 

 
thanks,
Rama
 
   
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Datetime question

2006-08-03 Thread Diez B. Roggisch
Lad schrieb:
> In a datetime object I would like to change days and hours.
> Or in other words, I would like to copy this datetime object but
> increase days and hours.
> Is it possible?
> For example:If I have a datetime object like this
> datetime.datetime(2006, 8, 3, 14, 13, 56, 609000)
> 
> I would like to make a new ,for example like this
> 
> datetime.datetime(2006, 8, 12, 10, 13, 56, 609000)
> 
> is it possible to do so?

you'd been pointed to the resources yesterday - please read manuals 
carefully!

a = datetime.datetime(2006, 8, 12, 10, 13, 56, 609000)
b = a + datetime.timedelta(days=-2, hours=-4)


Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Datetime question

2006-08-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Lad wrote:

> In a datetime object I would like to change days and hours.
> Or in other words, I would like to copy this datetime object but
> increase days and hours.
> Is it possible?
> For example:If I have a datetime object like this
> datetime.datetime(2006, 8, 3, 14, 13, 56, 609000)
> 
> I would like to make a new ,for example like this
> 
> datetime.datetime(2006, 8, 12, 10, 13, 56, 609000)
> 
> is it possible to do so?

Yes it is, just add a `timedelta` object:

In [18]: a = datetime.datetime(2006, 8, 3, 14, 13, 56, 609000)

In [19]: a + datetime.timedelta(days=8, hours=20)
Out[19]: datetime.datetime(2006, 8, 12, 10, 13, 56, 609000)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Datetime question

2006-08-03 Thread Rama
the datetime object appears to have a replace method which could achieve what you want to do, albeith with some computation from your end first,
 
>>> d = datetime.datetime(2006, 8, 3, 14, 13, 56, 609000)>>> dir(d)['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__ne
w__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__str__', '__sub__', 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst', 'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat', 'isowe
ekday', 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 'time', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple'
, 'weekday', 'year']>>> d.replace(year=2007)datetime.datetime(2007, 8, 3, 14, 13, 56, 609000)>>>
 
thanks,
Rama
 
On 3 Aug 2006 05:26:31 -0700, Lad <[EMAIL PROTECTED]> wrote:
In a datetime object I would like to change days and hours.Or in other words, I would like to copy this datetime object but
increase days and hours.Is it possible?For example:If I have a datetime object like thisdatetime.datetime(2006, 8, 3, 14, 13, 56, 609000)I would like to make a new ,for example like thisdatetime.datetime
(2006, 8, 12, 10, 13, 56, 609000)is it possible to do so?Thank youL--http://mail.python.org/mailman/listinfo/python-list

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

Re: datetime question

2006-04-19 Thread Philippe Martin
:-)

Thanks.

Philippe


Scott David Daniels wrote:

> Jorge Godoy wrote:
>> Philippe Martin wrote:
>> 
>>> I need to get the date and time under Windows and Linux but need the
>>> information visible to the user (cannot find my words) not the sytem
>>> information (ex: a PC setup on greenwich but the date/time displayed are
>>> relative to some other place.
>> 
>> Something like this?
>> 
> import datetime
> datetime.datetime.now()
>> ...
> 
> Just so you (Phillipe) know, you are talking about "local time" vs. UTC.
>  >>> import datetime
>  >>> print datetime.datetime.now() # local
>  2006-04-18 15:25:03.14
>  >>> print datetime.datetime.utcnow() # zulu / utc / gmt
>  2006-04-18 22:25:13.625000
> 
> --Scott David Daniels
> [EMAIL PROTECTED]

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


Re: datetime question

2006-04-18 Thread Scott David Daniels
Jorge Godoy wrote:
> Philippe Martin wrote:
> 
>> I need to get the date and time under Windows and Linux but need the
>> information visible to the user (cannot find my words) not the sytem
>> information (ex: a PC setup on greenwich but the date/time displayed are
>> relative to some other place.
> 
> Something like this?
> 
 import datetime
 datetime.datetime.now()
> ...

Just so you (Phillipe) know, you are talking about "local time" vs. UTC.
 >>> import datetime
 >>> print datetime.datetime.now() # local
 2006-04-18 15:25:03.14
 >>> print datetime.datetime.utcnow() # zulu / utc / gmt
 2006-04-18 22:25:13.625000

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime question

2006-04-18 Thread Philippe Martin
Thanks, yes, I guess the question is ... what date/time is it looking at ?
and is it the same under various OSs ?


Philippe


Jorge Godoy wrote:

> Philippe Martin wrote:
> 
>> Hi,
>> 
>> I need to get the date and time under Windows and Linux but need the
>> information visible to the user (cannot find my words) not the sytem
>> information (ex: a PC setup on greenwich but the date/time displayed are
>> relative to some other place.
> 
> Something like this?
> 
 import datetime
 datetime.datetime.now()
> datetime.datetime(2006, 4, 18, 16, 19, 42, 159000)
 print datetime.datetime.now()
> 2006-04-18 16:19:45.245053
 dir(datetime.datetime.now())
> ['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__ge__',
> '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__',
> '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__',
> '__repr__', '__rsub__', '__setattr__', '__str__', '__sub__', 'astimezone',
> 'combine', 'ctime', 'date', 'day', 'dst', 'fromordinal', 'fromtimestamp',
> 'hour', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond',
> 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second',
> 'strftime', 'time', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo',
> 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple',
> 'weekday', 'year']
 
> 
> --
> Jorge Godoy  <[EMAIL PROTECTED]>
> 
> "Quidquid latine dictum sit, altum sonatur."
> - Qualquer coisa dita em latim soa profundo.
> - Anything said in Latin sounds smart.

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


Re: datetime question

2006-04-18 Thread Jorge Godoy
Philippe Martin wrote:

> Hi,
> 
> I need to get the date and time under Windows and Linux but need the
> information visible to the user (cannot find my words) not the sytem
> information (ex: a PC setup on greenwich but the date/time displayed are
> relative to some other place.

Something like this?

>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2006, 4, 18, 16, 19, 42, 159000)
>>> print datetime.datetime.now()
2006-04-18 16:19:45.245053
>>> dir(datetime.datetime.now())
['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__ge__',
'__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__',
'__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__',
'__rsub__', '__setattr__', '__str__', '__sub__', 'astimezone', 'combine',
'ctime', 'date', 'day', 'dst', 'fromordinal', 'fromtimestamp', 'hour',
'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond', 'min',
'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime',
'time', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname',
'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple', 'weekday',
'year']
>>> 

-- 
Jorge Godoy  <[EMAIL PROTECTED]>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
-- 
http://mail.python.org/mailman/listinfo/python-list