So, what does Time::Moment::Epoch do?

It seems everything has its own idea of what a timestamp is. For example, I use Firefox most of the time. It keeps track of all kinds of things that I do. If I look in its places database

$ sqlite3 ~/.mozilla/firefox/xjici1nz.default/places.sqlite
sqlite> .tables
moz_anno_attributes  moz_favicons         moz_items_annos    
moz_annos            moz_historyvisits    moz_keywords       
moz_bookmarks        moz_hosts            moz_places         
moz_bookmarks_roots  moz_inputhistory   
sqlite> .headers on
sqlite> select * from moz_places;

I can see lots of places I've visited.

sqlite> select url, last_visit_date from moz_places limit 3;

One column is called "last_visit_date," but it doesn't look like a date; it's just a big number. Apparently, I visited www.ubuntu.com at 1461414650785039. Maybe it's a Unix date.

$ date -d @1461414650785039
Wed Sep 19 21:57:19 EST 46312356

Nope, that's some time after the Sun has exploded. What does it mean? Well, it turns out that Mozilla time is the same as Unix time, except it's measured in microseconds instead of seconds. With this module, we can convert that database entry into a standard datetime

$ perl -MTime::Moment::Epoch -E 'say Time::Moment::Epoch::mozilla("1461414650785039")'

So apparently I visited on April 23rd of this year, not some time in the distant future.

Sometimes I use Chromium. It keeps track of all kinds of things that I do too. If I look in its History database

$ sqlite3 ~/.config/chromium/Default/History
sqlite> .tables
downloads             meta                  urls                
downloads_url_chains  segment_usage         visit_source        
keyword_search_terms  segments              visits
sqlite> .headers on
sqlite> select * from urls;
sqlite> select url, last_visit_time from urls limit 3;

I see I last visited this website at 13106714670814172. When was that?

$ date -d @13106714670814172
Mon Nov 20 13:09:32 EST 415337223

Again, some crazy time in the future?

$ perl -MTime::Moment::Epoch -E 'say Time::Moment::Epoch::chrome("13106714670814172")'

No, it was just a little while ago. Chromium measures time in microseconds also, but instead of starting at 1970, it starts at 1601. But you don't have to remember that because Time::Moment::Epoch does.

Lots of times!

Firefox and Chromium times are just two examples. This module knows a bunch more (apfs, chrome, cocoa, dos, google_calendar, icq, java, mozilla, ole, symbian, unix, uuid_v1, windows_date, windows_file). If you know any others, please let me know!

Related projects

There are similar modules written in other languages:

Pull requests welcome!