ÿþ/ *  
   *   C o p y r i g h t   ( c )   2 0 0 6   H o   N g o c   D u c .   A l l   R i g h t s   R e s e r v e d .  
   *   A s t r o n o m i c a l   a l g o r i t h m s   f r o m   t h e   b o o k   " A s t r o n o m i c a l   A l g o r i t h m s "   b y   J e a n   M e e u s ,   1 9 9 8  
   *  
   *   P e r m i s s i o n   t o   u s e ,   c o p y ,   m o d i f y ,   a n d   r e d i s t r i b u t e   t h i s   s o f t w a r e   a n d   i t s  
   *   d o c u m e n t a t i o n   f o r   p e r s o n a l ,   n o n - c o m m e r c i a l   u s e   i s   h e r e b y   g r a n t e d   p r o v i d e d   t h a t  
   *   t h i s   c o p y r i g h t   n o t i c e   a n d   a p p r o p r i a t e   d o c u m e n t a t i o n   a p p e a r s   i n   a l l   c o p i e s .  
   * /  
 v a r   P I   =   M a t h . P I ;  
  
 / *   D i s c a r d   t h e   f r a c t i o n a l   p a r t   o f   a   n u m b e r ,   e . g . ,   I N T ( 3 . 2 )   =   3   * /  
 f u n c t i o n   I N T ( d )   {  
 	 r e t u r n   M a t h . f l o o r ( d ) ;  
 }  
  
 / *   C o m p u t e   t h e   ( i n t e g r a l )   J u l i a n   d a y   n u m b e r   o f   d a y   d d / m m / y y y y ,   i . e . ,   t h e   n u m b e r    
   *   o f   d a y s   b e t w e e n   1 / 1 / 4 7 1 3   B C   ( J u l i a n   c a l e n d a r )   a n d   d d / m m / y y y y .    
   *   F o r m u l a   f r o m   h t t p : / / w w w . t o n d e r i n g . d k / c l a u s / c a l e n d a r . h t m l  
   * /  
 f u n c t i o n   j d F r o m D a t e ( d d ,   m m ,   y y )   {  
 	 v a r   a ,   y ,   m ,   j d ;  
 	 a   =   I N T ( ( 1 4   -   m m )   /   1 2 ) ;  
 	 y   =   y y + 4 8 0 0 - a ;  
 	 m   =   m m + 1 2 * a - 3 ;  
 	 j d   =   d d   +   I N T ( ( 1 5 3 * m + 2 ) / 5 )   +   3 6 5 * y   +   I N T ( y / 4 )   -   I N T ( y / 1 0 0 )   +   I N T ( y / 4 0 0 )   -   3 2 0 4 5 ;  
 	 i f   ( j d   <   2 2 9 9 1 6 1 )   {  
 	 	 j d   =   d d   +   I N T ( ( 1 5 3 * m + 2 ) / 5 )   +   3 6 5 * y   +   I N T ( y / 4 )   -   3 2 0 8 3 ;  
 	 }  
 	 r e t u r n   j d ;  
 }  
  
 / *   C o n v e r t   a   J u l i a n   d a y   n u m b e r   t o   d a y / m o n t h / y e a r .   P a r a m e t e r   j d   i s   a n   i n t e g e r   * /  
 f u n c t i o n   j d T o D a t e ( j d )   {  
 	 v a r   a ,   b ,   c ,   d ,   e ,   m ,   d a y ,   m o n t h ,   y e a r ;  
 	 i f   ( j d   >   2 2 9 9 1 6 0 )   {   / /   A f t e r   5 / 1 0 / 1 5 8 2 ,   G r e g o r i a n   c a l e n d a r  
 	 	 a   =   j d   +   3 2 0 4 4 ;  
 	 	 b   =   I N T ( ( 4 * a + 3 ) / 1 4 6 0 9 7 ) ;  
 	 	 c   =   a   -   I N T ( ( b * 1 4 6 0 9 7 ) / 4 ) ;  
 	 }   e l s e   {  
 	 	 b   =   0 ;  
 	 	 c   =   j d   +   3 2 0 8 2 ;  
 	 }  
 	 d   =   I N T ( ( 4 * c + 3 ) / 1 4 6 1 ) ;  
 	 e   =   c   -   I N T ( ( 1 4 6 1 * d ) / 4 ) ;  
 	 m   =   I N T ( ( 5 * e + 2 ) / 1 5 3 ) ;  
 	 d a y   =   e   -   I N T ( ( 1 5 3 * m + 2 ) / 5 )   +   1 ;  
 	 m o n t h   =   m   +   3   -   1 2 * I N T ( m / 1 0 ) ;  
 	 y e a r   =   b * 1 0 0   +   d   -   4 8 0 0   +   I N T ( m / 1 0 ) ;  
 	 s   =   " N g à y   "   +   d a y   +   "   t h á n g   "   +   m o n t h   +   "   n m   "   +   y e a r  
  
 	 r e t u r n   s ;  
 }  
  
 / *   C o m p u t e   t h e   t i m e   o f   t h e   k - t h   n e w   m o o n   a f t e r   t h e   n e w   m o o n   o f   1 / 1 / 1 9 0 0   1 3 : 5 2   U C T    
   *   ( m e a s u r e d   a s   t h e   n u m b e r   o f   d a y s   s i n c e   1 / 1 / 4 7 1 3   B C   n o o n   U C T ,   e . g . ,   2 4 5 1 5 4 5 . 1 2 5   i s   1 / 1 / 2 0 0 0   1 5 : 0 0   U T C ) .  
   *   R e t u r n s   a   f l o a t i n g   n u m b e r ,   e . g . ,   2 4 1 5 0 7 9 . 9 7 5 8 6 1 7 8 1 3   f o r   k = 2   o r   2 4 1 4 9 6 1 . 9 3 5 1 5 7 7 4 6   f o r   k = - 2  
   *   A l g o r i t h m   f r o m :   " A s t r o n o m i c a l   A l g o r i t h m s "   b y   J e a n   M e e u s ,   1 9 9 8  
   * /  
 f u n c t i o n   N e w M o o n ( k )   {  
 	 v a r   T ,   T 2 ,   T 3 ,   d r ,   J d 1 ,   M ,   M p r ,   F ,   C 1 ,   d e l t a t ,   J d N e w ;  
 	 T   =   k / 1 2 3 6 . 8 5 ;   / /   T i m e   i n   J u l i a n   c e n t u r i e s   f r o m   1 9 0 0   J a n u a r y   0 . 5  
 	 T 2   =   T   *   T ;  
 	 T 3   =   T 2   *   T ;  
 	 d r   =   P I / 1 8 0 ;  
 	 J d 1   =   2 4 1 5 0 2 0 . 7 5 9 3 3   +   2 9 . 5 3 0 5 8 8 6 8 * k   +   0 . 0 0 0 1 1 7 8 * T 2   -   0 . 0 0 0 0 0 0 1 5 5 * T 3 ;  
 	 J d 1   =   J d 1   +   0 . 0 0 0 3 3 * M a t h . s i n ( ( 1 6 6 . 5 6   +   1 3 2 . 8 7 * T   -   0 . 0 0 9 1 7 3 * T 2 ) * d r ) ;   / /   M e a n   n e w   m o o n  
 	 M   =   3 5 9 . 2 2 4 2   +   2 9 . 1 0 5 3 5 6 0 8 * k   -   0 . 0 0 0 0 3 3 3 * T 2   -   0 . 0 0 0 0 0 3 4 7 * T 3 ;   / /   S u n ' s   m e a n   a n o m a l y  
 	 M p r   =   3 0 6 . 0 2 5 3   +   3 8 5 . 8 1 6 9 1 8 0 6 * k   +   0 . 0 1 0 7 3 0 6 * T 2   +   0 . 0 0 0 0 1 2 3 6 * T 3 ;   / /   M o o n ' s   m e a n   a n o m a l y  
 	 F   =   2 1 . 2 9 6 4   +   3 9 0 . 6 7 0 5 0 6 4 6 * k   -   0 . 0 0 1 6 5 2 8 * T 2   -   0 . 0 0 0 0 0 2 3 9 * T 3 ;   / /   M o o n ' s   a r g u m e n t   o f   l a t i t u d e  
 	 C 1 = ( 0 . 1 7 3 4   -   0 . 0 0 0 3 9 3 * T ) * M a t h . s i n ( M * d r )   +   0 . 0 0 2 1 * M a t h . s i n ( 2 * d r * M ) ;  
 	 C 1   =   C 1   -   0 . 4 0 6 8 * M a t h . s i n ( M p r * d r )   +   0 . 0 1 6 1 * M a t h . s i n ( d r * 2 * M p r ) ;  
 	 C 1   =   C 1   -   0 . 0 0 0 4 * M a t h . s i n ( d r * 3 * M p r ) ;  
 	 C 1   =   C 1   +   0 . 0 1 0 4 * M a t h . s i n ( d r * 2 * F )   -   0 . 0 0 5 1 * M a t h . s i n ( d r * ( M + M p r ) ) ;  
 	 C 1   =   C 1   -   0 . 0 0 7 4 * M a t h . s i n ( d r * ( M - M p r ) )   +   0 . 0 0 0 4 * M a t h . s i n ( d r * ( 2 * F + M ) ) ;  
 	 C 1   =   C 1   -   0 . 0 0 0 4 * M a t h . s i n ( d r * ( 2 * F - M ) )   -   0 . 0 0 0 6 * M a t h . s i n ( d r * ( 2 * F + M p r ) ) ;  
 	 C 1   =   C 1   +   0 . 0 0 1 0 * M a t h . s i n ( d r * ( 2 * F - M p r ) )   +   0 . 0 0 0 5 * M a t h . s i n ( d r * ( 2 * M p r + M ) ) ;  
 	 i f   ( T   <   - 1 1 )   {  
 	 	 d e l t a t =   0 . 0 0 1   +   0 . 0 0 0 8 3 9 * T   +   0 . 0 0 0 2 2 6 1 * T 2   -   0 . 0 0 0 0 0 8 4 5 * T 3   -   0 . 0 0 0 0 0 0 0 8 1 * T * T 3 ;  
 	 }   e l s e   {  
 	 	 d e l t a t =   - 0 . 0 0 0 2 7 8   +   0 . 0 0 0 2 6 5 * T   +   0 . 0 0 0 2 6 2 * T 2 ;  
 	 } ;  
 	 J d N e w   =   J d 1   +   C 1   -   d e l t a t ;  
 	 r e t u r n   J d N e w ;  
 }  
  
 / *   C o m p u t e   t h e   l o n g i t u d e   o f   t h e   s u n   a t   a n y   t i m e .    
   *   P a r a m e t e r :   f l o a t i n g   n u m b e r   j d n ,   t h e   n u m b e r   o f   d a y s   s i n c e   1 / 1 / 4 7 1 3   B C   n o o n  
   *   A l g o r i t h m   f r o m :   " A s t r o n o m i c a l   A l g o r i t h m s "   b y   J e a n   M e e u s ,   1 9 9 8  
   * /  
 f u n c t i o n   S u n L o n g i t u d e ( j d n )   {  
 	 v a r   T ,   T 2 ,   d r ,   M ,   L 0 ,   D L ,   L ;  
 	 T   =   ( j d n   -   2 4 5 1 5 4 5 . 0   )   /   3 6 5 2 5 ;   / /   T i m e   i n   J u l i a n   c e n t u r i e s   f r o m   2 0 0 0 - 0 1 - 0 1   1 2 : 0 0 : 0 0   G M T  
 	 T 2   =   T * T ;  
 	 d r   =   P I / 1 8 0 ;   / /   d e g r e e   t o   r a d i a n  
 	 M   =   3 5 7 . 5 2 9 1 0   +   3 5 9 9 9 . 0 5 0 3 0 * T   -   0 . 0 0 0 1 5 5 9 * T 2   -   0 . 0 0 0 0 0 0 4 8 * T * T 2 ;   / /   m e a n   a n o m a l y ,   d e g r e e  
 	 L 0   =   2 8 0 . 4 6 6 4 5   +   3 6 0 0 0 . 7 6 9 8 3 * T   +   0 . 0 0 0 3 0 3 2 * T 2 ;   / /   m e a n   l o n g i t u d e ,   d e g r e e  
 	 D L   =   ( 1 . 9 1 4 6 0 0   -   0 . 0 0 4 8 1 7 * T   -   0 . 0 0 0 0 1 4 * T 2 ) * M a t h . s i n ( d r * M ) ;  
 	 D L   =   D L   +   ( 0 . 0 1 9 9 9 3   -   0 . 0 0 0 1 0 1 * T ) * M a t h . s i n ( d r * 2 * M )   +   0 . 0 0 0 2 9 0 * M a t h . s i n ( d r * 3 * M ) ;  
 	 L   =   L 0   +   D L ;   / /   t r u e   l o n g i t u d e ,   d e g r e e  
 	 L   =   L * d r ;  
 	 L   =   L   -   P I * 2 * ( I N T ( L / ( P I * 2 ) ) ) ;   / /   N o r m a l i z e   t o   ( 0 ,   2 * P I )  
 	 r e t u r n   L ;  
 }  
  
 / *   C o m p u t e   s u n   p o s i t i o n   a t   m i d n i g h t   o f   t h e   d a y   w i t h   t h e   g i v e n   J u l i a n   d a y   n u m b e r .    
   *   T h e   t i m e   z o n e   i f   t h e   t i m e   d i f f e r e n c e   b e t w e e n   l o c a l   t i m e   a n d   U T C :   7 . 0   f o r   U T C + 7 : 0 0 .  
   *   T h e   f u n c t i o n   r e t u r n s   a   n u m b e r   b e t w e e n   0   a n d   1 1 .    
   *   F r o m   t h e   d a y   a f t e r   M a r c h   e q u i n o x   a n d   t h e   1 s t   m a j o r   t e r m   a f t e r   M a r c h   e q u i n o x ,   0   i s   r e t u r n e d .    
   *   A f t e r   t h a t ,   r e t u r n   1 ,   2 ,   3   . . .    
   * /  
 f u n c t i o n   g e t S u n L o n g i t u d e ( d a y N u m b e r ,   t i m e Z o n e )   {  
 	 r e t u r n   I N T ( S u n L o n g i t u d e ( d a y N u m b e r   -   0 . 5   -   t i m e Z o n e / 2 4 ) / P I * 6 ) ;  
 }  
  
 / *   C o m p u t e   t h e   d a y   o f   t h e   k - t h   n e w   m o o n   i n   t h e   g i v e n   t i m e   z o n e .  
   *   T h e   t i m e   z o n e   i f   t h e   t i m e   d i f f e r e n c e   b e t w e e n   l o c a l   t i m e   a n d   U T C :   7 . 0   f o r   U T C + 7 : 0 0  
   * /  
 f u n c t i o n   g e t N e w M o o n D a y ( k ,   t i m e Z o n e )   {  
 	 r e t u r n   I N T ( N e w M o o n ( k )   +   0 . 5   +   t i m e Z o n e / 2 4 ) ;  
 }  
  
 / *   F i n d   t h e   d a y   t h a t   s t a r t s   t h e   l u n e r   m o n t h   1 1   o f   t h e   g i v e n   y e a r   f o r   t h e   g i v e n   t i m e   z o n e   * /  
 f u n c t i o n   g e t L u n a r M o n t h 1 1 ( y y ,   t i m e Z o n e )   {  
 	 v a r   k ,   o f f ,   n m ,   s u n L o n g ;  
 	 / / o f f   =   j d F r o m D a t e ( 3 1 ,   1 2 ,   y y )   -   2 4 1 5 0 2 1 . 0 7 6 9 9 8 6 9 5 ;  
 	 o f f   =   j d F r o m D a t e ( 3 1 ,   1 2 ,   y y )   -   2 4 1 5 0 2 1 ;  
 	 k   =   I N T ( o f f   /   2 9 . 5 3 0 5 8 8 8 5 3 ) ;  
 	 n m   =   g e t N e w M o o n D a y ( k ,   t i m e Z o n e ) ;  
 	 s u n L o n g   =   g e t S u n L o n g i t u d e ( n m ,   t i m e Z o n e ) ;   / /   s u n   l o n g i t u d e   a t   l o c a l   m i d n i g h t  
 	 i f   ( s u n L o n g   > =   9 )   {  
 	 	 n m   =   g e t N e w M o o n D a y ( k - 1 ,   t i m e Z o n e ) ;  
 	 }  
 	 r e t u r n   n m ;  
 }  
  
 / *   F i n d   t h e   i n d e x   o f   t h e   l e a p   m o n t h   a f t e r   t h e   m o n t h   s t a r t i n g   o n   t h e   d a y   a 1 1 .   * /  
 f u n c t i o n   g e t L e a p M o n t h O f f s e t ( a 1 1 ,   t i m e Z o n e )   {  
 	 v a r   k ,   l a s t ,   a r c ,   i ;  
 	 k   =   I N T ( ( a 1 1   -   2 4 1 5 0 2 1 . 0 7 6 9 9 8 6 9 5 )   /   2 9 . 5 3 0 5 8 8 8 5 3   +   0 . 5 ) ;  
 	 l a s t   =   0 ;  
 	 i   =   1 ;   / /   W e   s t a r t   w i t h   t h e   m o n t h   f o l l o w i n g   l u n a r   m o n t h   1 1  
 	 a r c   =   g e t S u n L o n g i t u d e ( g e t N e w M o o n D a y ( k + i ,   t i m e Z o n e ) ,   t i m e Z o n e ) ;  
 	 d o   {  
 	 	 l a s t   =   a r c ;  
 	 	 i + + ;  
 	 	 a r c   =   g e t S u n L o n g i t u d e ( g e t N e w M o o n D a y ( k + i ,   t i m e Z o n e ) ,   t i m e Z o n e ) ;  
 	 }   w h i l e   ( a r c   ! =   l a s t   & &   i   <   1 4 ) ;  
 	 r e t u r n   i - 1 ;  
 }  
  
 / *   C o m v e r t   s o l a r   d a t e   d d / m m / y y y y   t o   t h e   c o r r e s p o n d i n g   l u n a r   d a t e   * /  
 f u n c t i o n   c o n v e r t S o l a r 2 L u n a r ( d d ,   m m ,   y y ,   t i m e Z o n e )   {  
 	 v a r   k ,   d a y N u m b e r ,   m o n t h S t a r t ,   a 1 1 ,   b 1 1 ,   l u n a r D a y ,   l u n a r M o n t h ,   l u n a r Y e a r ,   l u n a r L e a p ;  
 	 d a y N u m b e r   =   j d F r o m D a t e ( d d ,   m m ,   y y ) ;  
 	 k   =   I N T ( ( d a y N u m b e r   -   2 4 1 5 0 2 1 . 0 7 6 9 9 8 6 9 5 )   /   2 9 . 5 3 0 5 8 8 8 5 3 ) ;  
 	 m o n t h S t a r t   =   g e t N e w M o o n D a y ( k + 1 ,   t i m e Z o n e ) ;  
 	 i f   ( m o n t h S t a r t   >   d a y N u m b e r )   {  
 	 	 m o n t h S t a r t   =   g e t N e w M o o n D a y ( k ,   t i m e Z o n e ) ;  
 	 }  
 	 / / a l e r t ( d a y N u m b e r + "   - >   " + m o n t h S t a r t ) ;  
 	 a 1 1   =   g e t L u n a r M o n t h 1 1 ( y y ,   t i m e Z o n e ) ;  
 	 b 1 1   =   a 1 1 ;  
 	 i f   ( a 1 1   > =   m o n t h S t a r t )   {  
 	 	 l u n a r Y e a r   =   y y ;  
 	 	 a 1 1   =   g e t L u n a r M o n t h 1 1 ( y y - 1 ,   t i m e Z o n e ) ;  
 	 }   e l s e   {  
 	 	 l u n a r Y e a r   =   y y + 1 ;  
 	 	 b 1 1   =   g e t L u n a r M o n t h 1 1 ( y y + 1 ,   t i m e Z o n e ) ;  
 	 }  
 	 l u n a r D a y   =   d a y N u m b e r - m o n t h S t a r t + 1 ;  
 	 d i f f   =   I N T ( ( m o n t h S t a r t   -   a 1 1 ) / 2 9 ) ;  
 	 l u n a r L e a p   =   0 ;  
 	 l u n a r M o n t h   =   d i f f + 1 1 ;  
 	 i f   ( b 1 1   -   a 1 1   >   3 6 5 )   {  
 	 	 l e a p M o n t h D i f f   =   g e t L e a p M o n t h O f f s e t ( a 1 1 ,   t i m e Z o n e ) ;  
 	 	 i f   ( d i f f   > =   l e a p M o n t h D i f f )   {  
 	 	 	 l u n a r M o n t h   =   d i f f   +   1 0 ;  
 	 	 	 i f   ( d i f f   = =   l e a p M o n t h D i f f )   {  
 	 	 	 	 l u n a r L e a p   =   1 ;  
 	 	 	 }  
 	 	 }  
 	 }  
 	 i f   ( l u n a r M o n t h   >   1 2 )   {  
 	 	 l u n a r M o n t h   =   l u n a r M o n t h   -   1 2 ;  
 	 }  
 	 i f   ( l u n a r M o n t h   > =   1 1   & &   d i f f   <   4 )   {  
 	 	 l u n a r Y e a r   - =   1 ;  
 	 }  
 	 s   =   " N g à y   "   +   l u n a r D a y   +   "   t h á n g   "   +   l u n a r M o n t h   +   "   n m   "   +   l u n a r Y e a r  
  
 	 r e t u r n   s ;  
  
 }  
  
  
 / *   C o m v e r t   s o l a r   d a t e   d d / m m / y y y y   t o   t h e   c o r r e s p o n d i n g   l u n a r   d a t e   * /  
 f u n c t i o n   c o n v e r t S o l a r 2 L u n a r 2 ( d d ,   m m ,   y y ,   t i m e Z o n e )   {  
 	 v a r   k ,   d a y N u m b e r ,   m o n t h S t a r t ,   a 1 1 ,   b 1 1 ,   l u n a r D a y ,   l u n a r M o n t h ,   l u n a r Y e a r ,   l u n a r L e a p ;  
 	 d a y N u m b e r   =   j d F r o m D a t e ( d d ,   m m ,   y y ) ;  
 	 k   =   I N T ( ( d a y N u m b e r   -   2 4 1 5 0 2 1 . 0 7 6 9 9 8 6 9 5 )   /   2 9 . 5 3 0 5 8 8 8 5 3 ) ;  
 	 m o n t h S t a r t   =   g e t N e w M o o n D a y ( k + 1 ,   t i m e Z o n e ) ;  
 	 i f   ( m o n t h S t a r t   >   d a y N u m b e r )   {  
 	 	 m o n t h S t a r t   =   g e t N e w M o o n D a y ( k ,   t i m e Z o n e ) ;  
 	 }  
 	 / / a l e r t ( d a y N u m b e r + "   - >   " + m o n t h S t a r t ) ;  
 	 a 1 1   =   g e t L u n a r M o n t h 1 1 ( y y ,   t i m e Z o n e ) ;  
 	 b 1 1   =   a 1 1 ;  
 	 i f   ( a 1 1   > =   m o n t h S t a r t )   {  
 	 	 l u n a r Y e a r   =   y y ;  
 	 	 a 1 1   =   g e t L u n a r M o n t h 1 1 ( y y - 1 ,   t i m e Z o n e ) ;  
 	 }   e l s e   {  
 	 	 l u n a r Y e a r   =   y y + 1 ;  
 	 	 b 1 1   =   g e t L u n a r M o n t h 1 1 ( y y + 1 ,   t i m e Z o n e ) ;  
 	 }  
 	 l u n a r D a y   =   d a y N u m b e r - m o n t h S t a r t + 1 ;  
 	 d i f f   =   I N T ( ( m o n t h S t a r t   -   a 1 1 ) / 2 9 ) ;  
 	 l u n a r L e a p   =   0 ;  
 	 l u n a r M o n t h   =   d i f f + 1 1 ;  
 	 i f   ( b 1 1   -   a 1 1   >   3 6 5 )   {  
 	 	 l e a p M o n t h D i f f   =   g e t L e a p M o n t h O f f s e t ( a 1 1 ,   t i m e Z o n e ) ;  
 	 	 i f   ( d i f f   > =   l e a p M o n t h D i f f )   {  
 	 	 	 l u n a r M o n t h   =   d i f f   +   1 0 ;  
 	 	 	 i f   ( d i f f   = =   l e a p M o n t h D i f f )   {  
 	 	 	 	 l u n a r L e a p   =   1 ;  
 	 	 	 }  
 	 	 }  
 	 }  
 	 i f   ( l u n a r M o n t h   >   1 2 )   {  
 	 	 l u n a r M o n t h   =   l u n a r M o n t h   -   1 2 ;  
 	 }  
 	 i f   ( l u n a r M o n t h   > =   1 1   & &   d i f f   <   4 )   {  
 	 	 l u n a r Y e a r   - =   1 ;  
 	 }  
 	 s   =   l u n a r D a y   +   " / "   +   l u n a r M o n t h   +   " / "   +   l u n a r Y e a r  
  
 	 r e t u r n   s ;  
  
 }  
  
  
 / *   C o n v e r t   a   l u n a r   d a t e   t o   t h e   c o r r e s p o n d i n g   s o l a r   d a t e   * /  
 f u n c t i o n   c o n v e r t L u n a r 2 S o l a r ( l u n a r D a y ,   l u n a r M o n t h ,   l u n a r Y e a r ,   l u n a r L e a p ,   t i m e Z o n e )   {  
 	 v a r   k ,   a 1 1 ,   b 1 1 ,   o f f ,   l e a p O f f ,   l e a p M o n t h ,   m o n t h S t a r t ;  
 	 i f   ( l u n a r M o n t h   <   1 1 )   {  
 	 	 a 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r - 1 ,   t i m e Z o n e ) ;  
 	 	 b 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r ,   t i m e Z o n e ) ;  
 	 }   e l s e   {  
 	 	 a 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r ,   t i m e Z o n e ) ;  
 	 	 b 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r + 1 ,   t i m e Z o n e ) ;  
 	 }  
 	 k   =   I N T ( 0 . 5   +   ( a 1 1   -   2 4 1 5 0 2 1 . 0 7 6 9 9 8 6 9 5 )   /   2 9 . 5 3 0 5 8 8 8 5 3 ) ;  
 	 o f f   =   l u n a r M o n t h   -   1 1 ;  
 	 i f   ( o f f   <   0 )   {  
 	 	 o f f   + =   1 2 ;  
 	 }  
 	 i f   ( b 1 1   -   a 1 1   >   3 6 5 )   {  
 	 	 l e a p O f f   =   g e t L e a p M o n t h O f f s e t ( a 1 1 ,   t i m e Z o n e ) ;  
 	 	 l e a p M o n t h   =   l e a p O f f   -   2 ;  
 	 	 i f   ( l e a p M o n t h   <   0 )   {  
 	 	 	 l e a p M o n t h   + =   1 2 ;  
 	 	 }  
 	 	 i f   ( l u n a r L e a p   ! =   0   & &   l u n a r M o n t h   ! =   l e a p M o n t h )   {  
 	 	 	 r e t u r n   n e w   A r r a y ( 0 ,   0 ,   0 ) ;  
 	 	 }   e l s e   i f   ( l u n a r L e a p   ! =   0   | |   o f f   > =   l e a p O f f )   {  
 	 	 	 o f f   + =   1 ;  
 	 	 }  
 	 }  
 	 m o n t h S t a r t   =   g e t N e w M o o n D a y ( k + o f f ,   t i m e Z o n e ) ;  
 	 r e t u r n   j d T o D a t e ( m o n t h S t a r t + l u n a r D a y - 1 ) ;  
 }  
  
  
  
 f u n c t i o n   t h a n g d l ( l u n a r D a y ,   l u n a r M o n t h ,   l u n a r Y e a r ,   l u n a r L e a p ,   t i m e Z o n e )   {  
 	 v a r   k ,   a 1 1 ,   b 1 1 ,   o f f ,   l e a p O f f ,   l e a p M o n t h ,   m o n t h S t a r t ;  
 	 i f   ( l u n a r M o n t h   <   1 1 )   {  
 	 	 a 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r - 1 ,   t i m e Z o n e ) ;  
 	 	 b 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r ,   t i m e Z o n e ) ;  
 	 }   e l s e   {  
 	 	 a 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r ,   t i m e Z o n e ) ;  
 	 	 b 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r + 1 ,   t i m e Z o n e ) ;  
 	 }  
 	 k   =   I N T ( 0 . 5   +   ( a 1 1   -   2 4 1 5 0 2 1 . 0 7 6 9 9 8 6 9 5 )   /   2 9 . 5 3 0 5 8 8 8 5 3 ) ;  
 	 o f f   =   l u n a r M o n t h   -   1 1 ;  
 	 i f   ( o f f   <   0 )   {  
 	 	 o f f   + =   1 2 ;  
 	 }  
 	 i f   ( b 1 1   -   a 1 1   >   3 6 5 )   {  
 	 	 l e a p O f f   =   g e t L e a p M o n t h O f f s e t ( a 1 1 ,   t i m e Z o n e ) ;  
 	 	 l e a p M o n t h   =   l e a p O f f   -   2 ;  
 	 	 i f   ( l e a p M o n t h   <   0 )   {  
 	 	 	 l e a p M o n t h   + =   1 2 ;  
 	 	 }  
 	 	 i f   ( l u n a r L e a p   ! =   0   & &   l u n a r M o n t h   ! =   l e a p M o n t h )   {  
 	 	 	 r e t u r n   n e w   A r r a y ( 0 ,   0 ,   0 ) ;  
 	 	 }   e l s e   i f   ( l u n a r L e a p   ! =   0   | |   o f f   > =   l e a p O f f )   {  
 	 	 	 o f f   + =   1 ;  
 	 	 }  
 	 }  
 	 m o n t h S t a r t   =   g e t N e w M o o n D a y ( k + o f f ,   t i m e Z o n e ) ;  
 	 j d   =   m o n t h S t a r t + l u n a r D a y - 1 ;  
 	 i f   ( j d   >   2 2 9 9 1 6 0 )   {   / /   A f t e r   5 / 1 0 / 1 5 8 2 ,   G r e g o r i a n   c a l e n d a r  
 	 	 a   =   j d   +   3 2 0 4 4 ;  
 	 	 b   =   I N T ( ( 4 * a + 3 ) / 1 4 6 0 9 7 ) ;  
 	 	 c   =   a   -   I N T ( ( b * 1 4 6 0 9 7 ) / 4 ) ;  
 	 }   e l s e   {  
 	 	 b   =   0 ;  
 	 	 c   =   j d   +   3 2 0 8 2 ;  
 	 }  
 	 d   =   I N T ( ( 4 * c + 3 ) / 1 4 6 1 ) ;  
 	 e   =   c   -   I N T ( ( 1 4 6 1 * d ) / 4 ) ;  
 	 m   =   I N T ( ( 5 * e + 2 ) / 1 5 3 ) ;  
 	 d a y   =   e   -   I N T ( ( 1 5 3 * m + 2 ) / 5 )   +   1 ;  
 	 m o n t h   =   m   +   3   -   1 2 * I N T ( m / 1 0 ) ;  
 	 y e a r   =   b * 1 0 0   +   d   -   4 8 0 0   +   I N T ( m / 1 0 ) ;  
 	 r e t u r n   m o n t h ;  
 }  
  
  
 f u n c t i o n   n a m d l ( l u n a r D a y ,   l u n a r M o n t h ,   l u n a r Y e a r ,   l u n a r L e a p ,   t i m e Z o n e )   {  
 	 v a r   k ,   a 1 1 ,   b 1 1 ,   o f f ,   l e a p O f f ,   l e a p M o n t h ,   m o n t h S t a r t ;  
 	 i f   ( l u n a r M o n t h   <   1 1 )   {  
 	 	 a 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r - 1 ,   t i m e Z o n e ) ;  
 	 	 b 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r ,   t i m e Z o n e ) ;  
 	 }   e l s e   {  
 	 	 a 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r ,   t i m e Z o n e ) ;  
 	 	 b 1 1   =   g e t L u n a r M o n t h 1 1 ( l u n a r Y e a r + 1 ,   t i m e Z o n e ) ;  
 	 }  
 	 k   =   I N T ( 0 . 5   +   ( a 1 1   -   2 4 1 5 0 2 1 . 0 7 6 9 9 8 6 9 5 )   /   2 9 . 5 3 0 5 8 8 8 5 3 ) ;  
 	 o f f   =   l u n a r M o n t h   -   1 1 ;  
 	 i f   ( o f f   <   0 )   {  
 	 	 o f f   + =   1 2 ;  
 	 }  
 	 i f   ( b 1 1   -   a 1 1   >   3 6 5 )   {  
 	 	 l e a p O f f   =   g e t L e a p M o n t h O f f s e t ( a 1 1 ,   t i m e Z o n e ) ;  
 	 	 l e a p M o n t h   =   l e a p O f f   -   2 ;  
 	 	 i f   ( l e a p M o n t h   <   0 )   {  
 	 	 	 l e a p M o n t h   + =   1 2 ;  
 	 	 }  
 	 	 i f   ( l u n a r L e a p   ! =   0   & &   l u n a r M o n t h   ! =   l e a p M o n t h )   {  
 	 	 	 r e t u r n   n e w   A r r a y ( 0 ,   0 ,   0 ) ;  
 	 	 }   e l s e   i f   ( l u n a r L e a p   ! =   0   | |   o f f   > =   l e a p O f f )   {  
 	 	 	 o f f   + =   1 ;  
 	 	 }  
 	 }  
 	 m o n t h S t a r t   =   g e t N e w M o o n D a y ( k + o f f ,   t i m e Z o n e ) ;  
 	 j d   =   m o n t h S t a r t + l u n a r D a y - 1 ;  
 	 i f   ( j d   >   2 2 9 9 1 6 0 )   {   / /   A f t e r   5 / 1 0 / 1 5 8 2 ,   G r e g o r i a n   c a l e n d a r  
 	 	 a   =   j d   +   3 2 0 4 4 ;  
 	 	 b   =   I N T ( ( 4 * a + 3 ) / 1 4 6 0 9 7 ) ;  
 	 	 c   =   a   -   I N T ( ( b * 1 4 6 0 9 7 ) / 4 ) ;  
 	 }   e l s e   {  
 	 	 b   =   0 ;  
 	 	 c   =   j d   +   3 2 0 8 2 ;  
 	 }  
 	 d   =   I N T ( ( 4 * c + 3 ) / 1 4 6 1 ) ;  
 	 e   =   c   -   I N T ( ( 1 4 6 1 * d ) / 4 ) ;  
 	 m   =   I N T ( ( 5 * e + 2 ) / 1 5 3 ) ;  
 	 d a y   =   e   -   I N T ( ( 1 5 3 * m + 2 ) / 5 )   +   1 ;  
 	 m o n t h   =   m   +   3   -   1 2 * I N T ( m / 1 0 ) ;  
 	 y e a r   =   b * 1 0 0   +   d   -   4 8 0 0   +   I N T ( m / 1 0 ) ;  
 	 r e t u r n   y e a r ;  
 }  
 