Plugin Directory

Changeset 3275729


Ignore:
Timestamp:
04/17/2025 11:22:46 AM (12 months ago)
Author:
addonspress
Message:

3.0.3

Location:
nepali-date-converter
Files:
34 added
6 edited

Legend:

Unmodified
Added
Removed
  • nepali-date-converter/trunk/inc/class/ndc-frontend.php

    r3263598 r3275729  
    340340         */
    341341        private function get_current_english_date( string $format ): array {
    342             $date_string = wp_date( 'Y-m-d' );
    343             $dates       = explode( '-', $date_string );
    344 
    345             return array(
    346                 'year'      => (int) $dates[0],
    347                 'month'     => (int) $dates[1],
    348                 'day'       => (int) $dates[2],
    349                 'formatted' => wp_date( $format ),
    350             );
     342            try {
     343                $timezone    = new DateTimeZone( 'Asia/Kathmandu' );
     344                $datetime    = new DateTime( 'now', $timezone );
     345                $date_string = $datetime->format( 'Y-m-d' );
     346                $dates       = explode( '-', $date_string );
     347
     348                return array(
     349                    'year'      => (int) $dates[0],
     350                    'month'     => (int) $dates[1],
     351                    'day'       => (int) $dates[2],
     352                    'formatted' => $datetime->format( $format ),
     353                );
     354            } catch ( Exception $e ) {
     355                // Fallback: return current UTC date.
     356                $dates = explode( '-', gmdate( 'Y-m-d' ) );
     357                return array(
     358                    'year'      => (int) $dates[0],
     359                    'month'     => (int) $dates[1],
     360                    'day'       => (int) $dates[2],
     361                    'formatted' => gmdate( $format ),
     362                );
     363            }
    351364        }
    352365
  • nepali-date-converter/trunk/inc/class/ndc-post-date.php

    r3263892 r3275729  
    637637            // Determine format to use.
    638638            $result_format = $format && ! $this->options['force_format']
    639             ? $format
    640             : ( 'ndc-date-format-custom' !== $this->options['date_format']['selected']
    641                 ? $this->options['date_format']['selected']
    642                 : $this->options['date_format']['custom'] );
     639                ? $format
     640                : ( 'ndc-date-format-custom' !== $this->options['date_format']['selected']
     641            ? $this->options['date_format']['selected']
     642            : $this->options['date_format']['custom'] );
    643643
    644644            // Handle Unix timestamp format.
     
    647647            }
    648648
     649            try {
     650                $date = new DateTime( $the_date );
     651                $date->setTimezone( new DateTimeZone( 'Asia/Kathmandu' ) );
     652                $post_timestamp = $date->getTimestamp();
     653            } catch ( Exception $e ) {
     654                return $the_date;
     655            }
     656
    649657            // Handle human time diff if enabled.
    650             $post_timestamp = strtotime( $post->post_date );
    651658            if ( $this->should_use_human_time_diff() ) {
    652659                $current_local_timestamp = strtotime( get_date_from_gmt( gmdate( 'Y-m-d H:i:s' ), 'Y-m-d H:i:s' ) );
     
    655662
    656663            // Convert to Nepali date.
    657             $date_parts = explode( '-', wp_date( 'Y-m-d-H-i-s', $post_timestamp ) );
     664            $date_parts = explode( '-', gmdate( 'Y-m-d-H-i-s', $post_timestamp ) );
    658665
    659666            $nepali_date = ndc_eng_to_nep_date(
     
    673680        }
    674681
     682
    675683        /**
    676684         * Check if human time diff should be used
  • nepali-date-converter/trunk/inc/frameworks/nepali-calendar/nepali-calendar.php

    r3263892 r3275729  
    381381        private $date_data = array(
    382382            'eng_date' => array(
    383                 'year'    => '',
    384                 'month'   => '',
    385                 'wp_date' => '',
     383                'year'  => '',
     384                'month' => '',
     385                'date' => '',
    386386            ),
    387387            'nep_date' => array(
    388                 'year'    => '',
    389                 'month'   => '',
    390                 'wp_date' => '',
     388                'year'  => '',
     389                'month' => '',
     390                'date' => '',
    391391            ),
    392392            'from'     => '',
     
    416416
    417417        /**
    418          * Gets the Nepali wp_date range
     418         * Gets the Nepali date range
    419419         *
    420420         * @return array First and last years in the Nepali calendar data
     
    432432
    433433        /**
    434          * Gets the approximate English wp_date range
     434         * Gets the approximate English date range
    435435         *
    436436         * @return array Approximate English years corresponding to Nepali range
     
    446446
    447447        /**
    448          * Checks if an English wp_date is within the supported range
     448         * Checks if an English date is within the supported range
    449449         *
    450450         * @param int $year Year.
     
    459459            if ( $year < $english_range['first'] || $year > $english_range['last'] ) {
    460460                return sprintf(
    461                 // translators: %1$d represents the first year, %2$d represents the last year in the supported Nepali wp_date range.
     461                // translators: %1$d represents the first year, %2$d represents the last year in the supported Nepali date range.
    462462                    __( 'Supported only between %1$d-%2$d', 'nepali-date-converter' ),
    463463                    $english_range['first'],
     
    478478
    479479        /**
    480          * Checks if a Nepali wp_date is within the supported range
     480         * Checks if a Nepali date is within the supported range
    481481         *
    482482         * @param int $year Year.
     
    491491            if ( $year < $nepali_range['first'] || $year > $nepali_range['last'] ) {
    492492                return sprintf(
    493                 // translators: %1$d represents the first year, %2$d represents the last year in the supported Nepali wp_date range.
     493                // translators: %1$d represents the first year, %2$d represents the last year in the supported Nepali date range.
    494494                    __( 'Supported only between %1$d-%2$d', 'nepali-date-converter' ),
    495495                    $nepali_range['first'],
     
    541541
    542542        /**
    543          * Converts English wp_date to Nepali wp_date
     543         * Converts English date to Nepali date.
    544544         *
    545545         * @param array  $input_date Array with year, month, day, hour, min, sec.
    546546         * @param string $date_format Output format ('nep_char' or 'eng_char').
    547          * @param string $format PHP wp_date format string.
    548          * @return array Converted wp_date data.
     547         * @param string $format PHP date format string.
     548         * @return array Converted date data.
    549549         * @since 1.0.0
    550550         */
     
    583583            $total_days = 0;
    584584
    585             // Calculate total days from reference English date.
    586585            for ( $y = 0; $y < ( $year - $ref_eng_year ); $y++ ) {
    587586                $total_days += $this->is_leap_year( $ref_eng_year + $y ) ? 366 : 365;
    588587            }
    589588
    590             // Add days from months in current year.
    591589            $month_days = $this->is_leap_year( $year ) ? $this->leap_month_days : $this->month_days;
    592590            for ( $m = 0; $m < ( $month - 1 ); $m++ ) {
    593                 $total_days += $month_days [ $m ];
    594             }
    595 
    596             // Add days in current month.
     591                $total_days += $month_days[ $m ];
     592            }
     593
    597594            $total_days += $day;
    598595
    599             // Convert to Nepali date.
    600596            $nep_year  = $ref_nep_year;
    601597            $nep_month = $ref_nep_month;
     
    627623            }
    628624
    629             /*
    630             Format the date.
    631             * no supported
    632             S, c, r, U
    633             may be c= $y.'-'.$m.'-'.$np_date.'स'.wp_date('H',$create_date).':'.wp_date('i',$create_date).':'.wp_date('s',$create_date).'+00:00',
    634             */
    635             $hour = $input_date['hour'] ?? '';
    636             $min  = $input_date['min'] ?? '';
    637             $sec  = $input_date['sec'] ?? '';
    638 
    639             $date_str = sprintf( '%d-%d-%d', $year, $month, $day );
    640 
    641             if ( isset( $hour ) ) {
    642                 $date_str .= sprintf( ' %02d', $hour );
    643                 if ( isset( $min ) ) {
    644                     $date_str .= sprintf( ':%02d', $min );
    645                     if ( isset( $sec ) ) {
    646                         $date_str .= sprintf( ':%02d', $sec );
    647                     }
    648                 }
    649             }
     625            $hour = $input_date['hour'] ?? 0;
     626            $min  = $input_date['min'] ?? 0;
     627            $sec  = $input_date['sec'] ?? 0;
     628
     629            $date_str = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $year, $month, $day, $hour, $min, $sec );
    650630
    651631            try {
    652                 $timezone  = wp_timezone();
    653                 $datetime  = new DateTimeImmutable( $date_str, $timezone );
     632                $datetime  = new DateTimeImmutable( $date_str, new DateTimeZone( 'UTC' ) );
    654633                $timestamp = $datetime->getTimestamp();
    655634            } catch ( Exception $e ) {
     
    657636            }
    658637
    659             // Date format replacements.
    660638            $replacements = array(
    661639                'd' => $this->get_two_char_str( $nep_day ),
    662640                'j' => $nep_day,
    663                 'l' => wp_date( 'l', $timestamp ),
    664                 'D' => wp_date( 'D', $timestamp ),
     641                'l' => gmdate( 'l', $timestamp ),
     642                'D' => gmdate( 'D', $timestamp ),
    665643                'm' => $this->get_two_char_str( $nep_month ),
    666644                'n' => $nep_month,
     
    669647                'Y' => $nep_year,
    670648                'y' => substr( $nep_year, 2 ),
    671                 'a' => wp_date( 'a', $timestamp ),
    672                 'A' => wp_date( 'A', $timestamp ),
    673                 'g' => wp_date( 'g', $timestamp ),
    674                 'h' => wp_date( 'h', $timestamp ),
    675                 'G' => wp_date( 'G', $timestamp ),
    676                 'H' => wp_date( 'H', $timestamp ),
    677                 'i' => wp_date( 'i', $timestamp ),
    678                 's' => wp_date( 's', $timestamp ),
    679                 'T' => wp_date( 'T', $timestamp ),
     649                'a' => gmdate( 'a', $timestamp ),
     650                'A' => gmdate( 'A', $timestamp ),
     651                'g' => gmdate( 'g', $timestamp ),
     652                'h' => gmdate( 'h', $timestamp ),
     653                'G' => gmdate( 'G', $timestamp ),
     654                'H' => gmdate( 'H', $timestamp ),
     655                'i' => gmdate( 'i', $timestamp ),
     656                's' => gmdate( 's', $timestamp ),
     657                'T' => gmdate( 'T', $timestamp ),
    680658                'c' => sprintf(
    681                     '%d-%d-%dस%02d:%02d:%02d+00:00',
     659                    '%d-%02d-%02dस%02d:%02d:%02d+00:00',
    682660                    $nep_year,
    683661                    $nep_month,
    684662                    $nep_day,
    685                     wp_date( 'H', $timestamp ),
    686                     wp_date( 'i', $timestamp ),
    687                     wp_date( 's', $timestamp )
     663                    gmdate( 'H', $timestamp ),
     664                    gmdate( 'i', $timestamp ),
     665                    gmdate( 's', $timestamp )
    688666                ),
    689667                'r' => sprintf(
    690                     '%s, %d %s %d %02d:%02d:%02d +0200',
    691                     wp_date( 'D', $timestamp ),
     668                    '%s, %d %s %d %02d:%02d:%02d +0000',
     669                    gmdate( 'D', $timestamp ),
    692670                    $nep_day,
    693671                    array_keys( $this->short_eng_nep_mth )[ $nep_month - 1 ],
    694672                    $nep_year,
    695                     wp_date( 'H', $timestamp ),
    696                     wp_date( 'i', $timestamp ),
    697                     wp_date( 's', $timestamp )
     673                    gmdate( 'H', $timestamp ),
     674                    gmdate( 'i', $timestamp ),
     675                    gmdate( 's', $timestamp )
    698676                ),
    699677            );
     
    701679            $nepali_date = strtr( $format, $replacements );
    702680
    703             // Temporary placeholders for day names.
    704681            $day_placeholder = 'day' . $day_of_week;
    705             $long_day_map    = array(
    706                 'Sunday'    => $day_placeholder . '_long',
    707                 'Monday'    => $day_placeholder . '_long',
    708                 'Tuesday'   => $day_placeholder . '_long',
    709                 'Wednesday' => $day_placeholder . '_long',
    710                 'Thursday'  => $day_placeholder . '_long',
    711                 'Friday'    => $day_placeholder . '_long',
    712                 'Saturday'  => $day_placeholder . '_long',
    713             );
    714             $short_day_map   = array(
    715                 'Sun' => $day_placeholder . '_short',
    716                 'Mon' => $day_placeholder . '_short',
    717                 'Tue' => $day_placeholder . '_short',
    718                 'Wed' => $day_placeholder . '_short',
    719                 'Thu' => $day_placeholder . '_short',
    720                 'Fri' => $day_placeholder . '_short',
    721                 'Sat' => $day_placeholder . '_short',
    722             );
     682            $long_day_map    = array_fill_keys( array( 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ), $day_placeholder . '_long' );
     683            $short_day_map   = array_fill_keys( array( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ), $day_placeholder . '_short' );
    723684
    724685            if ( 'eng_char' === $date_format ) {
    725686                $nepali_date = strtr( $nepali_date, $this->long_eng_nep_mth_in_eng );
    726687                $nepali_date = strtr( $nepali_date, $this->short_eng_nep_mth_in_eng );
    727 
    728                 $long_day_replace  = array(
    729                     'day1_long' => 'Aaitabar',
    730                     'day2_long' => 'Sombar',
    731                     'day3_long' => 'Mangalbar',
    732                     'day4_long' => 'Budhabar',
    733                     'day5_long' => 'Bihibar',
    734                     'day6_long' => 'Sukrabar',
    735                     'day7_long' => 'Sanibar',
    736                 );
    737                 $short_day_replace = array(
    738                     'day1_short' => 'Aaita',
    739                     'day2_short' => 'Som',
    740                     'day3_short' => 'Mangal',
    741                     'day4_short' => 'Budha',
    742                     'day5_short' => 'Bihi',
    743                     'day6_short' => 'Sukra',
    744                     'day7_short' => 'Sani',
    745                 );
    746 
    747688                $nepali_date = strtr( $nepali_date, $long_day_map );
    748689                $nepali_date = strtr( $nepali_date, $short_day_map );
    749                 $nepali_date = strtr( $nepali_date, $long_day_replace );
    750                 $nepali_date = strtr( $nepali_date, $short_day_replace );
    751 
    752                 $am_pm_replace = array(
    753                     'am' => 'Bihana',
    754                     'pm' => 'Madhyanha',
     690                $nepali_date = strtr(
     691                    $nepali_date,
     692                    array(
     693                        'day1_long'  => 'Aaitabar',
     694                        'day2_long'  => 'Sombar',
     695                        'day3_long'  => 'Mangalbar',
     696                        'day4_long'  => 'Budhabar',
     697                        'day5_long'  => 'Bihibar',
     698                        'day6_long'  => 'Sukrabar',
     699                        'day7_long'  => 'Sanibar',
     700                        'day1_short' => 'Aaita',
     701                        'day2_short' => 'Som',
     702                        'day3_short' => 'Mangal',
     703                        'day4_short' => 'Budha',
     704                        'day5_short' => 'Bihi',
     705                        'day6_short' => 'Sukra',
     706                        'day7_short' => 'Sani',
     707                    )
    755708                );
    756                 $nepali_date   = strtr( $nepali_date, $am_pm_replace );
     709                $nepali_date = strtr(
     710                    $nepali_date,
     711                    array(
     712                        'am' => 'Bihana',
     713                        'pm' => 'Madhyanha',
     714                    )
     715                );
    757716            } else {
    758717                $nepali_date = strtr( $nepali_date, $this->eng_nep_num );
    759718                $nepali_date = strtr( $nepali_date, $this->long_eng_nep_mth );
    760719                $nepali_date = strtr( $nepali_date, $this->short_eng_nep_mth );
    761 
    762                 $long_day_replace  = array(
    763                     'day1_long' => 'आइतवार',
    764                     'day2_long' => 'सोमवार',
    765                     'day3_long' => 'मङ्लबार',
    766                     'day4_long' => 'बुधबार',
    767                     'day5_long' => 'बिहिबार',
    768                     'day6_long' => 'शुक्रबार',
    769                     'day7_long' => 'शनिबार',
    770                 );
    771                 $short_day_replace = array(
    772                     'day1_short' => 'आइत',
    773                     'day2_short' => 'सोम',
    774                     'day3_short' => 'मङ्ल',
    775                     'day4_short' => 'बुध',
    776                     'day5_short' => 'बिहि',
    777                     'day6_short' => 'शुक्र',
    778                     'day7_short' => 'शनि',
    779                 );
    780 
    781720                $nepali_date = strtr( $nepali_date, $long_day_map );
    782721                $nepali_date = strtr( $nepali_date, $short_day_map );
    783                 $nepali_date = strtr( $nepali_date, $long_day_replace );
    784                 $nepali_date = strtr( $nepali_date, $short_day_replace );
    785 
    786                 $am_pm_replace = array(
    787                     'am' => 'बिहान',
    788                     'pm' => 'मध्यान्ह',
     722                $nepali_date = strtr(
     723                    $nepali_date,
     724                    array(
     725                        'day1_long'  => 'आइतवार',
     726                        'day2_long'  => 'सोमवार',
     727                        'day3_long'  => 'मङ्लबार',
     728                        'day4_long'  => 'बुधबार',
     729                        'day5_long'  => 'बिहिबार',
     730                        'day6_long'  => 'शुक्रबार',
     731                        'day7_long'  => 'शनिबार',
     732                        'day1_short' => 'आइत',
     733                        'day2_short' => 'सोम',
     734                        'day3_short' => 'मङ्ल',
     735                        'day4_short' => 'बुध',
     736                        'day5_short' => 'बिहि',
     737                        'day6_short' => 'शुक्र',
     738                        'day7_short' => 'शनि',
     739                    )
    789740                );
    790                 $nepali_date   = strtr( $nepali_date, $am_pm_replace );
     741                $nepali_date = strtr(
     742                    $nepali_date,
     743                    array(
     744                        'am' => 'बिहान',
     745                        'pm' => 'मध्यान्ह',
     746                    )
     747                );
    791748            }
    792749
     
    800757            return $this->date_data;
    801758        }
    802 
    803759
    804760        /**
  • nepali-date-converter/trunk/languages/nepali-date-converter.pot

    r3263606 r3275729  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Nepali Date Converter 3.0.1\n"
     5"Project-Id-Version: Nepali Date Converter 3.0.3\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/nepali-date-converter\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2025-03-28T18:35:27+00:00\n"
     12"POT-Creation-Date: 2025-04-17T10:34:57+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.6.0\n"
     
    3838msgstr ""
    3939
    40 #: inc/class/ndc-frontend.php:407
     40#: inc/class/ndc-frontend.php:420
    4141msgid "To Eng Date"
    4242msgstr ""
    4343
    44 #: inc/class/ndc-frontend.php:440
     44#: inc/class/ndc-frontend.php:453
    4545msgid "To Nep Date"
    4646msgstr ""
     
    201201msgstr ""
    202202
    203 #. translators: %1$d represents the first year, %2$d represents the last year in the supported Nepali wp_date range.
     203#. translators: %1$d represents the first year, %2$d represents the last year in the supported Nepali date range.
    204204#: inc/frameworks/nepali-calendar/nepali-calendar.php:462
    205205#: inc/frameworks/nepali-calendar/nepali-calendar.php:494
  • nepali-date-converter/trunk/nepali-date-converter.php

    r3263892 r3275729  
    44Plugin URI: https://www.addonspress.com/wordpress-plugins/nepali-date-converter/
    55Description: Convert English to Nepali Date and Vice Versa and Post Date to Nepali Date.
    6 Version: 3.0.2
     6Version: 3.0.3
    77Author: addonspress
    88Author URI: https://www.addonspress.com/
     
    1717}
    1818/*Define Constants for this plugin*/
    19 define( 'NEPALI_DATE_CONVERTER_VERSION', '3.0.2' );
     19define( 'NEPALI_DATE_CONVERTER_VERSION', '3.0.3' );
    2020define( 'NEPALI_DATE_CONVERTER_PATH', plugin_dir_path( __FILE__ ) );
    2121define( 'NEPALI_DATE_CONVERTER_URL', plugin_dir_url( __FILE__ ) );
  • nepali-date-converter/trunk/readme.txt

    r3263892 r3275729  
    44Tags: Nepali post date, Nepali date converter, today Nepali date, English to Nepali date converter, Nepali to English date converter
    55Requires at least: 4.9
    6 Tested up to: 6.7
     6Tested up to: 6.8
    77Requires PHP: 7.2
    8 Stable tag: 3.0.2
     8Stable tag: 3.0.3
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    122122== Changelog ==
    123123
     124= 3.0.3 - 2025-04-17 =
     125* Added: WordPress latest compatibility
     126* Fixed: Adjusted post date to 5:45 AM in Kathmandu time zone before converting to Nepali date format. 
     127* Fixed: Replaced `date()` with `gmdate()` to ensure UTC-based date formatting and avoid time zone issues.
     128
    124129= 3.0.2 - 2025-03-29 =
    125130* Fixed: Ensured 0 hour is correctly handled in date formatting
Note: See TracChangeset for help on using the changeset viewer.