From 3194616888272ef648ca0a8fe370ddc99a48d0b5 Mon Sep 17 00:00:00 2001 From: bruno Date: Fri, 16 Jun 2023 14:13:45 -0400 Subject: [PATCH] =?UTF-8?q?Fun=C3=A7=C3=B5es=20para=20converter=20stftime?= =?UTF-8?q?=20para=20DateTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/util/util.php | 96 +++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/include/util/util.php b/include/util/util.php index 67f5c1f9..e1ffb643 100644 --- a/include/util/util.php +++ b/include/util/util.php @@ -2454,15 +2454,16 @@ function AjustaPerfil() { */ function strftime_( $format, $timestamp = null ){ - $date_immutable = new DateTimeImmutable( ); - - if( $timestamp ){ - $date_immutable = $date_immutable->setTimestamp( $timestamp ); - } + $date_immutable = new DateTimeImmutable( ); + if( $timestamp ){ + $date_immutable = $date_immutable->setTimestamp( $timestamp ); + } - /* tratar string */ + /* tratar string */ + $str_converted = convert_format_strftime( $format ); + return $date_immutable->format( $str_converted ); } @@ -2474,51 +2475,48 @@ function strftime_( $format, $timestamp = null ){ */ function convert_format_strftime( $format ){ - $id = 0; - - /* formato strftime */ - $patterns = array( - /* day */ - '%a', '%A', '%d','%e', '%j','%u', '%w', - /* Week */ - '%U', '%V','%W', - /* Month */ - '%b','%B', '%h','%m' , - /* Year */ - '%C','%g', '%G','%y', '%Y', - /* Time */ - '%H', '%k', '%I', '%l', '%L', '%M', '%p', '%P', '%r', '%R', '%S', - '%T','%X', '%z','%Z' , - /* Time and Date Stamps */ - '%c','%D', '%F','%s', '%x','%n', - '%t','%%' - ); - - /* valores similares de strftime - * para DateTime - * - */ - $replacements = array( - /* day */ - 'D', 'l', 'd', 'j', 'z', 'N', 'w', - /* Week */ - 'W', '', '', - /* mounth */ - 'M', 'F', 'M', 'm', - /* Year */ - '', 'y', 'o', 'y', 'o', - /* Time */ - 'H', 'G', 'h', 'g', 'g', 'i', 'A', 'a', '', '', 'i', - '', '', '', '', - /* Time and Date Stamps */ - '','', '','', '','', - ' ','\%' - ); - - + $id = 0; + + /* formato strftime */ + $patterns = array( + /* day */ + '/%a/', '/%A/', '/%d/','/%e/', '/%j/','/%u/', '/%w/', + /* Week */ + '/%U/', '/%V/','/%W/', + /* Month */ + '/%b/','/%B/', '/%h/','/%m/', + /* Year */ + '/%C/','/%g/', '/%G/','/%y/', '/%Y/', + /* Time */ + '/%H/', '/%k/', '/%I/', '/%l/', '/%M/', '/%p/', '/%P/', '/%r/', '/%R/', '/%S/', + '/%T/','/%X/', '/%z/','/%Z/', + /* Time and Date Stamps */ + '/%c/','/%D/', '/%F/','/%s/', '/%x/','/%n/', + '/%t/','/%%/' + ); - echo preg_replace( $patterns, $replacements, $format ); + /* valores similares de strftime + * para DateTime + * + */ + $replacements = array( + /* day */ + 'D', 'l', 'd', 'j', 'z', 'N', 'w', + /* Week */ + 'W', '', '', + /* mounth */ + 'M', 'F', 'M', 'm', + /* Year */ + '', 'y', 'o', 'y', 'o', + /* Time */ + 'H', 'G', 'h', ' g', 'i', 'A', 'a', '', '', 's', + '', '', '', '', + /* Time and Date Stamps */ + '','', '','', '','', + ' ','%' + ); + return preg_replace( $patterns, $replacements, $format ); }