Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-11-26 00:08:14

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

thg_if_time - output data depending the time of day

What is this plugin for?

This plugin will return true part of condition, if current server time is inside of set period.

Remember – this plugin works with time in 24h format!

Downloads

  1. Download as file
  2. Mirror file download
  3. Use copy-paste

Attributes

Attribute Default value Description
debug 0 Output some debug info in the top of the page
delim : The delimiter betwean hours and minutes (hours[*:*]minutes)
time_start 00:00 The start of time period
time_end 23:59 The end of time period
time_now server time You can set any time as current to check how plugin will work, remember to use right delim
hours_offset 0 Offset in hours from server time

Examples

Here are some exaples to look what plugin can do.

Example 1

<txp:thg_if_time debug="1" time_start="00:00" time_end="01:15" hours_offset="-1">
  <txp:title />
<txp:else />
  <txp:site_name />
</txp:thg_if_time>

This code will output the title of current article, if current server time minus one hour is between 00:00 and 01:15. Beside this, you will se in the top of the page some debug info, like this:

Time is OK
hours_start : minutes_start – 00 : 00
hours_end : minutes_end – 01 : 15
hours_now : minutes_now – 1 : 09

Example 2

<txp:thg_if_time time_start="06 00" time_end="12 00" hours_offset="+2" delim=" ">
  <p>Good morning, visitor!</p>
<txp:else />
  <p>Good day, visitor!</p>
</txp:thg_if_time>

This code will greet visitor with good morning, if current server time plus 2 hours is between 06 00 and 12 00. If time doesn’t match, general greeting will appear. Also, in this example hours and minutes are seaprated by space (” “).

Example 3

<txp:thg_if_time time_start="22-00" time_end="23-00" time_now="22-26" delim="-">
  <p>Now is evening...</p>
<txp:else />
  <p>This text will not appear!</p>
</txp:thg_if_time>

Here manual setting of current time is used. else part of condition will not appear without regard to current server time. You can use this attr with attr debug to explore how this plugin works. Notice, that all times are set using custom delim.

Credits


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#2 2008-11-26 03:50:41

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: thg_if_time - output data depending the time of day

Nice! I’ll check this out immediately.

Offline

#3 2008-11-26 04:28:12

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: thg_if_time - output data depending the time of day

Works nicely under RC1 for 4.0.7.

Offline

#4 2008-11-26 09:03:35

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: thg_if_time - output data depending the time of day

rsilletti wrote:

Works nicely under RC1 for 4.0.7.

Glad to hear that :)


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

Board footer

Powered by FluxBB