Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 28th, 2006, 2:37 PM   #11
Dietrich
Professional Programmer
 
Dietrich's Avatar
 
Join Date: Feb 2005
Posts: 434
Rep Power: 4 Dietrich is on a distinguished road
Thumbs up

Quote:
Originally Posted by Arevos
But %e is subtly different from %d. %d creates "01", whilst %e creates " 1".
Thanks a lot,
in a few days I would have seen this. Now I have to add some string processing to remove the leading zero.

Arevos, you are a genius!
__________________
I looked it up on the Intergnats!
Dietrich is offline   Reply With Quote
Old Jan 29th, 2006, 9:08 AM   #12
Steveire
Newbie
 
Join Date: Jan 2006
Posts: 13
Rep Power: 0 Steveire is on a distinguished road
Bingo. Thanks very.
Steveire is offline   Reply With Quote
Old Mar 7th, 2006, 8:02 PM   #13
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,076
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
I was wondering if there was an easier way to do the following:

from time import ctime, mktime, time

def ctime_to_epoch(ctime):
    x1 = ctime.split(' ')
    x2 = x1[3].split(':')
    localtime = (int(x1[-1]),
                 {"Jan":1,"Feb":2,"Mar":3,"Apr":4,
                  "May":5,"Jun":6,"Jul":7,"Aug":8,
                  "Sep":9,"Oct":10,"Nov":11,"Dec":12}[x1[1]],
                 int(x1[2]),int(x2[0]),int(x2[1]),int(x2[2]),0,0,0)
    return mktime(localtime)

ctime = ctime()
time = time()

print ctime_to_epoch(ctime)
print time

Converting a ctime literal back to seconds since epoch. I need to take forum post times and determine which posts are new by converting post times to epoch and comparing it to the epoch of his/her last visit.
Sane is offline   Reply With Quote
Old Mar 7th, 2006, 11:57 PM   #14
hydroxide
Programmer
 
Join Date: Apr 2005
Posts: 73
Rep Power: 4 hydroxide is on a distinguished road
Quote:
Originally Posted by Sane
I was wondering if there was an easier way to do the following:
import time

def timestr_to_epoch(timestr):
    localtime = time.strptime(timestr, "%a %b %d %H:%M:%S %Y")
    return time.mktime(localtime)

print timestr_to_epoch(time.ctime())
print time.time()
--OH.
hydroxide is offline   Reply With Quote
Old Mar 8th, 2006, 4:26 PM   #15
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,076
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Thanks. I wonder which is faster though.
Sane is offline   Reply With Quote
Old Mar 8th, 2006, 7:49 PM   #16
hydroxide
Programmer
 
Join Date: Apr 2005
Posts: 73
Rep Power: 4 hydroxide is on a distinguished road
Quote:
Originally Posted by Sane
Thanks. I wonder which is faster though.
Oh yours is about 4 times faster, but mine is easier to write, easier to maintain, easier to modify, easier to verify, easier to read, and easier to understand, so it's better*
import this
--OH.
*(If you have to process millions of dates in one go, and must have the speed, then yes, a hand-rolled problem-specific solution such as yours may be necessary. If you don't, the fraction of a second advantage is outweighed by the other factors)
hydroxide is offline   Reply With Quote
Old Mar 9th, 2006, 7:39 AM   #17
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,076
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Well not necessary "millions", but every forum they visit, every topic must have its last post's date converted to epoch to be compared with the user's last visit.

I had to do it awkwardly like this, because I forgot to incorporate new posts in to my forums when I was first programming them. But adding this in didn't change the speed of the forums noticably at all.
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:44 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC