We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Count-up & Countdown

Development and Programming

Arun S.'s avatar
Arun S.
792 posts
17 years ago
Arun S.'s avatar Arun S.

Hello everyone,

I just expanded on Steve Sharpe’s Timesince plugin to include some additional functionality.

This plugin maintains the functionality that is in Steve’s plugin and expands to include future dates. I needed something to show how much time remained until certain dates for an events page so this works great for that.

By default, it gives the following output (depending on how much time there since/until the date):

Dates that have passed: 25 minutes ago 2 hours, 1 minute ago 6 days, 8 hours ago 3 months, 11 days ago 2 years, 3 months ago

Dates to come: 25 minutes 2 hours, 1 minute 6 days, 8 hours 3 months, 11 days 2 years, 3 months

You can use it in any entry or comment template. The basic syntax is this:

{exp:count_time:standard} {entry_date} or {comment_date} {/exp:count_time:standard}</code></pre>

Additionally, there are two optional parameters that can be passed to the function. (1) seperator - The “seperator” parameter controls the character which appears between each unit. This is set to be a comma by default. (2) ending - the “ending” paramter controls what appears at the end of the date. This is set to be ago by default for dates that have passed and blank for dates to come.

For example,

{exp:count_time:standard seperator="and" ending="have elapsed."}
{entry_date}  or  {comment_date}
{/exp:count_time:standard}

The above would yield: 2 hours and 1 minute have elapsed.

Lastly, there are seven other calls you can make within the {exp:count_time} tag to determine the output.

{exp:count_time:standard} outputs a two unit string (2 Months, 5 Days)

The below only output in one unit. They also take the optional ending paramater. The default is ago for past events and nothing for future events.

{exp:count_time:years} –> 1 year (ago) {exp:count_time:months} –> 12 months (ago) {exp:count_time:weeks} –> 52 weeks (ago) {exp:count_time:days} –> 365 days (ago) {exp:count_time:hours} –> 8,760 hours (ago) {exp:count_time:minutes} –> 525,600 minutes (ago) {exp:count_time:seconds} –> 31,536,000 seconds (ago)

Files are attached 😊

EDIT: Updated with Mark Bowen’s suggestion (see below).

EDIT: Added language file

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Looks like a really great addition, well done.

One of my pet peeves though is when you have something like 1 years ago. Would it be possible in singular cases such as that to get it saying 1 year ago? 😉

Just a very very small thing though. I’m sure a lot of people will find this really useful so well done.

Best wishes,

Mark

       
Cocoaholic's avatar
Cocoaholic
445 posts
17 years ago
Cocoaholic's avatar Cocoaholic

Just what I was looking for.

Cheers!

       
Arun S.'s avatar
Arun S.
792 posts
17 years ago
Arun S.'s avatar Arun S.
Hiya, Looks like a really great addition, well done. One of my pet peeves though is when you have something like 1 years ago. Would it be possible in singular cases such as that to get it saying 1 year ago? 😉 Just a very very small thing though. I’m sure a lot of people will find this really useful so well done. Best wishes, Mark

I totally agree with you. That’s one of my pet peeves too actually. I noticed that late last night as I was about to go to sleep and didn’t have the energy to fix it.

Now, if the value is 1, the unit will in the singular form (year, month, day, etc…).

Attached is a new version.

       
Cocoaholic's avatar
Cocoaholic
445 posts
17 years ago
Cocoaholic's avatar Cocoaholic

Any chance you could make this plugin use a language file so it can be localized? :coolsmirk:

Just keeping you busy.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Sorry I hope it didn’t come across nasty when I said it was one of my pet peeves? Wasn’t meant to. Thanks for updating it, very nice indeed.

Best wishes,

Mark

       
Arun S.'s avatar
Arun S.
792 posts
17 years ago
Arun S.'s avatar Arun S.
Any chance you could make this plugin use a language file so it can be localized? :coolsmirk:

Ummm, sure why not. Updated version attached, with language files.

Hiya, Sorry I hope it didn’t come across nasty when I said it was one of my pet peeves? Wasn’t meant to. Thanks for updating it, very nice indeed.

Oh, don’t be silly. I wasn’t offended at all. You were right, it’s the details that count.

