Plugin Directory

Changeset 2335674


Ignore:
Timestamp:
07/05/2020 03:01:54 PM (6 years ago)
Author:
nyasro
Message:

fixing some deprecated code..

Location:
nyasro-nepali-date-converter/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • nyasro-nepali-date-converter/trunk/Nyasro_NDC_Class.php

    r950600 r2335674  
    11<?php
     2 
     3  class Nyasro_NepaliDateConverter {
     4   
     5    public $nep_month = [
     6      'Baisakh',
     7      'Jestha',
     8      'Asar',
     9      'Sharwan',
     10      'Bhadra',
     11      'Asoj',
     12      'Kartik',
     13      'Mansir',
     14      'Poush',
     15      'Magh',
     16      'Falgun',
     17      'Chaitra'
     18    ];
     19    public $eng_month = [
     20      "January",
     21      "February",
     22      "March",
     23      "April",
     24      "May",
     25      "June",
     26      "July",
     27      "August",
     28      "September",
     29      "October",
     30      "November",
     31      "December"
     32    ];
     33    private $eng_day = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
     34    private $dnep_month = [
     35      'बैशाख',
     36      'जेष्ठ',
     37      'असार',
     38      'साउन',
     39      'भदौ',
     40      'अशोज',
     41      'कार्तिक',
     42      'मंसिर',
     43      'पुस',
     44      'माघ',
     45      'फाल्गुन',
     46      'चैत्र'
     47    ];
     48    private $dnep_day = [ 'आइतवार', 'सोमवार', 'मङ्लबार', 'बुधबार', 'बिहिबार', 'शुक्रबार', 'शनिबार' ];
     49    private $eng2nep = [
     50      '0' => '०',
     51      '1' => '१',
     52      '2' => '२',
     53      '3' => '३',
     54      '4' => '४',
     55      '5' => '५',
     56      '6' => '६',
     57      '7' => '७',
     58      '8' => '८',
     59      '9' => '९',
     60    ];
     61   
     62    private $counter = 0;
     63   
     64   
     65    public function __construct( $f ) {
     66      add_action('wp_enqueue_scripts', [ $this, 'Ny_dateConvertStyle' ]);
     67      add_action('wp_ajax_nopriv_Ny_DateConvert', [ $this, 'Ny_Ajax_dateConvert' ]);
     68      add_action('wp_ajax_Ny_DateConvert', [ $this, 'Ny_Ajax_dateConvert' ]);
     69      add_action('widgets_init', [ $this, 'Ny_registerWidget' ]);
     70      add_shortcode(NY_NDCSC, [ $this, 'Ny_dateConvertSC' ]);
     71      add_shortcode(NY_NDCWSC, [ $this, 'Ny_dateConvertWidgetSC' ]);
     72      register_activation_hook($f, [ $this, 'Ny_chkPlg' ]);
     73    }
     74   
     75    ///////////////// DATE DONVERT SOHOTCODE FUNCTION
     76   
     77    public function Ny_dateConvertSC( $atts ) {
     78     
     79      if ( ! is_array($atts) ) {
     80        $atts = [];
     81      }
     82     
     83      if ( ! isset($atts[ 'date' ]) or ! $atts[ 'date' ] ) {
     84        $atts[ 'date' ] = date('Y-m-d');
     85      }
     86     
     87      if ( ! isset($atts[ 'convert' ]) or ! $atts[ 'convert' ] ) {
     88        $atts[ 'convert' ] = 'eng_to_nep';
     89      }
     90      $a = isset($atts[ 'array' ]) ? $atts[ 'array' ] : '';
     91      if ( $atts[ 'convert' ] === 'eng_to_nep' or $atts[ 'convert' ] === 'nep_to_eng' ) {
     92        return $this->Ny_dateConvert($atts[ 'date' ], $atts[ 'convert' ], $a);
     93      } else {
     94        return 'Invalid Conversion Type';
     95      }
     96     
     97     
     98    }
     99   
     100    public function Ny_chkPlg() {
     101      add_option('ny_date_convert', 'yes');
     102      $this->ny_dtcl();
     103    }
     104   
     105    //////////////////// DATE CONVERT MAIN FUNCTION
     106   
     107    public function Ny_dateConvert( $date, $conversion, $return ) {
     108      $date    = trim($date);
     109      $convert = trim($conversion);
     110     
     111      $date = explode('-', $date);
     112     
     113      $valid = $this->Ny_dateConvertCheck($date, $convert);
     114     
     115      if ( $valid ) {
     116        return $this->Ny_dateConvertError($valid);
     117      }
     118     
     119      $postdata = "year=$date[0]&month=$date[1]&day=$date[2]&convert=$convert";
     120      $postdata .= '&product=' . NY_NDC_PRODUCT_NAME;
     121     
     122      $data = nyasro_convert_date($postdata);
     123     
     124      if ( ! $data ) {
     125        return $this->Ny_dateConvertError('License failed');
     126      } else if ( $data === '-' ) {
     127        if ( $convert === 'eng_to_nep' ) {
     128          return $this->Ny_dateConvertError('Input English Date may be Out of range. (valid:1944 - 2033 AD)');
     129        }
     130        if ( $convert === 'nep_to_eng' ) {
     131          return $this->Ny_dateConvertError('Input Nepali Date may be Out of range. (valid:2000 - 2089 BS)');
     132        }
     133      }
     134     
     135      $data = $this->Ny_changeDateText($data, $convert, $return);
     136     
     137      return $data;
     138    }
     139   
     140    ////////////// DATE CONVERT CHANGE TEXT
     141   
     142    private function Ny_changeDateText( $date, $convert, $return ) {
     143      $date_arr   = explode('-', $date);
     144      $returndate = [];
     145     
     146     
     147      if ( $convert === 'eng_to_nep' ) {
     148        $datecon = $this->dnep_day[ $date_arr[ 0 ] - 1 ] . ', '
     149                   . $this->dnep_month[ $date_arr[ 2 ] - 1 ] . ' '
     150                   . $date_arr[ 1 ] . ', ' . $date_arr[ 3 ];
     151        $date    = strtr($datecon, $this->eng2nep);
     152      } else if ( $convert === 'nep_to_eng' ) {
     153        $date = $this->eng_day[ $date_arr[ 0 ] - 1 ] . ', '
     154                . $this->eng_month[ $date_arr[ 2 ] - 1 ] . ' '
     155                . $date_arr[ 1 ] . ', ' . $date_arr[ 3 ];
     156      };
     157      $returndate[ 'date' ] = $date;
     158      if ( $return ) {
     159        $returndate[ 'array' ] = $date_arr;
     160        return $returndate;
     161      }
     162      return $returndate[ 'date' ];
     163     
     164    }
     165   
     166    ////////////// DATE CONVERT WIDGET FUNCTIO
     167   
     168    public function Ny_dateConvertWidgetSC( $atts = [] ) {
     169      $this->counter = $this->counter + 1;
     170      $wid           = $this->counter;
     171      $today         = [ 'date' => date('Y-m-d'), 'convert' => 'eng_to_nep', 'array' => true ];
     172      ob_start();
     173       Nyasro_displayWidget($wid, $this->Ny_dateConvertSC($today));
     174      return ob_get_clean();
     175    }
     176   
     177    /////////////// DATE CONVERT STYLE
     178   
     179    public function Ny_dateConvertStyle() {
     180      wp_register_style('Ny_dateConvertCSS', plugins_url('Nyasro_NDC_Style.css', __FILE__));
     181      wp_register_script('Ny_dateConvertJS', plugins_url('Nyasro_NDC_Script.js', __FILE__));
     182      wp_enqueue_style('Ny_dateConvertCSS');
     183      wp_enqueue_script('jquery');
     184    }
     185   
     186    public function Ny_registerWidget() {
     187      register_widget('Nyasro_NepaliDateConverterWidget');
     188    }
     189   
     190    /////////////// DATE CONVERT AJAX
     191   
     192    public function Ny_Ajax_dateConvert() {
     193      $date = $_POST[ 'year' ] . '-' . $_POST[ 'month' ] . '-' . $_POST[ 'day' ];
     194      echo $this->Ny_dateConvertSC([ 'date' => $date, 'convert' => $_POST[ 'convert' ] ]);
     195      exit;
     196    }
     197   
     198    private function ny_dtcl() { }
     199   
     200    /////////////// DEATE CONVERT CHECK RANGE
     201   
     202    private function Ny_dateConvertCheck( $date, $convert ) {
     203      $year  = (int)$date [ 0 ];
     204      $month = (int)$date [ 1 ];
     205      $day   = (int)$date [ 2 ];
     206      $error = false;
     207     
     208      switch ( $convert ) {
     209        case 'nep_to_eng':
     210          if ( $year > 2089 || $year < 2000 ) {
     211            $error = 'Invalid Year';
     212          } else if ( $month > 12 || $month < 1 ) {
     213            $error = 'Invalid Month';
     214          } else if ( $day > 32 || $day < 1 ) {
     215            $error = 'Invalid Day';
     216          }
     217          break;
     218       
     219        case 'eng_to_nep':
     220          if ( $year > 2033 || $year < 1944 ) {
     221            $error = 'Invalid Year';
     222          } else if ( $month > 12 || $month < 1 ) {
     223            $error = 'Invalid Month';
     224          } else if ( $day > 31 || $day < 1 ) {
     225            $error = 'Invalid Day';
     226          }
     227          break;
     228      }
     229      return $error;
     230    }
     231   
     232    //////////////// DATE CONVERT DISPLAY ERROR
     233   
     234    private function Ny_dateConvertError( $msg ) {
     235      echo '<span style="color:#C00;">' . PRODUCT_NAME . '::' . $msg . '</span>';
     236    }
     237   
     238   
     239  }
    2240
    3     class Nyasro_NepaliDateConverter
    4     {
    5        
    6         public  $nep_month  = array('Baisakh','Jestha','Asar','Sharwan','Bhadra','Asoj','Kartik','Mansir','Poush','Magh','Falgun','Chaitra');
    7         public  $eng_month  = array("January","February","March","April","May","June","July","August","September","October","November","December");
    8         private $eng_day    = array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    9         private $dnep_month = array('बैशाख','जेष्ठ','असार','साउन','भदौ','अशोज','कार्तिक','मंसिर','पुस','माघ','फाल्गुन','चैत्र');
    10         private $dnep_day   = array('आइतवार','सोमवार','मङ्लबार','बुधबार','बिहिबार','शुक्रबार','शनिबार');
    11         private $eng2nep    = array('0'=>'०','1'=>'१','2'=>'२','3'=>'३','4'=>'४','5'=>'५','6'=>'६','7'=>'७','8'=>'८','9'=>'९',);
    12 
    13         private $counter    = 0;
    14        
    15                
    16         public function __construct( $f )
    17         {
    18             add_action('wp_enqueue_scripts', array($this,'Ny_dateConvertStyle'));
    19             add_action('wp_ajax_nopriv_Ny_DateConvert',array($this,'Ny_Ajax_dateConvert'));
    20             add_action('wp_ajax_Ny_DateConvert',array($this,'Ny_Ajax_dateConvert'));
    21             add_action('widgets_init',array($this,'Ny_registerWidget'));
    22             add_shortcode(NY_NDCSC,array($this,'Ny_dateConvertSC'));
    23             add_shortcode(NY_NDCWSC,array($this,'Ny_dateConvertWidgetSC'));
    24       register_activation_hook( $f, array($this,'Ny_chkPlg') );
    25         }
    26        
    27         ///////////////// DATE DONVERT SOHOTCODE FUNCTION
    28        
    29         public function Ny_dateConvertSC( $atts )
    30         {
    31             if(!isset($atts['date']) or !$atts['date'])
    32                 $atts['date']       = date('Y-m-d');
    33                
    34             if(!isset($atts['convert']) or !$atts['convert'])
    35             {
    36                 $atts['convert']    = 'eng_to_nep';
    37             }
    38             $a = isset($atts['array'])?$atts['array']:'';
    39             if($atts['convert']==='eng_to_nep' or $atts['convert']==='nep_to_eng')
    40                 return $this->Ny_dateConvert($atts['date'],$atts['convert'],$a);
    41                
    42             else    return 'Invalid Conversion Type';
    43            
    44 
    45         }
    46    
    47     public function Ny_chkPlg()
    48     {
    49       add_option('ny_date_convert','yes');
    50       $this->ny_dtcl();
    51     }
    52        
    53         //////////////////// DATE CONVERT MAIN FUNCTION
    54        
    55         public function Ny_dateConvert( $date , $conversion, $return )
    56         {
    57             $date       = trim($date);         
    58             $convert    = trim($conversion);
    59            
    60             $date       = explode('-',$date);
    61            
    62             $valid      = $this->Ny_dateConvertCheck( $date , $convert );
    63            
    64             if($valid)
    65                 return $this->Ny_dateConvertError( $valid );
    66            
    67             $postdata   = "year=$date[0]&month=$date[1]&day=$date[2]&convert=$convert";
    68             $postdata   .= '&product='.NY_NDC_PRODUCT_NAME;
    69            
    70             $data = nyasro_convert_date($postdata);
    71 
    72             if(!$data)
    73                 return $this->Ny_dateConvertError('License failed');
    74             elseif($data==='-')
    75             {
    76                 if($convert === 'eng_to_nep')
    77                     return $this->Ny_dateConvertError('Input English Date may be Out of range. (valid:1944 - 2033 AD)');
    78                 if($convert === 'nep_to_eng')
    79                     return $this->Ny_dateConvertError('Input Nepali Date may be Out of range. (valid:2000 - 2089 BS)');
    80             }
    81            
    82             $data       = $this->Ny_changeDateText( $data, $convert, $return);
    83            
    84             return $data;
    85         }
    86        
    87         ////////////// DATE CONVERT CHANGE TEXT
    88        
    89         private function Ny_changeDateText( $date , $convert , $return)
    90         {
    91             $date_arr           = explode('-',$date);
    92             $returndate         = array();
    93            
    94            
    95             if($convert==='eng_to_nep')
    96             {
    97                 $datecon        = $this->dnep_day[$date_arr[0]-1].', '
    98                                     .$this->dnep_month[$date_arr[2]-1].' '
    99                                     .$date_arr[1].', '.$date_arr[3];
    100                 $date           = strtr($datecon,$this->eng2nep);
    101             }
    102             elseif($convert==='nep_to_eng')
    103             {
    104                 $date           = $this->eng_day[$date_arr[0]-1].', '
    105                                     .$this->eng_month[$date_arr[2]-1].' '
    106                                     .$date_arr[1].', '.$date_arr[3];
    107             };
    108             $returndate['date'] = $date;
    109             if($return)
    110             {
    111                 $returndate['array']    = $date_arr;
    112                 return $returndate;
    113             }
    114             return $returndate['date'];
    115 
    116         }
    117        
    118         ////////////// DATE CONVERT WIDGET FUNCTIO
    119        
    120         public function Ny_dateConvertWidgetSC( $atts = array() )
    121         {
    122             $this->counter  = $this->counter + 1;
    123             $wid            = $this->counter;
    124             $today      = array('date'=>date('Y-m-d'),'convert'=>'eng_to_nep','array'=>true);
    125             return Nyasro_displayWidget($wid,$this->Ny_dateConvertSC( $today ));
    126         }
    127        
    128         /////////////// DATE CONVERT STYLE
    129        
    130         public function Ny_dateConvertStyle()
    131         {
    132             wp_register_style('Ny_dateConvertCSS',plugins_url('Nyasro_NDC_Style.css',__FILE__));
    133             wp_register_script('Ny_dateConvertJS',plugins_url('Nyasro_NDC_Script.js',__FILE__));
    134             wp_enqueue_style('Ny_dateConvertCSS');
    135             wp_enqueue_script('jquery');
    136         }
    137        
    138         public function Ny_registerWidget()
    139         {
    140             register_widget('Nyasro_NepaliDateConverterWidget');
    141         }
    142        
    143         /////////////// DATE CONVERT AJAX
    144            
    145         public function Ny_Ajax_dateConvert()
    146         {
    147             $date       = $_POST['year'].'-'.$_POST['month'].'-'.$_POST['day'];
    148             echo $this->Ny_dateConvertSC(array('date'=>$date,'convert'=>$_POST['convert']));
    149             exit;
    150         }
    151    
    152     private function ny_dtcl(){  }
    153        
    154         /////////////// DEATE CONVERT CHECK RANGE
    155        
    156         private function Ny_dateConvertCheck( $date , $convert)
    157         {
    158             $year       = (int) $date [0];
    159             $month      = (int) $date [1];
    160             $day        = (int) $date [2];
    161             $error      = false;
    162            
    163             switch( $convert )
    164             {
    165                 case 'nep_to_eng':
    166                     if( $year > 2089 || $year < 2000 )
    167                         $error  = 'Invalid Year';
    168                     elseif( $month > 12 || $month < 1)
    169                         $error  = 'Invalid Month';
    170                     elseif( $day > 32 || $day < 1 )
    171                         $error  = 'Invalid Day';
    172                     break;
    173                
    174                 case 'eng_to_nep':
    175                     if( $year > 2033 || $year < 1944 )
    176                         $error  = 'Invalid Year';
    177                     elseif( $month > 12 || $month < 1)
    178                         $error  = 'Invalid Month';
    179                     elseif( $day > 31 || $day < 1 )
    180                         $error  = 'Invalid Day';
    181                     break;
    182             }
    183             return $error;
    184         }
    185            
    186         //////////////// DATE CONVERT DISPLAY ERROR
    187        
    188         private function Ny_dateConvertError( $msg )
    189         {
    190             echo '<span style="color:#C00;">'.PRODUCT_NAME.'::'.$msg.'</span>';
    191         }
    192        
    193 
    194        
    195     }
    196241?>
  • nyasro-nepali-date-converter/trunk/Nyasro_NDC_Converter.php

    r943742 r2335674  
    11<?php
    2     class Nepali_Calendar{
    3         private $bs = array(
    4             0=>array(2000,30,32,31,32,31,30,30,30,29,30,29,31),
    5             1=>array(2001,31,31,32,31,31,31,30,29,30,29,30,30),
    6             2=>array(2002,31,31,32,32,31,30,30,29,30,29,30,30),
    7             3=>array(2003,31,32,31,32,31,30,30,30,29,29,30,31),
    8             4=>array(2004,30,32,31,32,31,30,30,30,29,30,29,31),
    9             5=>array(2005,31,31,32,31,31,31,30,29,30,29,30,30),
    10             6=>array(2006,31,31,32,32,31,30,30,29,30,29,30,30),
    11             7=>array(2007,31,32,31,32,31,30,30,30,29,29,30,31),
    12             8=>array(2008,31,31,31,32,31,31,29,30,30,29,29,31),
    13             9=>array(2009,31,31,32,31,31,31,30,29,30,29,30,30),
    14             10=>array(2010,31,31,32,32,31,30,30,29,30,29,30,30),
    15             11=>array(2011,31,32,31,32,31,30,30,30,29,29,30,31),
    16             12=>array(2012,31,31,31,32,31,31,29,30,30,29,30,30),
    17             13=>array(2013,31,31,32,31,31,31,30,29,30,29,30,30),
    18             14=>array(2014,31,31,32,32,31,30,30,29,30,29,30,30),
    19             15=>array(2015,31,32,31,32,31,30,30,30,29,29,30,31),
    20             16=>array(2016,31,31,31,32,31,31,29,30,30,29,30,30),
    21             17=>array(2017,31,31,32,31,31,31,30,29,30,29,30,30),
    22             18=>array(2018,31,32,31,32,31,30,30,29,30,29,30,30),
    23             19=>array(2019,31,32,31,32,31,30,30,30,29,30,29,31),
    24             20=>array(2020,31,31,31,32,31,31,30,29,30,29,30,30),
    25             21=>array(2021,31,31,32,31,31,31,30,29,30,29,30,30),
    26             22=>array(2022,31,32,31,32,31,30,30,30,29,29,30,30),
    27             23=>array(2023,31,32,31,32,31,30,30,30,29,30,29,31),
    28             24=>array(2024,31,31,31,32,31,31,30,29,30,29,30,30),
    29             25=>array(2025,31,31,32,31,31,31,30,29,30,29,30,30),
    30             26=>array(2026,31,32,31,32,31,30,30,30,29,29,30,31),
    31             27=>array(2027,30,32,31,32,31,30,30,30,29,30,29,31),
    32             28=>array(2028,31,31,32,31,31,31,30,29,30,29,30,30),
    33             29=>array(2029,31,31,32,31,32,30,30,29,30,29,30,30),
    34             30=>array(2030,31,32,31,32,31,30,30,30,29,29,30,31),
    35             31=>array(2031,30,32,31,32,31,30,30,30,29,30,29,31),
    36             32=>array(2032,31,31,32,31,31,31,30,29,30,29,30,30),
    37             33=>array(2033,31,31,32,32,31,30,30,29,30,29,30,30),
    38             34=>array(2034,31,32,31,32,31,30,30,30,29,29,30,31),
    39             35=>array(2035,30,32,31,32,31,31,29,30,30,29,29,31),
    40             36=>array(2036,31,31,32,31,31,31,30,29,30,29,30,30),
    41             37=>array(2037,31,31,32,32,31,30,30,29,30,29,30,30),
    42             38=>array(2038,31,32,31,32,31,30,30,30,29,29,30,31),
    43             39=>array(2039,31,31,31,32,31,31,29,30,30,29,30,30),
    44             40=>array(2040,31,31,32,31,31,31,30,29,30,29,30,30),
    45             41=>array(2041,31,31,32,32,31,30,30,29,30,29,30,30),
    46             42=>array(2042,31,32,31,32,31,30,30,30,29,29,30,31),
    47             43=>array(2043,31,31,31,32,31,31,29,30,30,29,30,30),
    48             44=>array(2044,31,31,32,31,31,31,30,29,30,29,30,30),
    49             45=>array(2045,31,32,31,32,31,30,30,29,30,29,30,30),
    50             46=>array(2046,31,32,31,32,31,30,30,30,29,29,30,31),
    51             47=>array(2047,31,31,31,32,31,31,30,29,30,29,30,30),
    52             48=>array(2048,31,31,32,31,31,31,30,29,30,29,30,30),
    53             49=>array(2049,31,32,31,32,31,30,30,30,29,29,30,30),
    54             50=>array(2050,31,32,31,32,31,30,30,30,29,30,29,31),
    55             51=>array(2051,31,31,31,32,31,31,30,29,30,29,30,30),
    56             52=>array(2052,31,31,32,31,31,31,30,29,30,29,30,30),
    57             53=>array(2053,31,32,31,32,31,30,30,30,29,29,30,30),
    58             54=>array(2054,31,32,31,32,31,30,30,30,29,30,29,31),
    59             55=>array(2055,31,31,32,31,31,31,30,29,30,29,30,30),
    60             56=>array(2056,31,31,32,31,32,30,30,29,30,29,30,30),
    61             57=>array(2057,31,32,31,32,31,30,30,30,29,29,30,31),
    62             58=>array(2058,30,32,31,32,31,30,30,30,29,30,29,31),
    63             59=>array(2059,31,31,32,31,31,31,30,29,30,29,30,30),
    64             60=>array(2060,31,31,32,32,31,30,30,29,30,29,30,30),
    65             61=>array(2061,31,32,31,32,31,30,30,30,29,29,30,31),
    66             62=>array(2062,30,32,31,32,31,31,29,30,29,30,29,31),
    67             63=>array(2063,31,31,32,31,31,31,30,29,30,29,30,30),
    68             64=>array(2064,31,31,32,32,31,30,30,29,30,29,30,30),
    69             65=>array(2065,31,32,31,32,31,30,30,30,29,29,30,31),
    70             66=>array(2066,31,31,31,32,31,31,29,30,30,29,29,31),
    71             67=>array(2067,31,31,32,31,31,31,30,29,30,29,30,30),
    72             68=>array(2068,31,31,32,32,31,30,30,29,30,29,30,30),
    73             69=>array(2069,31,32,31,32,31,30,30,30,29,29,30,31),
    74             70=>array(2070,31,31,31,32,31,31,29,30,30,29,30,30),
    75             71=>array(2071,31,31,32,31,31,31,30,29,30,29,30,30),
    76             72=>array(2072,31,32,31,32,31,30,30,29,30,29,30,30),
    77             73=>array(2073,31,32,31,32,31,30,30,30,29,29,30,31),
    78             74=>array(2074,31,31,31,32,31,31,30,29,30,29,30,30),
    79             75=>array(2075,31,31,32,31,31,31,30,29,30,29,30,30),
    80             76=>array(2076,31,32,31,32,31,30,30,30,29,29,30,30),
    81             77=>array(2077,31,32,31,32,31,30,30,30,29,30,29,31),
    82             78=>array(2078,31,31,31,32,31,31,30,29,30,29,30,30),
    83             79=>array(2079,31,31,32,31,31,31,30,29,30,29,30,30),
    84             80=>array(2080,31,32,31,32,31,30,30,30,29,29,30,30),
    85             81=>array(2081,31,31,32,32,31,30,30,30,29,30,30,30),
    86             82=>array(2082,30,32,31,32,31,30,30,30,29,30,30,30),
    87             83=>array(2083,31,31,32,31,31,30,30,30,29,30,30,30),
    88             84=>array(2084,31,31,32,31,31,30,30,30,29,30,30,30),
    89             85=>array(2085,31,32,31,32,30,31,30,30,29,30,30,30),
    90             86=>array(2086,30,32,31,32,31,30,30,30,29,30,30,30),
    91             87=>array(2087,31,31,32,31,31,31,30,30,29,30,30,30),
    92             88=>array(2088,30,31,32,32,30,31,30,30,29,30,30,30),
    93             89=>array(2089,30,32,31,32,31,30,30,30,29,30,30,30),
    94             90=>array(2090,30,32,31,32,31,30,30,30,29,30,30,30)
    95             );
    96        
    97         private $nep_date = array('year'=>'','month'=>'','date'=>'','day'=>'','nmonth'=>'','num_day'=>'','nepali'=>true);
    98         private $eng_date = array('year'=>'','month'=>'','date'=>'','day'=>'','emonth'=>'','num_day'=>'','nepali'=>false);
    99         public $debug_info = "";
    100    
    101    
    102         /**
    103          * Calculates wheather english year is leap year or not
    104          *
    105          * @param integer $year
    106          * @return boolean
    107          */
    108         public function is_leap_year($year)
    109         {
    110             $a = $year;
    111             if ($a%100==0)
    112             {
    113              if($a%400==0)
    114              {
    115                 return true;
    116              } else {
    117                 return false;
    118              }
    119                
    120             } else {
    121                 if ($a%4==0)
    122                 {
    123                     return true;
    124                 } else {
    125                     return false;
    126                 }
    127             }
    128         }
    129    
    130        
    131         private function is_range_eng($yy,$mm,$dd){
    132             if($yy<1944 || $yy>2033){
    133                 $this->debug_info = "Supported only between 1944-2022";
    134                 return false;
    135             }
    136                
    137             if($mm<1 || $mm >12){
    138                 $this->debug_info = "Error! value 1-12 only";
    139                 return false;
    140             }
    141                
    142             if($dd<1 || $dd >31){
    143                 $this->debug_info = "Error! value 1-31 only";           
    144                 return false;
    145             }   
    146            
    147             return true;
    148         }
    149    
    150         private function is_range_nep($yy,$mm,$dd){     
    151             if($yy<2000 || $yy>2089){
    152                 $this->debug_info="Supported only between 2000-2089";
    153                 return false;
    154             }
    155            
    156             if($mm<1 || $mm >12) {
    157                 $this->debug_info="Error! value 1-12 only";
    158                 return false;
    159             }
    160            
    161             if($dd<1 || $dd >32){
    162                 $this->debug_info="Error! value 1-31 only";
    163                 return false;
    164             }       
    165            
    166             return true;
    167         }   
    168        
    169        
    170         /**
    171          * currently can only calculate the date between AD 1944-2033...
    172          *
    173          * @param unknown_type $yy
    174          * @param unknown_type $mm
    175          * @param unknown_type $dd
    176          * @return unknown
    177          */
    178        
    179         public function eng_to_nep($yy,$mm,$dd){
    180             if ($this->is_range_eng($yy,$mm,$dd) == false){
    181                 return false;
    182             } else {           
    183                
    184                 // english month data.
    185                 $month = array(31,28,31,30,31,30,31,31,30,31,30,31);
    186                 $lmonth = array(31,29,31,30,31,30,31,31,30,31,30,31);
    187                
    188                 $def_eyy = 1944;                                    //spear head english date...
    189                 $def_nyy = 2000; $def_nmm = 9; $def_ndd = 17-1;     //spear head nepali date...
    190                 $total_eDays=0; $total_nDays=0; $a=0; $day=7-1;     //all the initializations...
    191                 $m = 0; $y = 0; $i =0; $j = 0;
    192                 $numDay=0;
    193                
    194                 // count total no. of days in-terms of year
    195                 for($i=0; $i<($yy-$def_eyy); $i++){ //total days for month calculation...(english)
    196                     if($this->is_leap_year($def_eyy+$i)==1)
    197                         for($j=0; $j<12; $j++)
    198                             $total_eDays += $lmonth[$j];
    199                     else
    200                         for($j=0; $j<12; $j++)
    201                             $total_eDays += $month[$j];
    202                 }
    203                
    204                 // count total no. of days in-terms of month                   
    205                 for($i=0; $i<($mm-1); $i++){       
    206                     if($this->is_leap_year($yy)==1)
    207                         $total_eDays += $lmonth[$i];
    208                     else
    209                         $total_eDays += $month[$i];
    210                 }
    211                
    212                 // count total no. of days in-terms of date
    213                 $total_eDays += $dd;
    214                
    215                
    216 
    217                 $i = 0; $j = $def_nmm;                 
    218                 $total_nDays = $def_ndd;
    219                 $m = $def_nmm;
    220                 $y = $def_nyy;
    221                
    222                 // count nepali date from array
    223                 while($total_eDays != 0) {
    224                     $a = $this->bs[$i][$j];
    225                     $total_nDays++;                     //count the days
    226                     $day++;                             //count the days interms of 7 days
    227                     if($total_nDays > $a){
    228                         $m++;
    229                         $total_nDays=1;
    230                         $j++;
    231                     }
    232                     if($day > 7)
    233                         $day = 1;
    234                     if($m > 12){
    235                         $y++;
    236                         $m = 1;
    237                     }
    238                     if($j > 12){
    239                         $j = 1; $i++;
    240                     }
    241                     $total_eDays--;
    242                 }
    243                
    244                 $numDay=$day;
    245                
    246                 $this->nep_date["year"] = $y;
    247                 $this->nep_date["date"] = $total_nDays;
    248                 $this->nep_date["day"] = $day;
    249                 $this->nep_date["month"] =$m;
    250                 return $this->nep_date;
    251             }
    252         }
    253        
    254        
    255         /**
    256          * currently can only calculate the date between BS 2000-2089
    257          *
    258          * @param unknown_type $yy
    259          * @param unknown_type $mm
    260          * @param unknown_type $dd
    261          * @return unknown
    262          */
    263         public function nep_to_eng($yy,$mm,$dd){
    264            
    265             $def_eyy = 1943 ; $def_emm=4 ; $def_edd=14-1;       // init english date.
    266             $def_nyy = 2000; $def_nmm = 1; $def_ndd = 1;        // equivalent nepali date.
    267             $total_eDays=0; $total_nDays=0; $a=0; $day=4-1;     // initializations...
    268             $m = 0; $y = 0; $i=0;
    269             $k = 0; $numDay = 0;
    270            
    271             $month = array(0,31,28,31,30,31,30,31,31,30,31,30,31);
    272             $lmonth = array(0,31,29,31,30,31,30,31,31,30,31,30,31);
    273            
    274             if($this->is_range_nep($yy,$mm,$dd)===false){
    275                 return false;
    276                
    277             } else {
    278                
    279                 // count total days in-terms of year
    280                 for($i=0; $i<($yy-$def_nyy); $i++){
    281                     for($j=1; $j<=12; $j++){
    282                         $total_nDays += $this->bs[$k][$j];
    283                     }
    284                     $k++;
    285                 }
    286                
    287                 // count total days in-terms of month           
    288                 for($j=1; $j<$mm; $j++){
    289                     $total_nDays += $this->bs[$k][$j];
    290                 }
    291                
    292                 // count total days in-terms of dat
    293                 $total_nDays += $dd;           
    294                
    295                 //calculation of equivalent english date...
    296                 $total_eDays = $def_edd;
    297                 $m = $def_emm;
    298                 $y = $def_eyy;
    299                 while($total_nDays != 0){
    300                     if($this->is_leap_year($y))
    301                     {
    302                         $a = $lmonth[$m];
    303                     }
    304                     else
    305                     {
    306                         $a = $month[$m];
    307                     }
    308                     $total_eDays++;
    309                     $day++;
    310                     if($total_eDays > $a){
    311                         $m++;
    312                         $total_eDays = 1;
    313                         if($m > 12){
    314                             $y++;
    315                             $m = 1;
    316                         }   
    317                     }
    318                     if($day > 7)
    319                         $day = 1;
    320                     $total_nDays--;
    321                 }
    322                 $numDay = $day;
    323                
    324                 $this->eng_date["year"] = $y;                   
    325                 $this->eng_date["date"] = $total_eDays;     
    326                 $this->eng_date["day"] = $day;                 
    327                 $this->eng_date["month"] =$m;           
    328                
    329                 return $this->eng_date;         
    330             }
    331         }
    332    
    333     };
    334 
    335 function nyasro_convert_date( $postdata )
    336 {
    337 parse_str($postdata);
    338 $eng2nep        = array(
    339                     '0'=>'०',
    340                     '1'=>'१',
    341                     '2'=>'२',
    342                     '3'=>'३',
    343                     '4'=>'४',
    344                     '5'=>'५',
    345                     '6'=>'६',
    346                     '7'=>'७',
    347                     '8'=>'८',
    348                     '9'=>'९',
    349                     );
    350 
    351 
    352 date_default_timezone_set(NY_NDC_TIMEZONE);
    353 
    354 
    355 $ny_year    = $year;
    356 $ny_month   = $month;
    357 $ny_day     = $day;
    358 
    359 
    360 if($ny_year && ($convert==='eng_to_nep' || $convert==='nep_to_eng'))
    361 {
    362     $cal = new Nepali_Calendar();
    363     $r=$cal->$convert($ny_year,$ny_month,$ny_day);
    364 }
    365 else
    366     exit;
    367    
    368 if(!isset($r['day']) or !$r['day'])
    369 {
    370     echo '-';
    371     exit;
    372 }
    373    
    374 return $r['day'].'-'.$r['date'].'-'.$r['month'].'-'.$r['year'];
    375 }
     2 
     3  class Nepali_Calendar {
     4    private $bs = [
     5      0  => [ 2000, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
     6      1  => [ 2001, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     7      2  => [ 2002, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     8      3  => [ 2003, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     9      4  => [ 2004, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
     10      5  => [ 2005, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     11      6  => [ 2006, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     12      7  => [ 2007, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     13      8  => [ 2008, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 ],
     14      9  => [ 2009, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     15      10 => [ 2010, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     16      11 => [ 2011, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     17      12 => [ 2012, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 ],
     18      13 => [ 2013, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     19      14 => [ 2014, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     20      15 => [ 2015, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     21      16 => [ 2016, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 ],
     22      17 => [ 2017, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     23      18 => [ 2018, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     24      19 => [ 2019, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
     25      20 => [ 2020, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
     26      21 => [ 2021, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     27      22 => [ 2022, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 ],
     28      23 => [ 2023, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
     29      24 => [ 2024, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
     30      25 => [ 2025, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     31      26 => [ 2026, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     32      27 => [ 2027, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
     33      28 => [ 2028, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     34      29 => [ 2029, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30 ],
     35      30 => [ 2030, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     36      31 => [ 2031, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
     37      32 => [ 2032, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     38      33 => [ 2033, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     39      34 => [ 2034, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     40      35 => [ 2035, 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 ],
     41      36 => [ 2036, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     42      37 => [ 2037, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     43      38 => [ 2038, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     44      39 => [ 2039, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 ],
     45      40 => [ 2040, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     46      41 => [ 2041, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     47      42 => [ 2042, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     48      43 => [ 2043, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 ],
     49      44 => [ 2044, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     50      45 => [ 2045, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     51      46 => [ 2046, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     52      47 => [ 2047, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
     53      48 => [ 2048, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     54      49 => [ 2049, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 ],
     55      50 => [ 2050, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
     56      51 => [ 2051, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
     57      52 => [ 2052, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     58      53 => [ 2053, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 ],
     59      54 => [ 2054, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
     60      55 => [ 2055, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     61      56 => [ 2056, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30 ],
     62      57 => [ 2057, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     63      58 => [ 2058, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
     64      59 => [ 2059, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     65      60 => [ 2060, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     66      61 => [ 2061, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     67      62 => [ 2062, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31 ],
     68      63 => [ 2063, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     69      64 => [ 2064, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     70      65 => [ 2065, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     71      66 => [ 2066, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31 ],
     72      67 => [ 2067, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     73      68 => [ 2068, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     74      69 => [ 2069, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     75      70 => [ 2070, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30 ],
     76      71 => [ 2071, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     77      72 => [ 2072, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30 ],
     78      73 => [ 2073, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31 ],
     79      74 => [ 2074, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
     80      75 => [ 2075, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     81      76 => [ 2076, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 ],
     82      77 => [ 2077, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31 ],
     83      78 => [ 2078, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30 ],
     84      79 => [ 2079, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30 ],
     85      80 => [ 2080, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30 ],
     86      81 => [ 2081, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],
     87      82 => [ 2082, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],
     88      83 => [ 2083, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30 ],
     89      84 => [ 2084, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30 ],
     90      85 => [ 2085, 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30 ],
     91      86 => [ 2086, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],
     92      87 => [ 2087, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30 ],
     93      88 => [ 2088, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30 ],
     94      89 => [ 2089, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 ],
     95      90 => [ 2090, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30 ]
     96    ];
     97   
     98    private $nep_date = [ 'year'    => '',
     99                          'month'   => '',
     100                          'date'    => '',
     101                          'day'     => '',
     102                          'nmonth'  => '',
     103                          'num_day' => '',
     104                          'nepali'  => true
     105    ];
     106    private $eng_date = [ 'year'    => '',
     107                          'month'   => '',
     108                          'date'    => '',
     109                          'day'     => '',
     110                          'emonth'  => '',
     111                          'num_day' => '',
     112                          'nepali'  => false
     113    ];
     114    public $debug_info = "";
     115   
     116   
     117    /**
     118     * Calculates wheather english year is leap year or not
     119     *
     120     * @param integer $year
     121     *
     122     * @return boolean
     123     */
     124    public function is_leap_year( $year ) {
     125      $a = $year;
     126      if ( $a % 100 == 0 ) {
     127        if ( $a % 400 == 0 ) {
     128          return true;
     129        } else {
     130          return false;
     131        }
     132       
     133      } else {
     134        if ( $a % 4 == 0 ) {
     135          return true;
     136        } else {
     137          return false;
     138        }
     139      }
     140    }
     141   
     142   
     143    private function is_range_eng( $yy, $mm, $dd ) {
     144      if ( $yy < 1944 || $yy > 2033 ) {
     145        $this->debug_info = "Supported only between 1944-2022";
     146        return false;
     147      }
     148     
     149      if ( $mm < 1 || $mm > 12 ) {
     150        $this->debug_info = "Error! value 1-12 only";
     151        return false;
     152      }
     153     
     154      if ( $dd < 1 || $dd > 31 ) {
     155        $this->debug_info = "Error! value 1-31 only";
     156        return false;
     157      }
     158     
     159      return true;
     160    }
     161   
     162    private function is_range_nep( $yy, $mm, $dd ) {
     163      if ( $yy < 2000 || $yy > 2089 ) {
     164        $this->debug_info = "Supported only between 2000-2089";
     165        return false;
     166      }
     167     
     168      if ( $mm < 1 || $mm > 12 ) {
     169        $this->debug_info = "Error! value 1-12 only";
     170        return false;
     171      }
     172     
     173      if ( $dd < 1 || $dd > 32 ) {
     174        $this->debug_info = "Error! value 1-31 only";
     175        return false;
     176      }
     177     
     178      return true;
     179    }
     180   
     181   
     182    /**
     183     * currently can only calculate the date between AD 1944-2033...
     184     *
     185     * @param unknown_type $yy
     186     * @param unknown_type $mm
     187     * @param unknown_type $dd
     188     *
     189     * @return unknown
     190     */
     191   
     192    public function eng_to_nep( $yy, $mm, $dd ) {
     193      if ( $this->is_range_eng($yy, $mm, $dd) == false ) {
     194        return false;
     195      } else {
     196       
     197        // english month data.
     198        $month  = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
     199        $lmonth = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
     200       
     201        $def_eyy     = 1944;                  //spear head english date...
     202        $def_nyy     = 2000;
     203        $def_nmm     = 9;
     204        $def_ndd     = 17 - 1;    //spear head nepali date...
     205        $total_eDays = 0;
     206        $total_nDays = 0;
     207        $a           = 0;
     208        $day         = 7 - 1;    //all the initializations...
     209        $m           = 0;
     210        $y           = 0;
     211        $i           = 0;
     212        $j           = 0;
     213        $numDay      = 0;
     214       
     215        // count total no. of days in-terms of year
     216        for ( $i = 0; $i < ( $yy - $def_eyy ); $i++ ) {  //total days for month calculation...(english)
     217          if ( $this->is_leap_year($def_eyy + $i) == 1 ) {
     218            for ( $j = 0; $j < 12; $j++ ) {
     219              $total_eDays += $lmonth[ $j ];
     220            }
     221          } else {
     222            for ( $j = 0; $j < 12; $j++ ) {
     223              $total_eDays += $month[ $j ];
     224            }
     225          }
     226        }
     227       
     228        // count total no. of days in-terms of month                   
     229        for ( $i = 0; $i < ( $mm - 1 ); $i++ ) {
     230          if ( $this->is_leap_year($yy) == 1 ) {
     231            $total_eDays += $lmonth[ $i ];
     232          } else {
     233            $total_eDays += $month[ $i ];
     234          }
     235        }
     236       
     237        // count total no. of days in-terms of date
     238        $total_eDays += $dd;
     239       
     240       
     241        $i           = 0;
     242        $j           = $def_nmm;
     243        $total_nDays = $def_ndd;
     244        $m           = $def_nmm;
     245        $y           = $def_nyy;
     246       
     247        // count nepali date from array
     248        while ( $total_eDays != 0 ) {
     249          $a = $this->bs[ $i ][ $j ];
     250          $total_nDays++;            //count the days
     251          $day++;                //count the days interms of 7 days
     252          if ( $total_nDays > $a ) {
     253            $m++;
     254            $total_nDays = 1;
     255            $j++;
     256          }
     257          if ( $day > 7 ) {
     258            $day = 1;
     259          }
     260          if ( $m > 12 ) {
     261            $y++;
     262            $m = 1;
     263          }
     264          if ( $j > 12 ) {
     265            $j = 1;
     266            $i++;
     267          }
     268          $total_eDays--;
     269        }
     270       
     271        $numDay = $day;
     272       
     273        $this->nep_date[ "year" ]  = $y;
     274        $this->nep_date[ "date" ]  = $total_nDays;
     275        $this->nep_date[ "day" ]   = $day;
     276        $this->nep_date[ "month" ] = $m;
     277        return $this->nep_date;
     278      }
     279    }
     280   
     281   
     282    /**
     283     * currently can only calculate the date between BS 2000-2089
     284     *
     285     * @param unknown_type $yy
     286     * @param unknown_type $mm
     287     * @param unknown_type $dd
     288     *
     289     * @return unknown
     290     */
     291    public function nep_to_eng( $yy, $mm, $dd ) {
     292     
     293      $def_eyy     = 1943;
     294      $def_emm     = 4;
     295      $def_edd     = 14 - 1;    // init english date.
     296      $def_nyy     = 2000;
     297      $def_nmm     = 1;
     298      $def_ndd     = 1;    // equivalent nepali date.
     299      $total_eDays = 0;
     300      $total_nDays = 0;
     301      $a           = 0;
     302      $day         = 4 - 1;    // initializations...
     303      $m           = 0;
     304      $y           = 0;
     305      $i           = 0;
     306      $k           = 0;
     307      $numDay      = 0;
     308     
     309      $month  = [ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
     310      $lmonth = [ 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
     311     
     312      if ( $this->is_range_nep($yy, $mm, $dd) === false ) {
     313        return false;
     314       
     315      } else {
     316       
     317        // count total days in-terms of year
     318        for ( $i = 0; $i < ( $yy - $def_nyy ); $i++ ) {
     319          for ( $j = 1; $j <= 12; $j++ ) {
     320            $total_nDays += $this->bs[ $k ][ $j ];
     321          }
     322          $k++;
     323        }
     324       
     325        // count total days in-terms of month           
     326        for ( $j = 1; $j < $mm; $j++ ) {
     327          $total_nDays += $this->bs[ $k ][ $j ];
     328        }
     329       
     330        // count total days in-terms of dat
     331        $total_nDays += $dd;
     332       
     333        //calculation of equivalent english date...
     334        $total_eDays = $def_edd;
     335        $m           = $def_emm;
     336        $y           = $def_eyy;
     337        while ( $total_nDays != 0 ) {
     338          if ( $this->is_leap_year($y) ) {
     339            $a = $lmonth[ $m ];
     340          } else {
     341            $a = $month[ $m ];
     342          }
     343          $total_eDays++;
     344          $day++;
     345          if ( $total_eDays > $a ) {
     346            $m++;
     347            $total_eDays = 1;
     348            if ( $m > 12 ) {
     349              $y++;
     350              $m = 1;
     351            }
     352          }
     353          if ( $day > 7 ) {
     354            $day = 1;
     355          }
     356          $total_nDays--;
     357        }
     358        $numDay = $day;
     359       
     360        $this->eng_date[ "year" ]  = $y;
     361        $this->eng_date[ "date" ]  = $total_eDays;
     362        $this->eng_date[ "day" ]   = $day;
     363        $this->eng_date[ "month" ] = $m;
     364       
     365        return $this->eng_date;
     366      }
     367    }
     368   
     369  }
     370 
     371  ;
     372 
     373  function nyasro_convert_date( $postdata ) {
     374   
     375    parse_str($postdata, $result);
     376    extract($result, EXTR_OVERWRITE);
     377    $eng2nep = [
     378      '0' => '०',
     379      '1' => '१',
     380      '2' => '२',
     381      '3' => '३',
     382      '4' => '४',
     383      '5' => '५',
     384      '6' => '६',
     385      '7' => '७',
     386      '8' => '८',
     387      '9' => '९',
     388    ];
     389   
     390   
     391    date_default_timezone_set(NY_NDC_TIMEZONE);
     392   
     393   
     394    $ny_year  = $year;
     395    $ny_month = $month;
     396    $ny_day   = $day;
     397   
     398   
     399    if ( $ny_year && ( $convert === 'eng_to_nep' || $convert === 'nep_to_eng' ) ) {
     400      $cal = new Nepali_Calendar();
     401      $r   = $cal->$convert($ny_year, $ny_month, $ny_day);
     402    } else {
     403      exit;
     404    }
     405   
     406    if ( ! isset($r[ 'day' ]) or ! $r[ 'day' ] ) {
     407      echo '-';
     408      exit;
     409    }
     410   
     411    return $r[ 'day' ] . '-' . $r[ 'date' ] . '-' . $r[ 'month' ] . '-' . $r[ 'year' ];
     412  }
  • nyasro-nepali-date-converter/trunk/Nyasro_NDC_Display.php

    r943740 r2335674  
    9090        <?php } ?>
    9191        <div id="Nyasro_NepaliDateConverter<?php echo $wid; ?>" class="Nyasro_NDC">
    92             <h4 class="Ny_h4 Ny_icon">Nepali Date Converter (Nyasro)</h4>
     92            <h4 class="Ny_h4 Ny_icon">Nepali Date Converter</h4>
    9393            <div class="Ny_dateBox">
    9494                <div class="Ny_nepDate">
Note: See TracChangeset for help on using the changeset viewer.