T(-) Countdown Proper Time Unit Calculation

string(10) "target is:" int(1721294882) string(14) "target is now:" string(16) "id-647c3cf8c2559" string(10) "target is:" int(1720085282) string(14) "target is now:" string(16) "id-647c3cf8c261f" string(10) "target is:" int(1719912482) string(14) "target is now:" string(16) "id-647c3cf8c26c6" string(10) "target is:" int(1719912482) string(14) "target is now:" string(16) "id-647c3cf8c2762" string(10) "target is:" int(1717493282) string(14) "target is now:" string(16) "id-647c3cf8c27f7" string(10) "target is:" int(1689758872) string(14) "target is now:" string(16) "id-647c3cf8c288b"

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"/]

Wk.
5
8
Tage
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"/]

Tage
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"/]

Wk.
5
6
Tage
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"/]

Wk.
5
6
Tage
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"/]

Tage
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"/]

Tage
4
5
Hours
0
0
Minutes
0
0
Seconds
0
0

T(-) Countdown Omitweeks Width Issue

string(10) "target is:" int(1690190872) string(14) "target is now:" string(16) "id-647c3cf8c368b" string(10) "target is:" int(1695374872) string(14) "target is now:" string(16) "id-647c3cf8c3737" string(10) "target is:" int(1695374872) string(14) "target is now:" string(16) "id-647c3cf8c37e6" string(10) "target is:" int(1690622872) string(14) "target is now:" string(16) "id-647c3cf8c3888" string(10) "target is:" int(1695634072) string(14) "target is now:" string(16) "id-647c3cf8c3918" string(10) "target is:" int(1695634072) string(14) "target is now:" string(16) "id-647c3cf8c39a8" string(10) "target is:" int(1690190872) string(14) "target is now:" string(16) "id-647c3cf8c3a3a" string(10) "target is:" int(1695374872) string(14) "target is now:" string(16) "id-647c3cf8c3ac8" string(10) "target is:" int(1695374872) string(14) "target is now:" string(16) "id-647c3cf8c3b52" string(10) "target is:" int(1690190872) string(14) "target is now:" string(16) "id-647c3cf8c3be2" string(10) "target is:" int(1695374872) string(14) "target is now:" string(16) "id-647c3cf8c3c6d" string(10) "target is:" int(1695374872) string(14) "target is now:" string(16) "id-647c3cf8c3cf9" string(10) "target is:" int(1690190872) string(14) "target is now:" string(16) "id-647c3cf8c3d87" string(10) "target is:" int(1695374872) string(14) "target is now:" string(16) "id-647c3cf8c3e27" string(10) "target is:" int(1695374872) string(14) "target is now:" string(16) "id-647c3cf8c3eb6" string(10) "target is:" int(1690190872) string(14) "target is now:" string(16) "id-647c3cf8c3f40" string(10) "target is:" int(1695374872) string(14) "target is now:" string(16) "id-647c3cf8c3fcd" string(10) "target is:" int(1695374872) string(14) "target is now:" string(16) "id-647c3cf8c4061" string(10) "target is:" int(1690190872) string(14) "target is now:" string(16) "id-647c3cf8c40ef"

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"/]

Tage
5
0
Hours
0
0
Minutes
0
0
Seconds
0
0

Tage
1
1
0
Hours
0
0
Minutes
0
0
Seconds
0
0

Wk.
1
5
Tage
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."/]

Tage
5
5
Hours
0
0
mins.
0
0
secs.
0
0

Tage
1
1
3
Hours
0
0
mins.
0
0
secs.
0
0

Wk.
1
6
Tage
0
1
Hours
0
0
mins.
0
0
secs.
0
0

sith

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

Tage
5
0
Hours
0
0
Minutes
0
0
Seconds
0
0

Tage
1
1
0
Hours
0
0
Minutes
0
0
Seconds
0
0

Wk.
1
5
Tage
0
5
Hours
0
0
Minutes
0
0
Seconds
0
0

carbonlite

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

Tage
5
0
Hours
0
0
Minutes
0
0
Seconds
0
0

Tage
1
1
0
Hours
0
0
Minutes
0
0
Seconds
0
0

Wk.
1
5
Tage
0
5
Hours
0
0
Minutes
0
0
Seconds
0
0

