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