Deprecation warning: relative_created_at is going away in seven days

9 views
Skip to first unread message

Alex Payne

unread,
Mar 20, 2007, 3:44:24 PM3/20/07
to twitter-deve...@googlegroups.com
We've had a couple suggestions to do away with the
relative_created_at attribute that we include our API output.
Because the value is relative, it changes between requests and ruins
most caching strategies.

We will be removing relative_created_at in seven days (Tuesday, April
27th). Please change your code accordingly.

Thanks, and do let us know if we can do anything date/time related to
make parsing easier for you.

--
Alex Payne
Obvious
http://twitter.com/al3x


Austin Marshall

unread,
Mar 20, 2007, 4:42:34 PM3/20/07
to twitter-deve...@googlegroups.com
seven days? as in about a week? or about a month (Tuesday, April 27th)?

Alex Payne

unread,
Mar 20, 2007, 4:48:04 PM3/20/07
to twitter-deve...@googlegroups.com
Whoops. Seven days as in March 27th. My mistake.

--
Alex

mike

unread,
Mar 20, 2007, 5:18:03 PM3/20/07
to Twitter Development Talk
On Mar 20, 12:44 pm, Alex Payne <a...@al3x.net> wrote:
> We've had a couple suggestions to do away with the
> relative_created_at attribute that we include our API output.
> Because the value is relative, it changes between requests and ruins
> most caching strategies.

hi all,

i hacked up this javascript "relative time" generator yesterday while
putting together the tweetbar... it's based on the time distance code
in Rails.

feel free to use it however you see fit:

function relative_time(time_value) {
var parsed_date = (new Date).setTime(Date.parse(time_value));

var delta = parseInt(((new Date).getTime() -
parsed_date.getTime()) / 1000);

if(delta < 60) {
return 'less than a minute ago';
} else if(delta < 120) {
return 'about a minute ago';
} else if(delta < (45*60)) {
return (parseInt(delta / 60)).toString() + ' minutes ago';
} else if(delta < (90*60)) {
return 'about an hour ago';
} else if(delta < (24*60*60)) {
return 'about ' + (parseInt(delta / 3600)).toString() + '
hours ago';
} else if(delta < (48*60*60)) {
return '1 day ago';
} else {
return (parseInt(delta / 86400)).toString() + ' days ago';
}
}


::md

Rick Measham

unread,
Mar 20, 2007, 7:41:18 PM3/20/07
to twitter-deve...@googlegroups.com
mike wrote:
> i hacked up this javascript "relative time" generator yesterday while
> putting together the tweetbar... it's based on the time distance code
> in Rails.
>
> feel free to use it however you see fit:

Thanks mike .. that's excellent.

Below I've re-written the same logic in perl for those of us using perl.

Cheers!
Rick Measham

# This code uses DateTime as that's what I use.
use DateTime::Format::HTTP;

sub relative_time {
my $time_value = shift;

my $parsed_date =
DateTime::Format::HTTP->parse_datetime($time_value)->epoch;
my $now = DateTime->now()->epoch;

my $delta = $now - $parsed_date;

if($delta < 60) {


return 'less than a minute ago';

} elsif($delta < 120) {


return 'about a minute ago';

} elsif($delta < (45*60)) {
return int($delta / 60) . ' minutes ago';
} elsif($delta < (90*60)) {


return 'about an hour ago';

} elsif($delta < (24*60*60)) {
return 'about ' + int($delta / 3600) + '
hours ago';
} elsif($delta < (48*60*60)) {


return '1 day ago';
} else {

return int($delta / 86400) + ' days ago';
}
}

bear

unread,
Mar 20, 2007, 8:33:49 PM3/20/07
to Twitter Development Talk

On Mar 20, 7:41 pm, Rick Measham <r...@isite.net.au> wrote:
> mike wrote:
> > i hacked up this javascript "relative time" generator yesterday while
> > putting together the tweetbar... it's based on the time distance code
> > in Rails.
>
> > feel free to use it however you see fit:
>
> Thanks mike .. that's excellent.
>
> Below I've re-written the same logic in perl for those of us using perl.

