$versions{'dates_mgr.pl'} = '06.6.00.0001';

# Contains all sub routines (functions) for dates that the store manager needs.

#######################################################################
#
# AgoraCart and all associated files, except where noted, are
# Copyright 2001 to Present jointly by K-Factor Technologies, Inc.
# and by C E Mayo (aka Mister Ed) at AgoraCart.com & K-Factor.net
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This copyright notice may not be removed or altered in any way.
#
#######################################################################

sub get_date {
    local ( @days, @months );
    local ($connector) = $mgr_connector_at;
    @days = @days_long;
    @months = @months_long;
    return get_date_engine();
}

#######################################################################

sub get_date_short {
    local ( @days, @months );
    local ($connector) = $mgr_connector_space;
    @days = @days_short;
    @months = @months_short;
    return get_date_engine();
}

#######################################################################

sub get_date_engine {

    local ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst, $date );

    # Uses the localtime command to get the current
    # time, from the value returned by the time
    # command, splitting it into variables.

    ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
      localtime(time);

    # Then the script formats the variables and assign them to
    # the final $date variable.

    if ( $hour < 10 ) {
        $hour = "0$hour";
    }

    if ( $min < 10 ) {
        $min = "0$min";
    }

    if ( $sec < 10 ) {
        $sec = "0$sec";
    }

    $year += 1900; # need to add for 1900's
    $date = "$days[$wday], $months[$mon] $mday, $year"
      . $connector
      . "$hour\:$min\:$sec";

    return $date;

}

#######################################################################

sub get_month_year {
    local ( @days, @months );
    @days = @days_long;
    @months = @months_long;
    return get_monthyear_engine();
}

#######################################################################

sub get_monthyear_engine {

    my ( $sec, $min, $hour, $mday, $mon, $wday, $yday, $isdst );
    my ( $month, $year );

    # Uses the localtime command to get the current
    # time, from the value returned by the time
    # command, splitting it into variables.

    ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time);

    $year += 1900; # need to add for 1900's
    $month = "$months[$mon]";

    return ( $mday, $month, $year );

}

#######################################################################
#                   get_date_from_epox_provided
#######################################################################
# Added by Mister Ed January 17, 2020

sub get_date_from_epox_provided {

    my ( $sec, $min, $hour, $mday, $mon, $wday, $yday, $isdst );
    my ( $month, $year );
    my $epox_time = shift;

    # Uses the localtime command to get the current
    # time, from the value returned by the time
    # command, splitting it into variables.

    ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime($epox_time);

    $year += 1900; # need to add for 1900's
    $month = "$months_short[$mon]";

    return ( "$month $mday, $year $hour:$min:$sec"  );

}

#######################################################################

1;
