T(-) Countdown Proper Time Unit Calculation

we should only have to calculate year, month and week time units once, as they will likely change only one time per viewing. Even so, we will need to properly calculate the amount of days, weeks and months remain, depending on how many time units are currently being displayed. We use a test of +410 days and 10 seconds from now to test how the change over works for the larger time units.

Test 1 – Showing Everything

This test should show everything: Years, Months, Weeks, Days… and the rest.
[tminus t="+410 days +10 sec" style="TIE-fighter"/]

weeks
5
8
days
0
4
hours
0
0
minutes
0
0
seconds
1
0

Test 2 – No Weeks

This test should show everything: Years, Months, Weeks, Days… and the rest.
[tminus t="+396 days +10 sec" omitweeks="true" style="TIE-fighter"/]

days
3
9
6
hours
0
0
minutes
0
0
seconds
1
0

Test 3 – No Months

This test should show everything: Years, Months, Weeks, Days… and the rest.
[tminus t="+394 days +10 sec" omitmonths="true" style="TIE-fighter"/]

weeks
5
6
days
0
2
hours
0
0
minutes
0
0
seconds
1
0

Test 4 – No Months or Years

This test should show everything: Years, Months, Weeks, Days… and the rest.
[tminus t="+394 days +10 sec" omitmonths="true" omityears="true" style="TIE-fighter"/]

weeks
5
6
days
0
2
hours
0
0
minutes
0
0
seconds
1
0

Test 5 – No Months or Weeks

This test should show: Years and days.
[tminus t="+366 days +10 sec" omitmonths="true" omitweeks="true" style="TIE-fighter"/]

days
3
6
6
hours
0
0
minutes
0
0
seconds
1
0

Test 6 – Days Only

This test should show only days:
[tminus t="+45 days" omityears="true" omitmonths="true" omitweeks="true"/]

days
4
5
hours
0
0
minutes
0
0
seconds
0
0

T(-) Countdown Omitweeks Width Issue

This post investigates issues with the width of a countdown that has the weeks omitted. Since the width should auto-adjust based on the displayed time units.

c-3po

We’ll start with the c-3po style based on this issue on the WordPress Forums.

[tminus t="2018-04-11" omitweeks="true" style="c-3po"/]

days
5
0
hours
0
0
minutes
0
0
seconds
0
0

days
1
1
0
hours
0
0
minutes
0
0
seconds
0
0

weeks
1
5
days
0
5
hours
0
0
minutes
0
0
seconds
0
0

[tminus t="2018-04-11" omitweeks="true" style="c-3po-mini" minutes="mins." seconds="secs."/]

days
5
5
hours
0
0
mins.
0
0
secs.
0
0

days
1
1
3
hours
0
0
mins.
0
0
secs.
0
0

weeks
1
6
days
0
1
hours
0
0
mins.
0
0
secs.
0
0

sith

[tminus t="2018-04-11" omitweeks="true" style="sith"/]

days
5
0
hours
0
0
minutes
0
0
seconds
0
0

days
1
1
0
hours
0
0
minutes
0
0
seconds
0
0

weeks
1
5
days
0
5
hours
0
0
minutes
0
0
seconds
0
0

carbonlite

[tminus t="2018-04-11" omitweeks="true" style="carbonlite"/]

days
5
0
hours
0
0
minutes
0
0
seconds
0
0

days
1
1
0
hours
0
0
minutes
0
0
seconds
0
0

weeks
1
5
days
0
5
hours
0
0
minutes
0
0
seconds
0
0

cloud-city

[tminus t="2018-04-11" omitweeks="true" style="cloud-city"/]

days
5
0
hours
0
0
minutes
0
0
seconds
0
0

days
1
1
0
hours
0
0
minutes
0
0
seconds
0
0

weeks
1
5
days
0
5
hours
0
0
minutes
0
0
seconds
0
0

Jedi

[tminus t="2018-04-11" omitweeks="true"/]

days
5
0
hours
0
0
minutes
0
0
seconds
0
0

days
1
1
0
hours
0
0
minutes
0
0
seconds
0
0

weeks
1
5
days
0
5
hours
0
0
minutes
0
0
seconds
0
0

circle

[tminus t="2018-04-11" style="circle" omitweeks="true"/]

