1*cdf0e10cSrcweirpackage timehelper; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir#************************************************************************* 4*cdf0e10cSrcweir# 5*cdf0e10cSrcweir# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6*cdf0e10cSrcweir# 7*cdf0e10cSrcweir# Copyright 2000, 2010 Oracle and/or its affiliates. 8*cdf0e10cSrcweir# 9*cdf0e10cSrcweir# OpenOffice.org - a multi-platform office productivity suite 10*cdf0e10cSrcweir# 11*cdf0e10cSrcweir# This file is part of OpenOffice.org. 12*cdf0e10cSrcweir# 13*cdf0e10cSrcweir# OpenOffice.org is free software: you can redistribute it and/or modify 14*cdf0e10cSrcweir# it under the terms of the GNU Lesser General Public License version 3 15*cdf0e10cSrcweir# only, as published by the Free Software Foundation. 16*cdf0e10cSrcweir# 17*cdf0e10cSrcweir# OpenOffice.org is distributed in the hope that it will be useful, 18*cdf0e10cSrcweir# but WITHOUT ANY WARRANTY; without even the implied warranty of 19*cdf0e10cSrcweir# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20*cdf0e10cSrcweir# GNU Lesser General Public License version 3 for more details 21*cdf0e10cSrcweir# (a copy is included in the LICENSE file that accompanied this code). 22*cdf0e10cSrcweir# 23*cdf0e10cSrcweir# You should have received a copy of the GNU Lesser General Public License 24*cdf0e10cSrcweir# version 3 along with OpenOffice.org. If not, see 25*cdf0e10cSrcweir# <http://www.openoffice.org/license.html> 26*cdf0e10cSrcweir# for a copy of the LGPLv3 License. 27*cdf0e10cSrcweir# 28*cdf0e10cSrcweir#************************************************************************* 29*cdf0e10cSrcweir 30*cdf0e10cSrcweiruse POSIX qw(strftime); 31*cdf0e10cSrcweiruse POSIX qw(time difftime); 32*cdf0e10cSrcweir# use POSIX qw(localtime); 33*cdf0e10cSrcweiruse strict; 34*cdf0e10cSrcweir# use Time::localtime; 35*cdf0e10cSrcweiruse loghelper; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweirBEGIN { 38*cdf0e10cSrcweir use Exporter (); 39*cdf0e10cSrcweir our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir $VERSION = 1.00; 42*cdf0e10cSrcweir # if using RCS/CVS, this may be preferred 43*cdf0e10cSrcweir $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker 44*cdf0e10cSrcweir @ISA = qw(Exporter); 45*cdf0e10cSrcweir @EXPORT = qw(&getTime &endTime &printTime &waitAMinute ); 46*cdf0e10cSrcweir %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], 47*cdf0e10cSrcweir # your exported package globals go here, 48*cdf0e10cSrcweir # as well as any optionally exported functions 49*cdf0e10cSrcweir @EXPORT_OK = ( ); # qw($Var1 %Hashit &func3); 50*cdf0e10cSrcweir} 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir# ------------------------------------------------------------------------------ 54*cdf0e10cSrcweir# our $starttime; 55*cdf0e10cSrcweirsub getTime() 56*cdf0e10cSrcweir{ 57*cdf0e10cSrcweir my $nValue; 58*cdf0e10cSrcweir # $nValue = localtime->sec(); 59*cdf0e10cSrcweir # $nValue += 60 * localtime->min(); 60*cdf0e10cSrcweir # $nValue += 3600 * localtime->hour(); 61*cdf0e10cSrcweir $nValue = time(); 62*cdf0e10cSrcweir return $nValue; 63*cdf0e10cSrcweir} 64*cdf0e10cSrcweir# sub startTime() 65*cdf0e10cSrcweir# { 66*cdf0e10cSrcweir# $starttime = getTime(); 67*cdf0e10cSrcweir# } 68*cdf0e10cSrcweirsub endTime($) 69*cdf0e10cSrcweir{ 70*cdf0e10cSrcweir my $starttime = shift; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir my $endtime = getTime(); 73*cdf0e10cSrcweir my $nTime = difftime($endtime, $starttime); 74*cdf0e10cSrcweir # my $nTime = $endtime - $starttime; 75*cdf0e10cSrcweir # if ($nTime < 0) 76*cdf0e10cSrcweir # { 77*cdf0e10cSrcweir # $nTime += 24 * 3600; # add 24 hours 78*cdf0e10cSrcweir # } 79*cdf0e10cSrcweir return $nTime; 80*cdf0e10cSrcweir} 81*cdf0e10cSrcweirsub printTime($) 82*cdf0e10cSrcweir{ 83*cdf0e10cSrcweir my $nTime = shift; 84*cdf0e10cSrcweir print( "Time: " . $nTime . " seconds.\n\n"); 85*cdf0e10cSrcweir} 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir# sub waitAMinute() 89*cdf0e10cSrcweir# { 90*cdf0e10cSrcweir# # _waitInSeconds(20); 91*cdf0e10cSrcweir# # _waitInSeconds(20); 92*cdf0e10cSrcweir# my $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; 93*cdf0e10cSrcweir# print $now_string . "\n"; 94*cdf0e10cSrcweir# # print getCurrentDateString() . "\n"; 95*cdf0e10cSrcweir# sleep(60); 96*cdf0e10cSrcweir# } 97*cdf0e10cSrcweir# 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir1; 100