1cdf0e10cSrcweirpackage timehelper;
2cdf0e10cSrcweir
3*9780544fSAndrew Rist#**************************************************************
4*9780544fSAndrew Rist#
5*9780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
6*9780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
7*9780544fSAndrew Rist#  distributed with this work for additional information
8*9780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
9*9780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
10*9780544fSAndrew Rist#  "License"); you may not use this file except in compliance
11*9780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
12*9780544fSAndrew Rist#
13*9780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
14*9780544fSAndrew Rist#
15*9780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
16*9780544fSAndrew Rist#  software distributed under the License is distributed on an
17*9780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*9780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
19*9780544fSAndrew Rist#  specific language governing permissions and limitations
20*9780544fSAndrew Rist#  under the License.
21*9780544fSAndrew Rist#
22*9780544fSAndrew Rist#**************************************************************
23*9780544fSAndrew Rist
24*9780544fSAndrew Rist
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse POSIX qw(strftime);
27cdf0e10cSrcweiruse POSIX qw(time difftime);
28cdf0e10cSrcweir# use POSIX qw(localtime);
29cdf0e10cSrcweiruse strict;
30cdf0e10cSrcweir# use Time::localtime;
31cdf0e10cSrcweiruse loghelper;
32cdf0e10cSrcweir
33cdf0e10cSrcweirBEGIN {
34cdf0e10cSrcweir    use Exporter   ();
35cdf0e10cSrcweir    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
36cdf0e10cSrcweir
37cdf0e10cSrcweir    $VERSION     = 1.00;
38cdf0e10cSrcweir    # if using RCS/CVS, this may be preferred
39cdf0e10cSrcweir    $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
40cdf0e10cSrcweir    @ISA         = qw(Exporter);
41cdf0e10cSrcweir    @EXPORT      = qw(&getTime &endTime &printTime &waitAMinute );
42cdf0e10cSrcweir    %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
43cdf0e10cSrcweir    # your exported package globals go here,
44cdf0e10cSrcweir    # as well as any optionally exported functions
45cdf0e10cSrcweir    @EXPORT_OK   = ( ); # qw($Var1 %Hashit &func3);
46cdf0e10cSrcweir}
47cdf0e10cSrcweir
48cdf0e10cSrcweir
49cdf0e10cSrcweir# ------------------------------------------------------------------------------
50cdf0e10cSrcweir# our $starttime;
51cdf0e10cSrcweirsub getTime()
52cdf0e10cSrcweir{
53cdf0e10cSrcweir    my $nValue;
54cdf0e10cSrcweir    # $nValue = localtime->sec();
55cdf0e10cSrcweir    # $nValue += 60 * localtime->min();
56cdf0e10cSrcweir    # $nValue += 3600 * localtime->hour();
57cdf0e10cSrcweir    $nValue = time();
58cdf0e10cSrcweir    return $nValue;
59cdf0e10cSrcweir}
60cdf0e10cSrcweir# sub startTime()
61cdf0e10cSrcweir# {
62cdf0e10cSrcweir#     $starttime = getTime();
63cdf0e10cSrcweir# }
64cdf0e10cSrcweirsub endTime($)
65cdf0e10cSrcweir{
66cdf0e10cSrcweir    my $starttime = shift;
67cdf0e10cSrcweir
68cdf0e10cSrcweir    my $endtime = getTime();
69cdf0e10cSrcweir    my $nTime = difftime($endtime, $starttime);
70cdf0e10cSrcweir    # my $nTime = $endtime - $starttime;
71cdf0e10cSrcweir    # if ($nTime < 0)
72cdf0e10cSrcweir    # {
73cdf0e10cSrcweir    #     $nTime += 24 * 3600; # add 24 hours
74cdf0e10cSrcweir    # }
75cdf0e10cSrcweir    return $nTime;
76cdf0e10cSrcweir}
77cdf0e10cSrcweirsub printTime($)
78cdf0e10cSrcweir{
79cdf0e10cSrcweir    my $nTime = shift;
80cdf0e10cSrcweir    print( "Time: " . $nTime . " seconds.\n\n");
81cdf0e10cSrcweir}
82cdf0e10cSrcweir
83cdf0e10cSrcweir
84cdf0e10cSrcweir# sub waitAMinute()
85cdf0e10cSrcweir# {
86cdf0e10cSrcweir#     # _waitInSeconds(20);
87cdf0e10cSrcweir#     # _waitInSeconds(20);
88cdf0e10cSrcweir#     my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
89cdf0e10cSrcweir#     print $now_string . "\n";
90cdf0e10cSrcweir#     # print getCurrentDateString() . "\n";
91cdf0e10cSrcweir#     sleep(60);
92cdf0e10cSrcweir# }
93cdf0e10cSrcweir#
94cdf0e10cSrcweir
95cdf0e10cSrcweir1;
96