PHP Classes

TimeControl: Validate time values against filter definitions

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (8 months ago) RSS 2.0 feedNot enough user ratingsTotal: 564 All time: 5,420 This week: 660Up
Version License Categories
timecontrol 1.0GNU General Publi...Time and Date, Validation
Description 

Author

This class is meant to determine whether the current time matches one or more different date range validation filter rules.

Multiple filter rules may be added verify whether the current time matches the year, month, day, week, day of week, hour or minute.

Picture of Thomas Björk
  Performance   Level  
Name: Thomas Björk <contact>
Classes: 11 packages by
Country: Sweden Sweden
Age: 56
All time rank: 1581 in Sweden Sweden
Week rank: 164 Down2 in Sweden Sweden Down
Innovation award
Innovation award
Nominee: 3x

Details

Simple manual TimeControl is a simple class for validating time. It can be used in access control system to determine if a user can login or not depending on what time it is. License -------------------------------------------------------------------------------- * TimeControl is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * TimeControl is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with TimeControl; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Functions -------------------------------------------------------------------------------- Clean(); ============== Removes all filters. AddFilter($filter, $onlyNow); ============================= Adds a new filter. The filter is composed as follows: {action};{year};{month};{day};{start};{end} Action: 0 gives false and 1 gives true on a match Year: The year with four digits or "*" for any year Month: The number of the month or "*" for any month. It is possible to use "," to separate more than one month "1,2" means january and february. It is also possible to use "-" to indicate a span "1-4" means january through april. If month begins with "w:" then it indicated weeknumber instead, year will become obsolete and day will indicate day of week. Day: The numerical value of the date or "*" for any date. It is possible to use "," to separate more than one date "1,2" means "1" and "2". It is also possible to use "-" to indicate a span "1-4" means "1st" through "4th". If day begins with "w:" then it indicated day of week instead, year will become obsolete as well as month. The short abbreviation for weekdays (mon,tue,wed,thu,fri,sat,sun) will be replaced by its corresponding number for day of week. Please note that a 0 for day of week means monday and 6 means sunday. This results in a logical connection for normal workingdays (monday through friday) as 0 through 4 and weekends (saturday and sunday) as 5 and 6. Start: Time when event should start. Hours and minutes separated by a ":". A "*" indicates "00:00". If time is given then it must contain a valute for both hour and minute. End: Time when event should end. Hours and minutes separated by a ":". A "*" indicates "23:59". If time is given then it must contain a valute for both hour and minute. When validation is performed it matches ((current time >= start time) and (current time <= end time)) If $onlyNow is set to true then only filters valid at the registered time will be added. GetFilterArray(); ============================= Returns the filters added sofar as an array. This array can be used as an argument for SetFilterArray which means that it is possible to store the filterarray in a database and load it at an appropriate time. SetFilterArray($filter); ============================= Sets the internal filters. The filter supplied as an argument should be an result from GetFilterArray. Validate(); ============================= A call to Validate will go through all filters to check if there is a match to the current time. If a match is found that will render the result false the rest of the filters will not be checked. Validate can return false if a match for false is found. If one or more results is found that is a match for true then Validate will return true. If no match for either true or false is found then Validate will return 0. <?php include("timecontrol.php"); $tc = new TimeControl(); $tc->AddFilter('0;*;*;w:0-4;*;07:59', false); // Any monday through friday from // midnight through 07:59 $tc->AddFilter('0;*;*;w:0-4;18:00;*', false); // Any monday through friday from // 18:00 through midnight $tc->AddFilter('0;*;*;w:5-6;*;*', false); // Any saturday or sunday $tc->AddFilter('1;*;*;w:0-4;09:00;17:59', false); // Any monday through friday // from 09:00 through 17:59 $tc->AddFilter('0;*;w:22;mon-wed;*;*', false); // All day on monday through // wednesday in week 22 $result = $tc->Validate(); if($result == true) { // A match is found indicating true // This occurs on mondays through fridays between 09:00 and 17:59 (except for // week 22 on monday through wednesday) } elseif($result === false) { // A match is found indicating false } else { // No match is found // This can occur monday through friday between 08:00 and 08:59 (except for // week 22 on monday through wednesday) } ?>

  Files folder image Files (5)  
File Role Description
Accessible without login Plain text file LICENSE Data License file
Accessible without login Plain text file license.txt Lic. GPL License
Accessible without login Plain text file README.md Data Updated readme to markdown
Accessible without login Plain text file readme.txt Doc. Readme file
Plain text file timecontrol.php Class The main class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 80%
Total:564
This week:0
All time:5,420
This week:660Up
User Comments (1)
*_* lovely, worked for me
16 years ago (anodude)
70%StarStarStarStar