cloud-city

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

Tage
5
0
Hours
0
0
Minutes
0
0
Seconds
0
0

Tage
1
1
0
Hours
0
0
Minutes
0
0
Seconds
0
0

Wk.
1
5
Tage
0
5
Hours
0
0
Minutes
0
0
Seconds
0
0

Jedi

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

Tage
5
0
Hours
0
0
Minutes
0
0
Seconds
0
0

Tage
1
1
0
Hours
0
0
Minutes
0
0
Seconds
0
0

Wk.
1
5
Tage
0
5
Hours
0
0
Minutes
0
0
Seconds
0
0

circle

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

Tage
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

string(10) "target is:" int(1685870992) string(14) "target is now:" int(2819)

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.

Wk.
0
0
Tage
0
0
Hours
0
0
Minutes
0
2
Seconds
0
0

Details
this is where the details of the special are presented

Yearly Countdown Omit Weeks

string(10) "target is:" int(1700069700) string(14) "target is now:" int(1031) string(10) "target is:" int(4102444800) string(14) "target is now:" string(16) "id-647c3cf8cb8bb"

I am a normal recurring countdown

Wk.
2
3
Tage
0
3
Hours
0
8
Minutes
0
7
Seconds
0
8

Just look at me go


Now with smart AjaxTime

Wk.
3
9
9
5
Tage
0
4
Hours
1
4
Minutes
3
2
Seconds
0
8

It’s Business Time!

string(10) "target is:" int(1685870872) string(14) "target is now:" int(2753)

This is a test of the new T(-) Opening Hours add-on plugin for T(-) Countdown Control.
It will allow a countdown schedule to be defined by referencing a weekly opening schedule.

Wk.
0
0
Tage
0
0
Hours
0
0
Minutes
0
0
Seconds
0
0

T(-) Countdown Control – Separating the Time Units

string(10) "target is:" int(1685871000) string(14) "target is now:" string(7) "explode"
Fatal error: Uncaught TypeError: date(): Argument #2 ($timestamp) must be of type ?int, string given in /var/www/vhosts/spacedonkey.de/httpdocs/wp-content/plugins/t-countdown-control/t-countdown-control.php:445 Stack trace: #0 /var/www/vhosts/spacedonkey.de/httpdocs/wp-content/plugins/t-countdown-control/t-countdown-control.php(445): date() #1 /var/www/vhosts/spacedonkey.de/httpdocs/wp-includes/shortcodes.php(355): WP_TMinusCountdown->shortcode_digit() #2 [internal function]: do_shortcode_tag() #3 /var/www/vhosts/spacedonkey.de/httpdocs/wp-includes/shortcodes.php(227): preg_replace_callback() #4 /var/www/vhosts/spacedonkey.de/httpdocs/wp-includes/class-wp-hook.php(308): do_shortcode() #5 /var/www/vhosts/spacedonkey.de/httpdocs/wp-includes/plugin.php(205): WP_Hook->apply_filters() #6 /var/www/vhosts/spacedonkey.de/httpdocs/wp-includes/post-template.php(255): apply_filters() #7 /var/www/vhosts/spacedonkey.de/httpdocs/wp-content/themes/twentyseventeen/template-parts/post/content.php(58): the_content() #8 /var/www/vhosts/spacedonkey.de/httpdocs/wp-includes/template.php(785): require('...') #9 /var/www/vhosts/spacedonkey.de/httpdocs/wp-includes/template.php(718): load_template() #10 /var/www/vhosts/spacedonkey.de/httpdocs/wp-includes/general-template.php(204): locate_template() #11 /var/www/vhosts/spacedonkey.de/httpdocs/wp-content/themes/twentyseventeen/archive.php(43): get_template_part() #12 /var/www/vhosts/spacedonkey.de/httpdocs/wp-includes/template-loader.php(106): include('...') #13 /var/www/vhosts/spacedonkey.de/httpdocs/wp-blog-header.php(19): require_once('...') #14 /var/www/vhosts/spacedonkey.de/httpdocs/index.php(17): require('...') #15 {main} thrown in /var/www/vhosts/spacedonkey.de/httpdocs/wp-content/plugins/t-countdown-control/t-countdown-control.php on line 445