days
5
0
hours
0
0
minutes
0
0
seconds
0
0

Tidal Chart for Leith

How to caculate a countdown to the next high and low tide.

First, there is a nice plugin called Tides Today UK and Ireland tide times that allows tidal charts to be displayed using a Sidebar Widget or a shortcode. For example:

[[tide_times days=1 title="Tide times for Leith" location="leith"]These are today's tides for Leith[/tide_times]]

That outputs a tidy forecast like so:

[tide_times days=1 title=”Tide times for Leith” location=”leith”]These are today’s tides for Leith[/tide_times]

The shortcode references the authors own web-service api that returns a JSON encoded dataset. Here is the dataset for Leith. However, the plugin author clearly (if not threateningly) states:

You may not use the data provided by the API for anything other than displaying tide information on your website by the
means provided by this plugin.

…Failure to comply with any of the conditions outlined here or as outlined in the Tides Today Terms and conditions will result in legal action being taken.

In the words of Al Swearengen:

Not a tone to get a deal done.

Even though the datasource provide is from the UK Hydrographic Office:

All data is provided by the UK Hydrographic Office and is provided under license. Crown Copyright 2016.

https://tides.today/about/

So we might need to find our own, tax-funded, public, non-threatening api to get our tidal info from, for example:
https://data.gov.uk/publisher/united-kingdom-hydrographic-office
https://www.tidetimes.org.uk/leith-tide-times
even better:
RSS: https://www.tidetimes.org.uk/leith-tide-times.rss
Twitter: https://twitter.com/LeithTideTimes
http://www.ntslf.org/
https://tidesandcurrents.noaa.gov/api/
https://www.worldtides.info/
https://www.wunderground.com/

The NOAA api looks quite promising… but it’s only for North America. So we move on to Worworldtides api which provides 1000 free calls per month. So far that is a winner. Now let’s take a look at The National Tidal and Sea Level Facility. It seems it only serves the UK and Ireland. Here is Leith.

Leith
http://www.ukho.gov.uk/easytide/EasyTide/ShowPrediction.aspx?PortID=0225&PredictionLength=1

Holy Island
http://www.ukho.gov.uk/easytide/EasyTide/ShowPrediction.aspx?PortID=0208&PredictionLength=1

Limited Time Offer Demo

This is an example of how a limited time offer would work in conjunction with content in a collapse-o-matic expand element.

This demo uses T(-) Countdown Control with a cookie that tracks when the offer expires for each unique visitor. Once the countdown reaches zero, T(-) Countdown Events will remove any special offer items.

For this demo, we’ll set the special timer for just two minutes. The offer will then be removed for 24 hours, and then after the 24 hours are past, the offer will reset.

Details
this is where the details of the special are presented

T(-) Countdown Control – Separating the Time Units

Normally a countdown groups the units of time (weeks, days, hours, minutes and seconds) into a single countdown unit. But what if you wanted to break out these units and have them displayed on different parts of the page?

Step One. We will need to add a new attribute that tells the countdown NOT to display any of the digits. This way all the countdown scripts and details are still loaded, but the countdown is not displayed. Something like:

[tminus cid="123" hidden="true" style="cloud-city"/]

Step Two. A new shortcode will need to be created for displaying the time unit. We will need to know the countdown id (cid) the time unit to be displayed, and the style to be used, if other than the default style set up on the plugin settings. If a custom style is used it must be defined in both the countdown and the units like so:

[[tminus_digit cid="123" unit="hours" style="cloud-city"/]]

The final set will be to modify the countdown script to locate the time units, even if they are not wrapped in a countdown dashboard.

Let’s get started.

Here is a hidden countdown:

Now we add all the digits, starting with weeks:
[tminus_digit cid=”281″ id=”explode” unit=”weeks” style=”cloud-city” omitweeks=”false”/]

Days:
[tminus_digit cid=”281″ id=”explode” unit=”days” style=”cloud-city”/]

Hours:
[tminus_digit cid=”281″ id=”explode” unit=”hours” style=”cloud-city”/]

Minutes:
[tminus_digit cid=”281″ id=”explode” unit=”minutes” style=”cloud-city”/]

Seconds:
[tminus_digit cid=”281″ id=”explode” unit=”seconds” style=”cloud-city”/]