Plugin Directory

Changeset 3674768


Ignore:
Timestamp:
08/31/2026 06:10:32 PM (8 weeks ago)
Author:
manjilshre
Message:

Fix date handling to prevent timezone-related date shifts

Location:
nepali-bs-date-tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • nepali-bs-date-tools/tags/1.0.1/bs_dateClass.php

    r3669018 r3674768  
    174174                        $get_totaldays_nepadate = $this->nepali_date_indays( $get_index_nepdate, $nepalidate_arr[1], $nepalidate_arr[2] );
    175175
    176                         $date_to_add=strtotime("April 14 1943");
    177                         $end = strtotime("+".$get_totaldays_nepadate." days", $date_to_add);
    178                         $engdate = wp_date("M j Y, l", $end);
    179                        
     176                        $wp_timezone = wp_timezone();
     177                        $date = new DateTime( 'April 14 1943', $wp_timezone );
     178                        $days_to_add = (int) $get_totaldays_nepadate;
     179                        $date->modify( "+{$days_to_add} days" );
     180                        $engdate = wp_date( 'M j Y, l', $date->getTimestamp(), $wp_timezone );                 
    180181                        return esc_html($engdate);
    181182                }
    182183
    183                 function get_day($totaldays){
    184                        
    185                         $date_to_add=strtotime("April 14 1943");
    186                         $end = strtotime("+".($totaldays-1)." days", $date_to_add);
    187                         $day = wp_date("w", $end);
    188                        
    189                         return $day;
     184                function get_day($totaldays){                   
     185                       
     186                        $wp_timezone = wp_timezone();                   
     187                        $date = new DateTime( 'April 14 1943', $wp_timezone );                 
     188                        $days_to_add = $totaldays - 1;
     189                        $date->modify( "+{$days_to_add} days" );
     190                        return $date->format( 'w' );
     191
    190192                }
    191193
  • nepali-bs-date-tools/tags/1.0.1/nepali-bs-date-tools.php

    r3669018 r3674768  
    6666    global $NBSD_Dateplugin;
    6767
    68     $dateto_convert = ( $today_date == '' ? wp_date('Y-m-d', strtotime($post->post_date)) : $today_date );
     68    $dateto_convert = ( $today_date == '' ? get_post_datetime( $post )->format( 'Y-m-d' ) : $today_date );
    6969    $nepaliDate  = $NBSD_Dateplugin->NBSD_convertTonepalidate( ['engdate' => $dateto_convert] );
    7070    $nepaliDate = explode(" ", $nepaliDate);
    … …  
    102102        if( $get_bsdate_options['chk_time'] == 1 ){
    103103           
    104             $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(wp_date('H:i', strtotime($post->post_date)));
     104            $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(get_post_datetime( $post )->format( 'H:i' ));
    105105        }
    106106    }
    … …  
    120120                if( $get_bsdate_options['chk_time'] == 1 ){
    121121           
    122                     $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(wp_date('H:i', strtotime($post->post_date)));
     122                    $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(get_post_datetime( $post )->format( 'H:i' ));
    123123                }
    124124
    … …  
    131131                if( $get_bsdate_options['chk_time'] == 1 ){
    132132           
    133                     $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(wp_date('H:i', strtotime($post->post_date)));
     133                    $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(get_post_datetime( $post )->format( 'H:i' ));
    134134                }
    135135               
  • nepali-bs-date-tools/trunk/bs_dateClass.php

    r3554371 r3674768  
    174174                        $get_totaldays_nepadate = $this->nepali_date_indays( $get_index_nepdate, $nepalidate_arr[1], $nepalidate_arr[2] );
    175175
    176                         $date_to_add=strtotime("April 14 1943");
    177                         $end = strtotime("+".$get_totaldays_nepadate." days", $date_to_add);
    178                         $engdate = wp_date("M j Y, l", $end);
    179                        
     176                        $wp_timezone = wp_timezone();
     177                        $date = new DateTime( 'April 14 1943', $wp_timezone );
     178                        $days_to_add = (int) $get_totaldays_nepadate;
     179                        $date->modify( "+{$days_to_add} days" );
     180                        $engdate = wp_date( 'M j Y, l', $date->getTimestamp(), $wp_timezone );                 
    180181                        return esc_html($engdate);
    181182                }
    182183
    183                 function get_day($totaldays){
    184                        
    185                         $date_to_add=strtotime("April 14 1943");
    186                         $end = strtotime("+".($totaldays-1)." days", $date_to_add);
    187                         $day = wp_date("w", $end);
    188                        
    189                         return $day;
     184                function get_day($totaldays){                   
     185                       
     186                        $wp_timezone = wp_timezone();                   
     187                        $date = new DateTime( 'April 14 1943', $wp_timezone );                 
     188                        $days_to_add = $totaldays - 1;
     189                        $date->modify( "+{$days_to_add} days" );
     190                        return $date->format( 'w' );
     191
    190192                }
    191193
  • nepali-bs-date-tools/trunk/nepali-bs-date-tools.php

    r3669018 r3674768  
    6666    global $NBSD_Dateplugin;
    6767
    68     $dateto_convert = ( $today_date == '' ? wp_date('Y-m-d', strtotime($post->post_date)) : $today_date );
     68    $dateto_convert = ( $today_date == '' ? get_post_datetime( $post )->format( 'Y-m-d' ) : $today_date );
    6969    $nepaliDate  = $NBSD_Dateplugin->NBSD_convertTonepalidate( ['engdate' => $dateto_convert] );
    7070    $nepaliDate = explode(" ", $nepaliDate);
    … …  
    102102        if( $get_bsdate_options['chk_time'] == 1 ){
    103103           
    104             $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(wp_date('H:i', strtotime($post->post_date)));
     104            $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(get_post_datetime( $post )->format( 'H:i' ));
    105105        }
    106106    }
    … …  
    120120                if( $get_bsdate_options['chk_time'] == 1 ){
    121121           
    122                     $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(wp_date('H:i', strtotime($post->post_date)));
     122                    $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(get_post_datetime( $post )->format( 'H:i' ));
    123123                }
    124124
    … …  
    131131                if( $get_bsdate_options['chk_time'] == 1 ){
    132132           
    133                     $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(wp_date('H:i', strtotime($post->post_date)));
     133                    $converted_date .= " ".$NBSD_Dateplugin->NBSD_convertTonepalinumber(get_post_datetime( $post )->format( 'H:i' ));
    134134                }
    135135               
Note: See TracChangeset for help on using the changeset viewer.