Jump to content

ToolsTimeFormat


Adam Kiss
 Share

Recommended Posts

TimeFormat for ProcessWire v1.0.3

This is a tiny ProcessWire Modules used for formatting times as 'X seconds ago', 'minutes ago'. It goes up to decades.

Important note: this module uses 'soft limit' for units. That means that it will show '8 days ago' for 8 days, but '1 week ago' for 9 days, for instance. This will be configurable in one of the later releases.

Usage

It's very simple. Load module, pass the timestamp to `format` function. Bam, done.



<?php
  $time_format = $modules->get('ToolsTimeFormat');
  $posted = $time_format->ago($page->created);


Links


Notes

  • v1.0.2 & v1.0.3 - bugfixing and module rename
 

  • Like 4
Link to comment
Share on other sites

Something that the forum software does is that it only limits it to seconds, minutes and hours ago, then in other places says "Today at X:XXam" and finally "Yesterday at X:XXam" so it would be nice to have those options and set a cut-off in a future version so that "if the date is before yesterday then just return the date formatted with date()" for example :)

The thing is, once you get past today and yesterday, you have to think about your use case and whether "11 months ago" is actually that descriptive. Not a criticism, just a note that when using this module you have to think about where you're going to use this and how accurate you want to be.

Link to comment
Share on other sites

Something that the forum software does is that it only limits it to seconds, minutes and hours ago, then in other places says "Today at X:XXam" and finally "Yesterday at X:XXam" so it would be nice to have those options and set a cut-off in a future version so that "if the date is before yesterday then just return the date formatted with date()" for example :)

The thing is, once you get past today and yesterday, you have to think about your use case and whether "11 months ago" is actually that descriptive. Not a criticism, just a note that when using this module you have to think about where you're going to use this and how accurate you want to be.

I hear ya.

  1. 11 months ago has place for blogs for one
  2. There are many things planned, namely:
    • limiting the level you go into (maybe you want something like 432 days and don't want it translated into 14 months)
    • other formats (today at XX:YY, for instance)
    • configurability of soft limits
      • simpler way to go to hard limits than defining precise soft limits

I just wanted this one out quickly, because I also planned to introduce new Modules group with it which I hope will catch on.

  • Like 1
Link to comment
Share on other sites

Can't install.

2013-01-12 23:03:28 admin pwprofile/processwire/module/ Parse Error syntax error, unexpected ')' (line 78 of /Applications/XAMPP/xamppfiles/htdocs/pwprofile/site/modules/ToolsTimeAgo.module)

Link to comment
Share on other sites

Translation doesn't work. Or am I missing something? 

  • ProcessLanguageTranslator: Found /site/modules/ToolsTimeAgo.module

  • ProcessLanguageTranslator: That file has no translatable phrases

Translation doesn't work for runtime variables as the string. And I thought the _() have to be on 1 line, but I could be wrong.

Link to comment
Share on other sites

Well, the strings should be prepared for translation, even though I haven't really played with translations before.

I use static (read: always the same) strings for translation, although there might be problem with them being passed through variables. Unfortunately, there can't be $this->() call in class variable definition. Would it help if I moved the those string definitions into init() function?

Any help here would be great!

Also, Soma, thanks for spotting all the errors :) I am personally happy with my fast shipping (for a change!), but these things happen, and another set of eyes is always welcome. So, thanks again! :)

Link to comment
Share on other sites

DateTime() takes a string argument when creating new object - it takes the very same arguments as strtotime() does. It's a natural date parser, so if you want to tell it that 'this number is a timestap', you have to prepend '@' before it.

That means, that you could theoretically do this:

  $tf = $modules->get('ToolsTimeFormat');
  echo $tf->ago('2012/12/24 18:00');

Edit: +bonus tiny english lesson :) 'learn' is a word you use when you gain information ('I'm learning'). When you give information, the verb is 'teaching' (e.g. "I am teaching you, you are learning from me"). Hope that helps. (as an absolute off-topic, if I ever make a mistake, you are absolutely free to correct me, so I can learn something new :))

  • Like 2
Link to comment
Share on other sites

Here is something for us all to learn. Martijn's mistake happened because the dutch word "leren" means learn and teach at the same time. Strange fact but true, courtesy of google translate :)

I suspected it could be something like this, because the word "lernen" in German means both learn and study, and I always found it funny when German people would say to me in English "leave me alone, i have to learn now".

Link to comment
Share on other sites

  • 7 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...