and here it is in python :) -- the only thing I hacked in was to
remove the +0000 from the string as I believe the time is returned to
us as localtime. If it's not then switch localtime() with gmtime()
below :)


from time import strptime, mktime, localtime

_partialMinute = 45 * 60
_partialHour = 90 * 60
_fullDay = 24 * 60 * 60
_twoDays = _fullDay * 2

def relative_time(dateString):
"""
Take the created_at timestamp string and convert
it to a relative text expression
"""
date = dateString.replace(' +0000', '')
parsed = mktime(strptime(date, '%a %b %d %H:%M:%S %Y'))
now = mktime(localtime())
delta = now - parsed

if delta < 60:


return 'less than a minute ago'

elif delta < 120:


return 'about a minute ago'

elif delta < _partialMinute:
return '%d minutes ago' % (delta / 60)
elif delta < _partialHour:


return 'about an hour ago'

elif delta < _fullDay:
return 'about %d hours ago' % (delta / 3600)
elif delta < _twoDays:


return '1 day ago'
else:

return '%d days ago' % (delta / 86400)


print relative_time('Wed Mar 07 09:32:51 +0000 2007')
print relative_time('Tue Mar 20 20:08:00 +0000 2007')

Chris Messina

unread,
Mar 20, 2007, 8:40:10 PM3/20/07
to twitter-deve...@googlegroups.com
Any more, feel free to add them to the wiki:

https://twitter.pbwiki.com/RelativeTimeScripts

Chris


--
Chris Messina
Citizen Provocateur &
Open Source Ambassador-at-Large
Work: http://citizenagency.com
Blog: http://factoryjoe.com/blog
Cell: 412 225-1051
Skype: factoryjoe
This email is: [ ] bloggable [X] ask first [ ] private

bear

unread,
Mar 21, 2007, 2:09:55 AM3/21/07
to Twitter Development Talk
Great idea Chris!

I've just edited the Python version to include some basic tests.

Rick Measham

unread,
Mar 21, 2007, 2:21:57 AM3/21/07
to twitter-deve...@googlegroups.com
bear wrote:
> I've just edited the Python version to include some basic tests.

I don't read python too well, but looks good. The time for comparison is
a good idea .. I've added it to the other two examples we have there.

Cheers!
Rick Measham

Chris Messina

unread,
Mar 21, 2007, 2:25:42 AM3/21/07
to twitter-deve...@googlegroups.com
Nice! Keep it coming!

DeWitt Clinton

unread,
Mar 21, 2007, 4:09:23 PM3/21/07
to twitter-deve...@googlegroups.com
Hi all,

I updated the python-twitter library to automatically generate a value for relative_created_at value.  The change should be transparent for existing users of the library.

  http://code.google.com/p/python-twitter/

Also, I noticed that there are inconsistencies in the styles and formats people are using to generate the relative created at string.  Since I haven't found a well-defined set of rules, I made up some of my own.  When Twitter publishes something official then I will update the library to conform.

The new version is available in the subversion trunk, and I'd still love someone to try it out and let me know if I missed anything.  I'm holding off on a full release until I find out if there are any more API changes I should incorporate.

Thanks!

-DeWitt

Harakiro

unread,
Mar 25, 2007, 12:41:39 PM3/25/07
to Twitter Development Talk
I've written the logic for flash AS2.0 I tried adding to the wiki but
didnt have the password.

