Code Duplication    Length = 14-14 lines in 3 locations

classes/fields/date.php 1 location

@@ 322-335 (lines=14) @@
319
     *
320
     * @return string
321
     */
322
    public function convert_date ( $value, $new_format, $original_format = 'Y-m-d' ) {
323
        if ( !empty( $value ) && !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
324
            $date = $this->createFromFormat( $original_format, (string) $value );
325
326
            if ( false !== $date )
327
                $value = $date->format( $new_format );
328
            else
329
                $value = date_i18n( $new_format, strtotime( (string) $value ) );
330
        }
331
        else
332
            $value = date_i18n( $new_format );
333
334
        return $value;
335
    }
336
}
337

classes/fields/datetime.php 1 location

@@ 399-412 (lines=14) @@
396
     *
397
     * @return string
398
     */
399
    public function convert_date ( $value, $new_format, $original_format = 'Y-m-d H:i:s' ) {
400
        if ( !empty( $value ) && !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
401
            $date = $this->createFromFormat( $original_format, (string) $value );
402
403
            if ( false !== $date )
404
                $value = $date->format( $new_format );
405
            else
406
                $value = date_i18n( $new_format, strtotime( (string) $value ) );
407
        }
408
        else
409
            $value = date_i18n( $new_format );
410
411
        return $value;
412
    }
413
}
414

classes/fields/time.php 1 location

@@ 335-348 (lines=14) @@
332
     * @param $new_format
333
     * @param $original_format
334
     */
335
    public function convert_date ( $value, $new_format, $original_format = 'H:i:s' ) {
336
        if ( !empty( $value ) && !in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ) ) ) {
337
            $date = $this->createFromFormat( $original_format, (string) $value );
338
339
            if ( false !== $date )
340
                $value = $date->format( $new_format );
341
            else
342
                $value = date_i18n( $new_format, strtotime( (string) $value ) );
343
        }
344
        else
345
            $value = date_i18n( $new_format );
346
347
        return $value;
348
    }
349
}
350