Accessing RFC2822 joined single parameters separately, from RT::Date Object

Hi there :slight_smile:

I have been looking into the source code from github, /lib/RT/

Is it also possible to extract the parameter ‘Date’ in 3 parts? (example, day, 16) (example, month, 2)
Is it also possible to extract the parameter ‘Time’ in hours? (example, hours, 14)

The reason for this, is to convert an RFC2822 format date to custom business hours.
I already created a local perl script which will do the conversion using parameters from the perl DateTime lib.

For example a couple of parameters im using for the conversion

my @workingDays = (1,2,3,4,5); # for example, mon,tues,wed,thur,friday
my @workingHours = (20,21,22); # 8pm, 9pm,10pm
my $CurrentHour = $DateTime->hour; # 11pm

I saw that the parameters which are being calculated for the RFC2822 format are local, not gobal. then parameters returned as a joined parameter

Local parameters from

my $self = shift;
    my %args = ( Date => 1,
                 Time => 1,
                 Timezone => '',
                 DayOfWeek => 1,
                 Seconds => 1,

       #  0    1    2     3     4    5     6     7      8     9
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =

    my ($date, $time) = ('','');
    $date .= "$DAYS_OF_WEEK[$wday], " if $args{'DayOfWeek'} && $args{'Date'};
    $date .= sprintf("%02d %s %04d", $mday, $MONTHS[$mon], $year) if $args{'Date'};

    if ( $args{'Time'} ) {
        $time .= sprintf("%02d:%02d", $hour, $min);
        $time .= sprintf(":%02d", $sec) if $args{'Seconds'};
        $time .= sprintf " %s%02d%02d", $self->_SplitOffset( $offset );

Then returns the at the end of the method using

    return join ' ', grep $_, ($date, $time);

I have been looking at the docs

I see you have the functions such as

  • GetWeekday
  • GetMonth
  • AddDays

Would be cool to have AddHours, but a mathematical conversion can be done and still use AddDays for this

I then was looking at the RFC2822 Date Format in the docs
This returns

Supports arguments: Timezone, Date, Time, DayOfWeek and Seconds.

If you have an RT::Date object with the date/time in it already, you could use the AddSeconds() or AddDays() methods to add your offsets and then use RT::Date's RFC2822 formatting on the output to get the format of date you want so you don’t have to mess with the individual date/time components. The AddSeconds() method can be used to add hours simply by multiplying your hours figure by 3600.

If you really do need the date/time all split up you could just get the ISO format from your RT::Date object, split it on ’ ’ to break the date from the time, then split the date into three on - and the time into three on ‘:’. I’ve done that regularly on many systems (though I’ve not needed to with RT). Newer versions of RT also have a DateTimeObj() method in RT::Date which gives you the underlying DateTime object that you can then manipulate directly using that Perl module.

1 Like