I've also broken the date conversion out into a seperate utility
function. Also changed elseif's to a switch just because im anal and
like the cleanliness of a switch =).
/**
* getDateFromString()
* @param str String - date in Thu Jul 8 12:48:23 GMT+0800 2004
format
* @return date - date in flash format
*/
function getDateFromString(str:String):Date
{
var m = {Jan:0, Feb:1, Mar:2, Apr:3, May:4, Jun:5, Jul:6, Aug:
7, Sep:8, Oct:9, Nov:10, Dec:11};
var dArr:Array = str.split(' ');
var tArr:Array = dArr[3].split(':');

return new Date(Date.UTC(dArr[5], m[dArr[1]], dArr[2], tArr[0],
tArr[1], tArr[2]));

//return new Date(Date.UTC(Number(dArr[5]), m[dArr[1]],
Number(dArr[2]), (Number(tArr[0])-Number(dArr[4].substring(3, 6))),
(Number(tArr[1])-Number(dArr[4].substring(6, 8))), Number(tArr[2])));
}
/**
* relative_time()
* @param time_value - date in Thu Jul 8 12:48:23 GMT+0800 2004
format
* @return string
*/
function relative_time(time_value):String
{
var parsed_date:Date = getDateFromString(time_value);
var relative_to:Date = new Date();
var dateDiff:Number = (relative_to.getTime() - parsed_date) / 1000;

switch(true){
case dateDiff < 60:
return 'about a minute ago';
break;
case dateDiff < 120:
return 'about a minute ago';
break;
case dateDiff < (45*60):
return int(dateDiff / 60) + ' minutes ago';
break;
case dateDiff < (90*60):
return 'about an hour ago';
break;
case dateDiff < (24*60*60):
return 'about ' + int(dateDiff / 3600) + ' hours ago';
break;
case dateDiff < (48*60*60):
return '1 day ago';
break;
default:
return int(dateDiff / 86400) + ' days ago';
break;
}
}


On Mar 21, 4:09 pm, "DeWitt Clinton" <dclin...@gmail.com> wrote:
> Hi all,
>
> I updated the python-twitter library to automatically generate a value for
> relative_created_at value. The change should be transparent for existing
> users of the library.
>
> http://code.google.com/p/python-twitter/
>
> Also, I noticed that there are inconsistencies in the styles and formats
> people are using to generate the relative created at string. Since I
> haven't found a well-defined set of rules, I made up some of my own. When
> Twitter publishes something official then I will update the library to
> conform.
>
> The new version is available in the subversion trunk, and I'd still love
> someone to try it out and let me know if I missed anything. I'm holding off
> on a full release until I find out if there are any more API changes I
> should incorporate.
>
> Thanks!
>
> -DeWitt
>

> > This email is: [ ] bloggable [X] ask first [ ] private- Hide quoted text -
>
> - Show quoted text -

Harakiro

unread,
Mar 25, 2007, 12:43:14 PM3/25/07
to Twitter Development Talk
Blah please note do not include that last commented return statment...
my bad.

> > - Show quoted text -- Hide quoted text -

Chris Messina

unread,
Mar 25, 2007, 2:37:44 PM3/25/07
to twitter-deve...@googlegroups.com

Harakiro

unread,
Mar 25, 2007, 3:17:13 PM3/25/07
to Twitter Development Talk
Aside from the tabbing on the vars in the first function for
formatting. looks good to me.

Thanks,

Jesse

On Mar 25, 2:37 pm, "Chris Messina" <chris.mess...@gmail.com> wrote:
> Can you proof this?
>
> http://twitter.pbwiki.com/RelativeTimeScripts#FlashActionscript
>
> Chris
>

Harakiro

unread,
Mar 25, 2007, 3:22:14 PM3/25/07
to Twitter Development Talk
Do i get a by Jesse Edwards on there too haha =)

Rick Measham

unread,
Mar 25, 2007, 5:17:13 PM3/25/07
to twitter-deve...@googlegroups.com
Harakiro wrote:
> I've written the logic for flash AS2.0 I tried adding to the wiki but
> didnt have the password.

The password is on the front page of the wiki.

> I've also broken the date conversion out into a seperate utility
> function.

I would have thought that as ActionScript is an ECMA script, the
Date.parse() would have worked. However from reading the docs, you
should be able to just give the HTTP format date (based on that in
RFC822) to the Date constructor:

var parsed_date:Date = new Date(time_value);

If not that, there appears to be a parseRFC822() method.

I also note that in your delta (dateDiff) algorithm you convert one Date
object into miliseconds but not the other. Of course it will still work
as applying a math function to a Date object will use the getTime()
result. But it would still be good to do one or the other to both dates.

Cheers!
Rick Measham


Harakiro

unread,
Mar 25, 2007, 9:24:17 PM3/25/07
to Twitter Development Talk
Rick thanks for pointing out the error on the dateDiff stuff it is
infact a typo. I was intending to use getTime for each.

