Code Duplication    Length = 19-22 lines in 3 locations

app/Helpers/Helper.php 3 locations

@@ 8-26 (lines=19) @@
5
use Illuminate\Support\Facades\Config;
6
use Illuminate\Support\Facades\Lang;
7
8
if (!function_exists('humanizeDate')) {
9
    /**
10
     * Computes a human readable localized date.
11
     *
12
     * @param Date $datetime DateTime object to translate.
13
     *
14
     * @return string
15
     */
16
    function humanizeDate(Date $datetime) : string
17
    {
18
        $dateFormat = Config::get('app.date_format');
19
        $locale = App::getLocale();
20
        $timezone = Config::get('app.local_timezone');
21
22
        $datetime->setTimezone(new \DateTimeZone($timezone));
23
24
        return $datetime->format($dateFormat[$locale]);
25
    }
26
}
27
28
if (!function_exists('humanizeTime')) {
29
    /**
@@ 111-132 (lines=22) @@
108
    }
109
}
110
111
if (!function_exists('ptDayStartToUtcTime')) {
112
    /**
113
     * Given a date, creates a datetime object representing the start of day
114
     * in the most Western timezone in Canada (America/Vancouver).
115
     *
116
     * @param string $date ISO standard date YYYY-MM-DD.
117
     *
118
     * @return Date
119
     */
120
    function ptDayStartToUtcTime(string $date) : Date
121
    {
122
        $jobTimezone = Config::get('app.job_timezone');
123
        $dbTimezone = Config::get('app.timezone');
124
        // Create a new date that's the beginning of the day in
125
        // Pacific Daylight/Standard Time.
126
        $date = new Date("$date 00:00:00", new \DateTimeZone($jobTimezone));
127
        // Convert to UTC for correct offset.
128
        $date->setTimezone($dbTimezone);
129
130
        return $date;
131
    }
132
}
133
134
if (!function_exists('ptDayEndToUtcTime')) {
135
    /**
@@ 134-155 (lines=22) @@
131
    }
132
}
133
134
if (!function_exists('ptDayEndToUtcTime')) {
135
    /**
136
     * Given a date, creates a datetime object representing the start of day
137
     * in the most Western timezone in Canada (America/Vancouver).
138
     *
139
     * @param string $date ISO standard date YYYY-MM-DD.
140
     *
141
     * @return Date
142
     */
143
    function ptDayEndToUtcTime(string $date) : Date
144
    {
145
        $jobTimezone = Config::get('app.job_timezone');
146
        $dbTimezone = Config::get('app.timezone');
147
        // Create a new date that's the beginning of the day in
148
        // Pacific Daylight/Standard Time.
149
        $date = new Date("$date 23:59:59", new \DateTimeZone($jobTimezone));
150
        // Convert to UTC for correct offset.
151
        $date->setTimezone($dbTimezone);
152
153
        return $date;
154
    }
155
}
156