<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# ----------------------------------------------------------------------------
# This software is Copyright (C) 2007, All Rights Reserved
# ----------------------------------------------------------------------------
# This program is protected by local and international copyright laws. Any
# use of this program is subject to the the terms of the license agreement
# included as part of this distribution archive. Any other uses are strictly
# prohibited without the written permission of the Vendor and all
# other rights are reserved.
# -----------------------------------------------------------------------------
# Warning : Modifying this program violates your license agreement!
# -----------------------------------------------------------------------------

package IT::App::Common;

use strict;

use IT::Globals;

# ------------------------------------------------------------------------
# Function    : getTimeAdjustedToMatchGMT
# Description : Takes time() value as an argument and adjusts it to match
#               for local time offset from GMT.  So if it was 4:31, Mar 1st
#               this function would return a time value that would be
#               4:31, Mar 1st as returned by gmtime().
# Usage       : $adjustedTimeValue = &amp;IT::App::Common::getTimeAdjustedToMatchGMT($timeValue);
# Usage       : $adjustedTimeValue = &amp;IT::App::Common::getTimeAdjustedToMatchGMT();
# ------------------------------------------------------------------------

sub getTimeAdjustedToMatchGMT {
  my $inputTime = shift || time();

  my $localTimeOffset = &amp;getLocalTimeOffsetFromGMT();
  my $adjustedTime    = $inputTime + $localTimeOffset;

  if ($adjustedTime &lt;= 0) { $adjustedTime = 1; }  # true, non-negative value

  return $adjustedTime;
}

# ------------------------------------------------------------------------
# Function    : getLocalTimeOffsetFromGMT
# Description : Get local time offset from GMT in seconds.  We store all dates
#               internally as if they were GMT dates.  Use this to modify time()
#
# Usage       : $localTimeAdjustmentInSeconds = &amp;IT::App::Common::getLocalTimeOffsetFromGMT();
#               my $time = time() + $localTimeAdjustmentInSeconds;
# ------------------------------------------------------------------------

sub getLocalTimeOffsetFromGMT {
  my $localTimeAdjustmentInSeconds = 0;
  my $oneMinute = 60;
  my $oneHour   = 60*60;

  ### adjust hours
  if    ($SETTINGS-&gt;{'localtime_hour_adjustment'} eq 'add') {
    $localTimeAdjustmentInSeconds += $SETTINGS-&gt;{'localtime_hour_offset'} * $oneHour;
  }
  elsif ($SETTINGS-&gt;{'localtime_hour_adjustment'} eq 'minus') {
    $localTimeAdjustmentInSeconds -= $SETTINGS-&gt;{'localtime_hour_offset'} * $oneHour;
  }
  else { die("unknown 'localtime_hour_adjustment' value '$SETTINGS-&gt;{'localtime_hour_adjustment'}'.  Should be 'add' or 'minus'."); }

  ### adjust minutes
  if    ($SETTINGS-&gt;{'localtime_minute_adjustment'} eq 'add') {
    $localTimeAdjustmentInSeconds += $SETTINGS-&gt;{'localtime_minute_offset'} * $oneMinute;
  }
  elsif ($SETTINGS-&gt;{'localtime_minute_adjustment'} eq 'minus') {
    $localTimeAdjustmentInSeconds -= $SETTINGS-&gt;{'localtime_minute_offset'} * $oneMinute;
  }
  else { die("unknown 'localtime_minute_adjustment' value '$SETTINGS-&gt;{'localtime_hour_adjustment'}'.  Should be 'add' or 'minus'."); }

  ### Adjust for Daylight Savings Time
  my $isDaylightSavingsTime = (localtime(time))[8];
  if ($isDaylightSavingsTime &amp;&amp; $SETTINGS-&gt;{'localtimeDstAdjustment'}) {
    $localTimeAdjustmentInSeconds += $oneHour;
  }

  return $localTimeAdjustmentInSeconds;
}

# ----------------------------------------------------------------------------
# end of file
1;

</pre></body></html>