In AS2 I dont belive the Date constructor can accept the a date in a
"string" format. It's pretty specific in its format. Also flash starts
its month array with 0 so you have to have that offset in the numbers
there as well. Perhapse they've added the RFC822 into the contstructor
in AS3, one can hope.

Date constructor in AS2
public Date([yearOrTimevalue:Number], [month:Number], [date:Number],
[hour:Number], [minute:Number], [second:Number], [millisecond:Number])

Also thanks ill find the password and fix the typo mentioned above.

Jesse

Harakiro

unread,
Mar 25, 2007, 9:33:10 PM3/25/07
to Twitter Development Talk
I must be doing something wrong. I've registered with pbwiki.

I try to join the wiki with twitter and sweety and it says it does not
exist.

I try to edit the page and enter the password on the page sweety and
it says this wiki does not use that password =(

Jesse

> > Rick Measham- Hide quoted text -

bear

unread,
Mar 26, 2007, 1:41:06 AM3/26/07
to Twitter Development Talk
I actually think the password on the page is wrong - I looked in the
page history and see that someone has changed the first letter

Probably need to get Mr.Messina to look at that

DeWitt Clinton

unread,
Mar 26, 2007, 10:32:49 AM3/26/07
to twitter-deve...@googlegroups.com
Hi,

Is there any update regarding official documentation on the upcoming API changes?  I'd like to push out version 0.2 of the python library, and the first release of a parallel Java library that I wrote, but I'm reluctant to do so until I know for sure what is changing in the API.

Since Alex mentioned that at the very least, relative_created_at is going away tomorrow (the 27th) this would presumably need to be done today.

Thanks!

-DeWitt

Alex Payne

unread,
Mar 26, 2007, 10:40:09 AM3/26/07
to twitter-deve...@googlegroups.com
DeWitt,

Other than the deprecation of relative_created_at, there's nothing in
the API changes that's going to negatively impact existing
applications. Everything that's been added lately is all convenience
methods. I still intend to put up official docs. I'll try to knock
those out today.

--
Alex

DeWitt Clinton

unread,
Mar 26, 2007, 10:46:41 AM3/26/07
to twitter-deve...@googlegroups.com
Great!  Thanks for the quick feedback, Alex!

I'm going to go ahead and push out 0.2 of the python library this morning, and I'll do a 0.3 if there are convenience methods that should be added to the library to mirror the API itself.

-DeWitt

DeWitt Clinton

unread,
Mar 26, 2007, 11:52:17 AM3/26/07
to twitter-deve...@googlegroups.com
Here it is -- python-twitter 0.2 -- reflecting, to the best of my knowledge, the latest API changes:

  http://code.google.com/p/python-twitter/

And please ping me off-list if you're interested in testing out java-twitter before I release it.  I should have something ready to download shortly.

-DeWitt

weiran

unread,
Apr 2, 2007, 3:36:01 PM4/2/07
to Twitter Development Talk
I've just added my C# implementation to the wiki.

One problem I'm having is that my relative date I have to compare it
against (my system clock) isn't the same as the one used on the site.
For example when I make an update at 9PM, it appears on the site as
8PM, so it's always an hour out.

This could be due to the fact that us in the UK have recently had our
daylight saving, switching to GMT+1 now. Is there anyway for Twitter
to know that we're now in BST (British Summer time) instead of GMT?

> This email is: [ ] bloggable [X] ask first [ ] private- Hide quoted text -

Blaine Cook

unread,
Apr 2, 2007, 3:56:25 PM4/2/07
to twitter-deve...@googlegroups.com
We'll always provide our timestamps in UTC; you should convert that into whatever timezone is appropriate for your users.

cheers!

Blaine
It's Obvious - http://twitter.com/blaine

weiran

unread,
Apr 3, 2007, 4:50:53 AM4/3/07
to Twitter Development Talk
Ah I didn't realise this, thanks!

On Apr 2, 8:56 pm, "Blaine Cook" <rom...@gmail.com> wrote:
> We'll always provide our timestamps in UTC; you should convert that into
> whatever timezone is appropriate for your users.
>
> cheers!
>
> Blaine
> It's Obvious -http://twitter.com/blaine
>

Reply all
Reply to author
Forward
0 new messages