Changeset 3275729
- Timestamp:
- 04/17/2025 11:22:46 AM (12 months ago)
- Location:
- nepali-date-converter
- Files:
-
- 34 added
- 6 edited
-
tags/3.0.3 (added)
-
tags/3.0.3/inc (added)
-
tags/3.0.3/inc/class (added)
-
tags/3.0.3/inc/class/index.php (added)
-
tags/3.0.3/inc/class/ndc-frontend.php (added)
-
tags/3.0.3/inc/class/ndc-post-date.php (added)
-
tags/3.0.3/inc/frameworks (added)
-
tags/3.0.3/inc/frameworks/nepali-calendar (added)
-
tags/3.0.3/inc/frameworks/nepali-calendar/index.php (added)
-
tags/3.0.3/inc/frameworks/nepali-calendar/nepali-calendar.php (added)
-
tags/3.0.3/inc/functions (added)
-
tags/3.0.3/inc/functions/functions.php (added)
-
tags/3.0.3/inc/functions/index.php (added)
-
tags/3.0.3/inc/hooks (added)
-
tags/3.0.3/inc/hooks/enqueue-scripts.php (added)
-
tags/3.0.3/inc/hooks/index.php (added)
-
tags/3.0.3/inc/hooks/wp-ajax.php (added)
-
tags/3.0.3/inc/hooks/wp-footer.php (added)
-
tags/3.0.3/inc/index.php (added)
-
tags/3.0.3/inc/init.php (added)
-
tags/3.0.3/inc/shortcode (added)
-
tags/3.0.3/inc/shortcode/index.php (added)
-
tags/3.0.3/inc/shortcode/shortcode-nepali-date-converter.php (added)
-
tags/3.0.3/inc/shortcode/shortcode-today-date.php (added)
-
tags/3.0.3/inc/widgets (added)
-
tags/3.0.3/inc/widgets/index.php (added)
-
tags/3.0.3/inc/widgets/widget-nepali-date-converter.php (added)
-
tags/3.0.3/inc/widgets/widget-today-date.php (added)
-
tags/3.0.3/index.php (added)
-
tags/3.0.3/languages (added)
-
tags/3.0.3/languages/index.php (added)
-
tags/3.0.3/languages/nepali-date-converter.pot (added)
-
tags/3.0.3/nepali-date-converter.php (added)
-
tags/3.0.3/readme.txt (added)
-
trunk/inc/class/ndc-frontend.php (modified) (1 diff)
-
trunk/inc/class/ndc-post-date.php (modified) (4 diffs)
-
trunk/inc/frameworks/nepali-calendar/nepali-calendar.php (modified) (14 diffs)
-
trunk/languages/nepali-date-converter.pot (modified) (4 diffs)
-
trunk/nepali-date-converter.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
nepali-date-converter/trunk/inc/class/ndc-frontend.php
r3263598 r3275729 340 340 */ 341 341 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 } 351 364 } 352 365 -
nepali-date-converter/trunk/inc/class/ndc-post-date.php
r3263892 r3275729 637 637 // Determine format to use. 638 638 $result_format = $format && ! $this->options['force_format'] 639 ? $format640 : ( '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'] ); 643 643 644 644 // Handle Unix timestamp format. … … 647 647 } 648 648 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 649 657 // Handle human time diff if enabled. 650 $post_timestamp = strtotime( $post->post_date );651 658 if ( $this->should_use_human_time_diff() ) { 652 659 $current_local_timestamp = strtotime( get_date_from_gmt( gmdate( 'Y-m-d H:i:s' ), 'Y-m-d H:i:s' ) ); … … 655 662 656 663 // 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 ) ); 658 665 659 666 $nepali_date = ndc_eng_to_nep_date( … … 673 680 } 674 681 682 675 683 /** 676 684 * Check if human time diff should be used -
nepali-date-converter/trunk/inc/frameworks/nepali-calendar/nepali-calendar.php
r3263892 r3275729 381 381 private $date_data = array( 382 382 'eng_date' => array( 383 'year' => '',384 'month' => '',385 ' wp_date'=> '',383 'year' => '', 384 'month' => '', 385 'date' => '', 386 386 ), 387 387 'nep_date' => array( 388 'year' => '',389 'month' => '',390 ' wp_date'=> '',388 'year' => '', 389 'month' => '', 390 'date' => '', 391 391 ), 392 392 'from' => '', … … 416 416 417 417 /** 418 * Gets the Nepali wp_date range418 * Gets the Nepali date range 419 419 * 420 420 * @return array First and last years in the Nepali calendar data … … 432 432 433 433 /** 434 * Gets the approximate English wp_date range434 * Gets the approximate English date range 435 435 * 436 436 * @return array Approximate English years corresponding to Nepali range … … 446 446 447 447 /** 448 * Checks if an English wp_date is within the supported range448 * Checks if an English date is within the supported range 449 449 * 450 450 * @param int $year Year. … … 459 459 if ( $year < $english_range['first'] || $year > $english_range['last'] ) { 460 460 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. 462 462 __( 'Supported only between %1$d-%2$d', 'nepali-date-converter' ), 463 463 $english_range['first'], … … 478 478 479 479 /** 480 * Checks if a Nepali wp_date is within the supported range480 * Checks if a Nepali date is within the supported range 481 481 * 482 482 * @param int $year Year. … … 491 491 if ( $year < $nepali_range['first'] || $year > $nepali_range['last'] ) { 492 492 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. 494 494 __( 'Supported only between %1$d-%2$d', 'nepali-date-converter' ), 495 495 $nepali_range['first'], … … 541 541 542 542 /** 543 * Converts English wp_date to Nepali wp_date543 * Converts English date to Nepali date. 544 544 * 545 545 * @param array $input_date Array with year, month, day, hour, min, sec. 546 546 * @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. 549 549 * @since 1.0.0 550 550 */ … … 583 583 $total_days = 0; 584 584 585 // Calculate total days from reference English date.586 585 for ( $y = 0; $y < ( $year - $ref_eng_year ); $y++ ) { 587 586 $total_days += $this->is_leap_year( $ref_eng_year + $y ) ? 366 : 365; 588 587 } 589 588 590 // Add days from months in current year.591 589 $month_days = $this->is_leap_year( $year ) ? $this->leap_month_days : $this->month_days; 592 590 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 597 594 $total_days += $day; 598 595 599 // Convert to Nepali date.600 596 $nep_year = $ref_nep_year; 601 597 $nep_month = $ref_nep_month; … … 627 623 } 628 624 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 ); 650 630 651 631 try { 652 $timezone = wp_timezone(); 653 $datetime = new DateTimeImmutable( $date_str, $timezone ); 632 $datetime = new DateTimeImmutable( $date_str, new DateTimeZone( 'UTC' ) ); 654 633 $timestamp = $datetime->getTimestamp(); 655 634 } catch ( Exception $e ) { … … 657 636 } 658 637 659 // Date format replacements.660 638 $replacements = array( 661 639 'd' => $this->get_two_char_str( $nep_day ), 662 640 '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 ), 665 643 'm' => $this->get_two_char_str( $nep_month ), 666 644 'n' => $nep_month, … … 669 647 'Y' => $nep_year, 670 648 '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 ), 680 658 'c' => sprintf( 681 '%d-% d-%dस%02d:%02d:%02d+00:00',659 '%d-%02d-%02dस%02d:%02d:%02d+00:00', 682 660 $nep_year, 683 661 $nep_month, 684 662 $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 ) 688 666 ), 689 667 'r' => sprintf( 690 '%s, %d %s %d %02d:%02d:%02d +0 200',691 wp_date( 'D', $timestamp ),668 '%s, %d %s %d %02d:%02d:%02d +0000', 669 gmdate( 'D', $timestamp ), 692 670 $nep_day, 693 671 array_keys( $this->short_eng_nep_mth )[ $nep_month - 1 ], 694 672 $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 ) 698 676 ), 699 677 ); … … 701 679 $nepali_date = strtr( $format, $replacements ); 702 680 703 // Temporary placeholders for day names.704 681 $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' ); 723 684 724 685 if ( 'eng_char' === $date_format ) { 725 686 $nepali_date = strtr( $nepali_date, $this->long_eng_nep_mth_in_eng ); 726 687 $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 747 688 $nepali_date = strtr( $nepali_date, $long_day_map ); 748 689 $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 ) 755 708 ); 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 ); 757 716 } else { 758 717 $nepali_date = strtr( $nepali_date, $this->eng_nep_num ); 759 718 $nepali_date = strtr( $nepali_date, $this->long_eng_nep_mth ); 760 719 $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 781 720 $nepali_date = strtr( $nepali_date, $long_day_map ); 782 721 $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 ) 789 740 ); 790 $nepali_date = strtr( $nepali_date, $am_pm_replace ); 741 $nepali_date = strtr( 742 $nepali_date, 743 array( 744 'am' => 'बिहान', 745 'pm' => 'मध्यान्ह', 746 ) 747 ); 791 748 } 792 749 … … 800 757 return $this->date_data; 801 758 } 802 803 759 804 760 /** -
nepali-date-converter/trunk/languages/nepali-date-converter.pot
r3263606 r3275729 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Nepali Date Converter 3.0. 1\n"5 "Project-Id-Version: Nepali Date Converter 3.0.3\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/nepali-date-converter\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 2025-0 3-28T18:35:27+00:00\n"12 "POT-Creation-Date: 2025-04-17T10:34:57+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.6.0\n" … … 38 38 msgstr "" 39 39 40 #: inc/class/ndc-frontend.php:4 0740 #: inc/class/ndc-frontend.php:420 41 41 msgid "To Eng Date" 42 42 msgstr "" 43 43 44 #: inc/class/ndc-frontend.php:4 4044 #: inc/class/ndc-frontend.php:453 45 45 msgid "To Nep Date" 46 46 msgstr "" … … 201 201 msgstr "" 202 202 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. 204 204 #: inc/frameworks/nepali-calendar/nepali-calendar.php:462 205 205 #: inc/frameworks/nepali-calendar/nepali-calendar.php:494 -
nepali-date-converter/trunk/nepali-date-converter.php
r3263892 r3275729 4 4 Plugin URI: https://www.addonspress.com/wordpress-plugins/nepali-date-converter/ 5 5 Description: Convert English to Nepali Date and Vice Versa and Post Date to Nepali Date. 6 Version: 3.0. 26 Version: 3.0.3 7 7 Author: addonspress 8 8 Author URI: https://www.addonspress.com/ … … 17 17 } 18 18 /*Define Constants for this plugin*/ 19 define( 'NEPALI_DATE_CONVERTER_VERSION', '3.0. 2' );19 define( 'NEPALI_DATE_CONVERTER_VERSION', '3.0.3' ); 20 20 define( 'NEPALI_DATE_CONVERTER_PATH', plugin_dir_path( __FILE__ ) ); 21 21 define( 'NEPALI_DATE_CONVERTER_URL', plugin_dir_url( __FILE__ ) ); -
nepali-date-converter/trunk/readme.txt
r3263892 r3275729 4 4 Tags: Nepali post date, Nepali date converter, today Nepali date, English to Nepali date converter, Nepali to English date converter 5 5 Requires at least: 4.9 6 Tested up to: 6. 76 Tested up to: 6.8 7 7 Requires PHP: 7.2 8 Stable tag: 3.0. 28 Stable tag: 3.0.3 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 122 122 == Changelog == 123 123 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 124 129 = 3.0.2 - 2025-03-29 = 125 130 * Fixed: Ensured 0 hour is correctly handled in date formatting
Note: See TracChangeset
for help on using the changeset viewer.