Morton Fox (mortonfox) wrote,
Morton Fox

Of phones and time


There must be a sales drive going on at Sprint now because yesterday morning, I got a phone call from a rather insistent Sprint sales representative. Of course, I wasn't going to upgrade my calling plan since I hardly use any minutes in the first place, and I wasn't going to upgrade my phone either because I just got a replacement Razr V3m in good working condition. However, that sales call did get me to at least take a look at Sprint's current selection of phones.

The LG Rumor is one that I might get for the slide-out keyboard. The dealbreaker is it doesn't support EV-DO! If I have Power Vision, why get a phone that can't use it? The only other Sprint offering that I thought was interesting was the HTC Touch, a touchscreen Windows Mobile smartphone. However, the reviews are lukewarm. The rest of the phones are either less capable than the Razr V3m (so why buy those when I can always get a V3m on eBay?) or too high-end for me to be bringing out into the woods. Bottom line is I ought to wait and see. Maybe they'll have more choices next year when my contract is up for renewal.

Did more work on TwitVim. Yesterday, I added support for highlighting #hashtags and jumping to the Twitter Search for those hashtags. That should make hashtags easier to follow in TwitVim, not that many people on my friends timeline use those.

Then today, I rewrote TwitVim's date/time reformatting code in pure Vim script. It used to be written in Perl, so only those who ran Vim with the if_perl extension compiled in would see those. Everyone else saw raw Twitter API timestamps, which are in GMT instead of local time and aren't very pretty, besides. Now that this piece of code is in Vim script, everyone will get the new timestamps. Why was it in Perl earlier? Because Vim has barely anything by way of date/time handling functions so I was using Perl's library functions for that. Once I had the Julian date formula though, it was easy to write a Vim function to convert date strings to UNIX time values. (i.e. seconds since Jan 1, 1970) Of course, it was even easier to peek into the Perl library to see how they implemented timegm(). Wish I'd thought of that earlier.

So here's what timegm() looks like in Vim script:
" Convert date to Julian date.
function! s:julian(year, mon, mday)
    let month = (a:mon - 1 + 10) % 12
    let year = a:year - month / 10
    return a:mday + 365 * year + year / 4 - year / 100 + year / 400 + ((month * 306) + 5) / 10

" Calculate number of days since UNIX Epoch.
function! s:daygm(year, mon, mday)
    return s:julian(a:year, a:mon, a:mday) - s:julian(1970, 1, 1)

" Convert date/time to UNIX time. (seconds since Epoch)
function! s:timegm(year, mon, mday, hour, min, sec)
    return a:sec + a:min * 60 + a:hour * 60 * 60 + s:daygm(a:year, a:mon, a:mday) * 60 * 60 * 24
Certainly not a long or difficult piece of code once the details have been hammered out.
Tags: hashtags, phone, sprint, time, timegm, twitvim, vim
  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded