Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

setting limitations for users based on time

by Coarlx (Initiate)
on Jan 02, 2015 at 09:19 UTC ( #1111968=perlquestion: print w/replies, xml ) Need Help??

Coarlx has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a time clock, but the problem i am having is that i want to allow the user to clock in 5 mins before the hour begins.I honestly have no idea how to do this i have been trying all the different modules i just may not be doing it in the correct manner.

  • Comment on setting limitations for users based on time

Replies are listed 'Best First'.
Re: setting limitations for users based on time
by marto (Archbishop) on Jan 02, 2015 at 09:52 UTC

    Welcome, please read and understand How do I post a question effectively?, it's better if you show people what you tried and explain how it failed. Below is an example of what I think you're looking for.

    #!/usr/bin/perl use strict; use warnings; use DateTime; my $dt = DateTime->now; my $minute = $dt->minute; if ( $minute >= 55 ){ print "It's within 5 minutes of an hour\n"; }else{ print "No clock in for you!\n"; }
Re: setting limitations for users based on time
by Anonymous Monk on Jan 02, 2015 at 09:31 UTC
    What did you try?
Re: setting limitations for users based on time
by sundialsvc4 (Abbot) on Jan 02, 2015 at 16:15 UTC

    Yes, there must be someting more to it than just this.   All that you need to know is, what is the hour and minute of the current time-of-day.   The built-in module Time::Piece will very conveniently give you this.   There must be some starting and ending range of times that you care about.   If, for example, you must clock-in within 5 minutes either side of the hour ...

    use Time::Piece; my $t = localtime; # RETURNS AN OBJECT unless ( ($t->minute <= 5) or ($t->minute >= 55) { die "You can't log in now!" }

    There might be a little additional logic to “round up to the next hour” if minute >= 55 ...

      Had you actually tested what you posted you'd know this doesn't compile.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1111968]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2019-12-07 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (162 votes). Check out past polls.

    Notices?