Any other suggestions/criticisms are welcome. I only started teaching myself PHP a couple months ago and just picked up EE last week, so I’m sure there is probably a lot of room for improvement in my coding.

       
Cocoaholic's avatar
Cocoaholic
445 posts
17 years ago
Cocoaholic's avatar Cocoaholic

Excellent service!

Hmm, what else can we request… 😉

Thanks for a great add-on.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Yes… What else can we request!! 😉

Just joking. You have made a great addition here so thanks for all the great work.

Best wishes,

Mark

       
Ryan M.'s avatar
Ryan M.
1,511 posts
17 years ago
Ryan M.'s avatar Ryan M.

Hmm, I can use this to get some nasty PHP off of a template I’m working on. Thanks for this. One thing I might suggest has nothing to do with the plugin itself…but how it’s presented for download in a thread. This isn’t directed towards you…but to everyone, sort of, and I might make a more general post about it in another thread.

I REALLY like it when you know you can ALWAYS go to the first post in a thread to get the latest version. Sometimes threads get up to 11+ pages and if the latest version isn’t in the first thread (a convention I know Mark Huot and I use) you’re always wondering if the latest one might be on page 2…or 4…or 28… Looking back, I see that you DO have 1.1.0 in the top thread as well…my bad. But I’ll leave all this here for when some new plugin-writing person comes along.

I was also going to suggest the convention of beginning your post title with “Plugin:”, but I see you’ve already done that!

Anyway, thanks again for this!

       
Oxygen Smith's avatar
Oxygen Smith
120 posts
17 years ago
Oxygen Smith's avatar Oxygen Smith

Oh dear– I can think of a feature request. Sorry.

Although I think this would be expected behaviour, when you set it up as “days until” the entry, once the entry is passed, it starts counting upwards again.

So 3 days before May Day 2008 (May 1), we can get it to say “3 days until May Day 2008!” Using the same code, on May Day 2008, it will say “1 day until May Day 2008!” (a little odd) Using the same code, 6 days after May Day 2008, it will say “6 days until May Day 2008!”

It would be sweet if there was a way of making {exp:count_time:days} display a special message when the countdown is “zero days until” (such as ‘It’s May Day 2008!’)

…and maybe another special message if ‘after’ (ie. the days until would be negative): ‘May Day 2008 has passed.’?

Not sure how this would be done… maybe it would have to have a parameter that would make it “aware” it is counting “time until” or “time since”?

Just trying to use this in place of a Javascript countdown script (for a group who runs a May Day website, if you couldn’t tell) 😉

I’m trying to set it up so that they can re-set the countdown via a “countdown” entry, and Javascript behind the scenes wouldn’t have to be adjusted.

Thanks! This is a pretty sweet plug-in!

R o B

       
Arun S.'s avatar
Arun S.
792 posts
17 years ago
Arun S.'s avatar Arun S.

Hmm…doesn’t the current version do that? Oops. I actually realized this a while ago and changed it. I guess I forgot to upload the new version. Sorry :-p.

I don’t have it available right now. I try to get it up later today or tomorrow.

       
gridonic's avatar
gridonic
231 posts
17 years ago
gridonic's avatar gridonic

Hi

I’ve recently discovered a bug in your plugin. For a more detailed description and how we tracked it down (Lisa and Me), please have a look at:

http://ellislab.com/forums/viewthread/78616

Summary: the plugin somehow changes the headers sent in the 404 page. You should be able to replicate it easily, pull some weblog entries in your 404 template and add this:

{exp:count_time:standard seperator="and" ending="ago."}{entry_date}{/exp:count_time:standard}

It will change the “404” headers to “200” and break a proper “page not found” page.

Haven’t had time to go through your code, maybe you’ll take a minute.

       
Arun S.'s avatar
Arun S.
792 posts
17 years ago
Arun S.'s avatar Arun S.

Thanks. I have no idea why that would be happening. I didn’t intentionally do anything with headers. Will post with an update in a while.

       
gridonic's avatar
gridonic
231 posts
17 years ago
gridonic's avatar gridonic

Yes, seems strange to mee to, i quickly went through your code and did not find any explicit header changement.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.