forked from qtranslate/qtranslate-xt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtranslate_date_time.php
602 lines (548 loc) · 23 KB
/
qtranslate_date_time.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
<?php
/**
* Locale-formatted strftime using \IntlDateFormatter (PHP 8.1 compatible)
* This provides a cross-platform alternative to strftime() for when it will be removed from PHP.
* Note that output can be slightly different between libc sprintf and this function as it is using ICU.
* Non-standard strftime: '%q' is a qTranslate format to mimic date 'S'.
*
* Usage:
* echo strftime('%A %e %B %Y %X', new \DateTime('2021-09-28 00:00:00'), 'fr_FR');
*
* Original use:
* \setlocale('fr_FR.UTF-8', LC_TIME);
* echo \strftime('%A %e %B %Y %X', strtotime('2021-09-28 00:00:00'));
*
* @param string $format Date format
* @param integer|string|DateTime $timestamp Timestamp
*
* @return string
* @todo Maybe deprecate. Avoid using this function, meant to transition from legacy strftime formats.
* @see https://gist.github.com/bohwaz/42fc223031e2b2dd2585aab159a20f30 (for the original code).
*/
function qxtranxf_intl_strftime( $format, $timestamp = null, $locale = null ) {
if ( null === $timestamp ) {
$timestamp = new \DateTime;
} elseif ( is_numeric( $timestamp ) ) {
$timestamp = date_create( '@' . $timestamp );
if ( $timestamp ) {
$timestamp->setTimezone( new \DateTimezone( date_default_timezone_get() ) );
}
} elseif ( is_string( $timestamp ) ) {
$timestamp = date_create( $timestamp );
}
if ( ! ( $timestamp instanceof \DateTimeInterface ) ) {
throw new \InvalidArgumentException( '$timestamp argument is neither a valid UNIX timestamp, a valid date-time string or a DateTime object.' );
}
$locale = substr( (string) $locale, 0, 5 );
$intl_formats = [
'%a' => 'EEE', // An abbreviated textual representation of the day Sun through Sat
'%A' => 'EEEE', // A full textual representation of the day Sunday through Saturday
'%b' => 'MMM', // Abbreviated month name, based on the locale Jan through Dec
'%B' => 'MMMM', // Full month name, based on the locale January through December
'%h' => 'MMM', // Abbreviated month name, based on the locale (an alias of %b) Jan through Dec
];
// \DateTimeInterface, string
$intl_formatter = function ( $timestamp, $format ) use ( $intl_formats, $locale ) {
$tz = $timestamp->getTimezone();
$date_type = \IntlDateFormatter::FULL;
$time_type = \IntlDateFormatter::FULL;
$pattern = '';
// %c = Preferred date and time stamp based on locale
// Example: Tue Feb 5 00:45:10 2009 for February 5, 2009 at 12:45:10 AM
if ( $format == '%c' ) {
$date_type = \IntlDateFormatter::LONG;
$time_type = \IntlDateFormatter::SHORT;
}
// %x = Preferred date representation based on locale, without the time
// Example: 02/05/09 for February 5, 2009
elseif ( $format == '%x' ) {
$date_type = \IntlDateFormatter::SHORT;
$time_type = \IntlDateFormatter::NONE;
} // Localized time format
elseif ( $format == '%X' ) {
$date_type = \IntlDateFormatter::NONE;
$time_type = \IntlDateFormatter::MEDIUM;
} else {
$pattern = $intl_formats[ $format ];
}
return ( new \IntlDateFormatter( $locale, $date_type, $time_type, $tz, null, $pattern ) )->format( $timestamp );
};
// Same order as https://www.php.net/manual/en/function.strftime.php
$translation_table = [
// Day
'%a' => $intl_formatter,
'%A' => $intl_formatter,
'%d' => 'd',
'%e' => function ( $timestamp ) {
return sprintf( '% 2u', $timestamp->format( 'j' ) );
},
'%j' => function ( $timestamp ) {
// Day number in year, 001 to 366
return sprintf( '%03d', $timestamp->format( 'z' ) + 1 );
},
'%u' => 'N',
'%w' => 'w',
// Week
'%U' => function ( $timestamp ) {
// Number of weeks between date and first Sunday of year
$day = new \DateTime( sprintf( '%d-01 Sunday', $timestamp->format( 'Y' ) ) );
return sprintf( '%02u', 1 + ( $timestamp->format( 'z' ) - $day->format( 'z' ) ) / 7 );
},
'%V' => 'W',
'%W' => function ( $timestamp ) {
// Number of weeks between date and first Monday of year
$day = new \DateTime( sprintf( '%d-01 Monday', $timestamp->format( 'Y' ) ) );
return sprintf( '%02u', 1 + ( $timestamp->format( 'z' ) - $day->format( 'z' ) ) / 7 );
},
// Month
'%b' => $intl_formatter,
'%B' => $intl_formatter,
'%h' => $intl_formatter,
'%m' => 'm',
// Year
'%C' => function ( $timestamp ) {
// Century (-1): 19 for 20th century
return floor( $timestamp->format( 'Y' ) / 100 );
},
'%g' => function ( $timestamp ) {
return substr( $timestamp->format( 'o' ), -2 );
},
'%G' => 'o',
'%y' => 'y',
'%Y' => 'Y',
// Time
'%H' => 'H',
'%k' => function ( $timestamp ) {
return sprintf( '% 2u', $timestamp->format( 'G' ) );
},
'%I' => 'h',
'%l' => function ( $timestamp ) {
return sprintf( '% 2u', $timestamp->format( 'g' ) );
},
'%M' => 'i',
'%p' => 'A', // AM PM (this is reversed on purpose!)
'%P' => 'a', // am pm
'%r' => 'h:i:s A', // %I:%M:%S %p
'%R' => 'H:i', // %H:%M
'%S' => 's',
'%T' => 'H:i:s', // %H:%M:%S
'%X' => $intl_formatter, // Preferred time representation based on locale, without the date
// Timezone
'%z' => 'O',
'%Z' => 'T',
// Time and Date Stamps
'%c' => $intl_formatter,
'%D' => 'm/d/Y',
'%F' => 'Y-m-d',
'%s' => 'U',
'%x' => $intl_formatter,
// QTranslate: non-standard strftime
'%E' => 'j', // Day number no zero
'%q' => 'S', // Day english ordinal
'%f' => 'w', // Week number
'%v' => 'T', // Timezone abbreviation, if known; otherwise the GMT offset.
'%i' => 'n', // Numeric representation of a month, without leading zeros
'%J' => 't', // Number of days in the given month
'%K' => 'B', // Swatch internet time 000-999
'%L' => 'G', // 24-hour format of an hour without leading zeros ---> %L should be %k!
'%N' => 'u', // Microseconds
'%Q' => 'e', // Timezone identifier
'%o' => 'I', // 1 if Daylight Saving Time, 0 otherwise.
'%O' => 'O', // Difference to Greenwich time (GMT) without colon between hours and minutes
'%1' => 'Z', // Timezone offset in seconds
'%2' => 'c', // ISO 8601 date
'%3' => 'r', // RFC 2822/» RFC 5322 formatted date
'%4' => 'U', // Seconds since the Unix Epoch
];
$out = preg_replace_callback( '/(?<!%)(%[a-zA-Z])/', function ( $match ) use ( $translation_table, $timestamp ) {
if ( $match[1] == '%n' ) {
return "\n";
} elseif ( $match[1] == '%t' ) {
return "\t";
}
if ( ! isset( $translation_table[ $match[1] ] ) ) {
throw new \InvalidArgumentException( sprintf( 'Format "%s" is unknown in time format', $match[1] ) );
}
$replace = $translation_table[ $match[1] ];
if ( is_string( $replace ) ) {
return $timestamp->format( $replace );
} else {
return $replace( $timestamp, $match[1] );
}
}, $format );
$out = str_replace( '%%', '%', $out );
return $out;
}
/**
* Converter of a format given in DateTime format, transformed to the extended "QTX-strftime" format.
*
* @param string $format in DateTime format. Format characters can be quoted with backslashes.
*
* @return string
* @todo Maybe deprecate. Don't use strftime formats anymore, since strftime is deprecated from PHP8.1.
* @see https://www.php.net/manual/en/function.strftime.php
* @see https://www.php.net/manual/en/datetime.format.php
*/
function qtranxf_convert_date_format_to_strftime_format( $format ) {
$mappings = array(
// day
'd' => '%d',
'D' => '%a',
'l' => '%A',
'N' => '%u',
// week
'W' => '%V',
// month
'F' => '%B',
'm' => '%m',
'M' => '%b',
// year
'o' => '%G',
'Y' => '%Y',
'y' => '%y',
// time
'a' => '%P',
'A' => '%p',
'g' => '%l',
'h' => '%I',
'H' => '%H',
'i' => '%M',
's' => '%S',
// QTranslate: override strftime, not consistent with date formats :-/
'z' => '%F', // z: The day of the year (starting from 0) -- %F: Same as "%Y-%m-%d
'P' => '%s', // P: Difference to Greenwich time (GMT) with colon between hours and minutes -- %s: unix timestamp
'L' => '%k', // L: leap year -- %k: Hour in 24-hour format, single digit
// QTranslate: non-standard strftime to mimic some date formats
'j' => '%E', // Day number no zero
'S' => '%q', // Day english ordinal
'w' => '%f', // Week number
'T' => '%v', // Timezone abbreviation, if known; otherwise the GMT offset.
'n' => '%i', // Numeric representation of a month, without leading zeros
't' => '%J', // Number of days in the given month
'B' => '%K', // Swatch internet time 000-999
'G' => '%L', // 24-hour format of an hour without leading zeros --> %L should be %k!
'u' => '%N', // Microseconds
'e' => '%Q', // Timezone identifier
'I' => '%o', // 1 if Daylight Saving Time, 0 otherwise.
'O' => '%O', // Difference to Greenwich time (GMT) without colon between hours and minutes
'Z' => '%1', // Timezone offset in seconds
'c' => '%2', // ISO 8601 date
'r' => '%3', // RFC 2822/» RFC 5322 formatted date
'U' => '%4' // Seconds since the Unix Epoch
);
$date_parameters = array();
$strftime_parameters = array();
$date_parameters[] = '#%#';
$strftime_parameters[] = '%';
foreach ( $mappings as $df => $sf ) {
// Format characters can be quoted with backslashes.
$date_parameters[] = '#(([^%\\\\])' . $df . '|^' . $df . ')#';
$strftime_parameters[] = '${2}' . $sf;
}
// convert everything
$format = preg_replace( $date_parameters, $strftime_parameters, $format );
// Remove single backslashes and convert double to single.
return stripslashes( $format );
}
/**
* [Legacy] Converter of a format given in DateTime format, transformed to the extended "QTX-strftime" format.
*
* @param string $format in DateTime format.
*
* @return string
* @deprecated Use qtranxf_convert_date_format_to_strftime_format.
*/
function qtranxf_convertDateFormatToStrftimeFormat( $format ) {
_deprecated_function( __FUNCTION__, '3.13.0', 'qtranxf_convert_date_format_to_strftime_format' );
return qtranxf_convert_date_format_to_strftime_format( $format );
}
/**
* Converter of a format/default pair to "QTX-strftime" format, applying 'use_strftime' configuration.
*
* @param string $format ATTENTION - always given in date PHP format.
* @param string $default_format language format following the 'use_strftime' configuration.
*
* @return string format in strftime
* @todo Maybe deprecate. Don't use strftime formats anymore, since strftime is deprecated from PHP8.1.
*/
function qtranxf_convert_to_strftime_format_using_config( $format, $default_format ) {
global $q_config;
// If one of special language-neutral formats is requested, don't override it.
switch ( $format ) {
case 'Z':
case 'c':
case 'r':
case 'U':
return qtranxf_convert_date_format_to_strftime_format( $format );
}
// Attention - this part is quite tricky.
// The user format is always given in date format, but not the language format which depends on use_strftime settings.
// The language format may contain escape backslash characters that must be unquoted in any case.
switch ( $q_config['use_strftime'] ) {
case QTX_DATE:
// Convert both.
return qtranxf_convert_date_format_to_strftime_format( ! empty( $format ) ? $format : $default_format );
case QTX_DATE_OVERRIDE:
return qtranxf_convert_date_format_to_strftime_format( $default_format );
case QTX_STRFTIME:
return ( ! empty( $format ) ? qtranxf_convert_date_format_to_strftime_format( $format ) : stripslashes( $default_format ) );
case QTX_STRFTIME_OVERRIDE:
return stripslashes( $default_format );
case QTX_DATE_WP:
default:
return '';
}
}
/**
* [Legacy] Converter of a format/default pair to "QTX-strftime" format, applying 'use_strftime' configuration.
*
* @param string $format ATTENTION - always given in date PHP format.
* @param string $default_format , following the strftime configuration.
*
* @return string
* @deprecated Use qtranxf_convert_to_strftime_format_using_config.
*/
function qtranxf_convertFormat( $format, $default_format ) {
_deprecated_function( __FUNCTION__, '3.13.0', 'qtranxf_convert_to_strftime_format_using_config' );
return qtranxf_convert_to_strftime_format_using_config( $format, $default_format );
}
/**
* Return the date or time format set for the current language config or default language.
*
* @param string $config_key
*
* @return string
*/
function qtranxf_get_language_date_or_time_format( $config_key ) {
assert( $config_key == 'date_format' || $config_key == 'time_format' );
global $q_config;
if ( isset( $q_config[ $config_key ][ $q_config['language'] ] ) ) {
return $q_config[ $config_key ][ $q_config['language'] ];
} elseif ( isset( $q_config[ $config_key ][ $q_config['default_language'] ] ) ) {
return $q_config[ $config_key ][ $q_config['default_language'] ];
} else {
return '';
}
}
/**
* [Legacy] Converter of a date format to "QTX-strftime" format, applying qTranslate 'use_strftime' configuration.
*
* @param string $format
*
* @return string
* @deprecated Use qtranxf_get_language_date_or_time_format.
*/
function qtranxf_convertDateFormat( $format ) {
_deprecated_function( __FUNCTION__, '3.13.0', 'qtranxf_get_language_date_or_time_format' );
$default_format = qtranxf_get_language_date_or_time_format( 'date_format' );
return qtranxf_convertFormat( $format, $default_format );
}
/**
* [Legacy] Converter of a time format to "QTX-strftime" format, applying qTranslate 'use_strftime' configuration.
*
* @param string $format
*
* @return string
* @deprecated Use qtranxf_get_language_date_or_time_format.
*/
function qtranxf_convertTimeFormat( $format ) {
_deprecated_function( __FUNCTION__, '3.13.0', 'qtranxf_get_language_date_or_time_format' );
$default_format = qtranxf_get_language_date_or_time_format( 'time_format' );
return qtranxf_convertFormat( $format, $default_format );
}
/**
* [Legacy] Extension of PHP "QTX-strftime", valid up to PHP 8.0.
*
* @param string $format extended strftime with additional features such as %q
* @param int $date timestamp
* @param string $default Default result when $format is empty.
* @param string $before Text copied before result.
* @param string $after Text copied after result.
*
* @return mixed|string
* @deprecated Use qxtranxf_intl_strftime, since strftime is deprecated from PHP8.1.
* @See https://www.php.net/manual/en/function.strftime.php
*/
function qtranxf_strftime( $format, $date, $default = '', $before = '', $after = '' ) {
_deprecated_function( __FUNCTION__, '3.13.0', 'qxtranxf_intl_strftime' );
if ( empty( $format ) ) {
return $default;
}
// add date suffix ability (%q) to strftime
$day = intval( ltrim( strftime( "%d", $date ), '0' ) );
$search = array();
$replace = array();
// date S
$search[] = '/(([^%])%q|^%q)/';
if ( $day == 1 || $day == 21 || $day == 31 ) {
$replace[] = '$2st';
} elseif ( $day == 2 || $day == 22 ) {
$replace[] = '$2nd';
} elseif ( $day == 3 || $day == 23 ) {
$replace[] = '$2rd';
} else {
$replace[] = '$2th';
}
$search[] = '/(([^%])%E|^%E)/';
$replace[] = '${2}' . $day; // date j
$search[] = '/(([^%])%f|^%f)/';
$replace[] = '${2}' . date( 'w', $date ); // date w
$search[] = '/(([^%])%F|^%F)/';
$replace[] = '${2}' . date( 'z', $date ); // date z
$search[] = '/(([^%])%i|^%i)/';
$replace[] = '${2}' . date( 'n', $date ); // date n
$search[] = '/(([^%])%J|^%J)/';
$replace[] = '${2}' . date( 't', $date ); // date t
$search[] = '/(([^%])%k|^%k)/';
$replace[] = '${2}' . date( 'L', $date ); // date L
$search[] = '/(([^%])%K|^%K)/';
$replace[] = '${2}' . date( 'B', $date ); // date B
$search[] = '/(([^%])%l|^%l)/';
$replace[] = '${2}' . date( 'g', $date ); // date g
$search[] = '/(([^%])%L|^%L)/';
$replace[] = '${2}' . date( 'G', $date ); // date G
$search[] = '/(([^%])%N|^%N)/';
$replace[] = '${2}' . date( 'u', $date ); // date u
$search[] = '/(([^%])%Q|^%Q)/';
$replace[] = '${2}' . date( 'e', $date ); // date e
$search[] = '/(([^%])%o|^%o)/';
$replace[] = '${2}' . date( 'I', $date ); // date I
$search[] = '/(([^%])%O|^%O)/';
$replace[] = '${2}' . date( 'O', $date ); // date O
$search[] = '/(([^%])%s|^%s)/';
$replace[] = '${2}' . date( 'P', $date ); // date P
$search[] = '/(([^%])%v|^%v)/';
$replace[] = '${2}' . date( 'T', $date ); // date T
$search[] = '/(([^%])%1|^%1)/';
$replace[] = '${2}' . date( 'Z', $date ); // date Z
$search[] = '/(([^%])%2|^%2)/';
$replace[] = '${2}' . date( 'c', $date ); // date c
$search[] = '/(([^%])%3|^%3)/';
$replace[] = '${2}' . date( 'r', $date ); // date r
$search[] = '/(([^%])%4|^%4)/';
$replace[] = '${2}' . $date; // date U
$format = preg_replace( $search, $replace, $format );
return $before . strftime( $format, $date ) . $after;
}
/**
* [Legacy] Generalized formatting of a date, applying qTranslate 'use_strftime' config.
*
* @param string $format
* @param string $mysql_time date string in MySQL format
* @param string $default_value default date value.
* @param string $before Deprecated. Not used, will be removed in a future version.
* @param string $after Deprecated. Not used, will be removed in a future version.
*
* @return string date/time if the format is valid, default value otherwise.
*/
function qtranxf_format_date( $format, $mysql_time, $default_value, $before = '', $after = '' ) {
if ( ! empty( $before ) || ! empty( $after ) ) {
_deprecated_argument( __FUNCTION__, '3.13.0' );
}
$timestamp = mysql2date( 'U', $mysql_time );
if ( $format == 'U' ) {
return $timestamp;
}
$language_format = qtranxf_get_language_date_or_time_format( 'date_format' );
// TODO: abandon strftime format in qTranslate.
$date_format = qtranxf_convert_to_strftime_format_using_config( $format, $language_format );
return ( ! empty( $date_format ) ? qxtranxf_intl_strftime( $date_format, $timestamp, get_locale() ) : $default_value );
}
/**
* [Legacy] Generalized formatting of a date, applying qTranslate 'use_strftime' config.
*
* @param string $format
* @param string $mysql_time time string in MySQL format
* @param string $default_value default time value.
* @param string $before Deprecated. Not used, will be removed in a future version.
* @param string $after Deprecated. Not used, will be removed in a future version.
*
* @return string date/time if the format is valid, default value otherwise.
*/
function qtranxf_format_time( $format, $mysql_time, $default_value, $before = '', $after = '' ) {
if ( ! empty( $before ) || ! empty( $after ) ) {
_deprecated_argument( __FUNCTION__, '3.13.0' );
}
$timestamp = mysql2date( 'U', $mysql_time );
if ( $format == 'U' ) {
return $timestamp;
}
$language_format = qtranxf_get_language_date_or_time_format( 'time_format' );
// TODO: abandon strftime format in qTranslate.
$date_format = qtranxf_convert_to_strftime_format_using_config( $format, $language_format );
return ( ! empty( $date_format ) ? qxtranxf_intl_strftime( $date_format, $timestamp, get_locale() ) : $default_value );
}
// @see get_the_date
function qtranxf_dateFromPostForCurrentLanguage( $old_date, $format = '', $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return $old_date;
}
return qtranxf_format_date( $format, $post->post_date, $old_date );
}
// @see get_the_modified_date
function qtranxf_dateModifiedFromPostForCurrentLanguage( $old_date, $format = '' ) {
global $post;
if ( ! $post ) {
return $old_date;
}
return qtranxf_format_date( $format, $post->post_modified, $old_date );
}
// @see get_the_time
function qtranxf_timeFromPostForCurrentLanguage( $old_date, $format = '', $post = null, $gmt = false ) {
$post = get_post( $post );
if ( ! $post ) {
return $old_date;
}
$post_date = $gmt ? $post->post_date_gmt : $post->post_date;
return qtranxf_format_time( $format, $post_date, $old_date );
}
// @see get_post_modified_time
function qtranxf_timeModifiedFromPostForCurrentLanguage( $old_date, $format = '', $gmt = false ) {
global $post;
if ( ! $post ) {
return $old_date;
}
$post_date = $gmt ? $post->post_modified_gmt : $post->post_modified;
return qtranxf_format_time( $format, $post_date, $old_date );
}
// @see get_comment_date
function qtranxf_dateFromCommentForCurrentLanguage( $old_date, $format, $comment = null ) {
if ( ! $comment ) {
global $comment; // TODO drop obsolete compatibility with older WP
}
if ( ! $comment ) {
return $old_date;
}
return qtranxf_format_date( $format, $comment->comment_date, $old_date );
}
// @see get_comment_time
function qtranxf_timeFromCommentForCurrentLanguage( $old_date, $format = '', $gmt = false, $translate = true, $comment = null ) {
if ( ! $translate ) {
return $old_date;
}
if ( ! $comment ) {
global $comment; // TODO drop obsolete compatibility with older WP
}
if ( ! $comment ) {
return $old_date;
}
$comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
return qtranxf_format_time( $format, $comment_date, $old_date );
}
/**
* Add date/time filters if the configuration allows it.
*
* @return void
*/
function qtranxf_add_date_time_filters() {
global $q_config;
if ( $q_config['use_strftime'] != QTX_DATE_WP && class_exists( 'IntlDateFormatter' ) ) {
add_filter( 'get_comment_date', 'qtranxf_dateFromCommentForCurrentLanguage', 0, 3 );
add_filter( 'get_comment_time', 'qtranxf_timeFromCommentForCurrentLanguage', 0, 5 );
add_filter( 'get_post_modified_time', 'qtranxf_timeModifiedFromPostForCurrentLanguage', 0, 3 );
add_filter( 'get_the_time', 'qtranxf_timeFromPostForCurrentLanguage', 0, 3 );
add_filter( 'get_the_date', 'qtranxf_dateFromPostForCurrentLanguage', 0, 3 );
add_filter( 'get_the_modified_date', 'qtranxf_dateModifiedFromPostForCurrentLanguage', 0, 2 );
}
}