File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -159,4 +159,18 @@ describe("Clock.vue", () => {
159159    expect ( wrapper . find ( ".clock__hour" ) [ 0 ] . text ( ) ) . toContain ( "09" ) ; 
160160    expect ( wrapper . find ( ".clock__ampm" ) [ 0 ] . text ( ) ) . toContain ( "pm" ) ; 
161161  } ) ; 
162+ 
163+   it ( "displays 12pm (noon/midday) in twelveHour mode" ,  ( )  =>  { 
164+     clock . tick ( 12  *  hours ) ; 
165+     const  wrapper  =  mount ( Clock ,  {  propsData : {  twelveHour : true  }  } ) ; 
166+     expect ( wrapper . find ( ".clock__hour" ) [ 0 ] . text ( ) ) . toContain ( "12" ) ; 
167+     expect ( wrapper . find ( ".clock__ampm" ) [ 0 ] . text ( ) ) . toContain ( "pm" ) ; 
168+   } ) ; 
169+ 
170+   it ( "displays 12am (midnight) in twelveHour mode" ,  ( )  =>  { 
171+     clock . tick ( 0  *  hours ) ; 
172+     const  wrapper  =  mount ( Clock ,  {  propsData : {  twelveHour : true  }  } ) ; 
173+     expect ( wrapper . find ( ".clock__hour" ) [ 0 ] . text ( ) ) . toContain ( "12" ) ; 
174+     expect ( wrapper . find ( ".clock__ampm" ) [ 0 ] . text ( ) ) . toContain ( "am" ) ; 
175+   } ) ; 
162176} ) ; 
Original file line number Diff line number Diff line change @@ -40,13 +40,13 @@ const getMinutes = () => padZero(getDate().getMinutes());
4040
4141const  getHour  =  twelveHour  =>  {
4242  let  hours =  getDate ().getHours (); 
43-   if  (twelveHour  &&  hours  >   12 ) { 
44-     hours =  hours -  12 ; 
43+   if  (twelveHour) { 
44+     hours =  hours %   12   ||  12 ; 
4545  } 
4646  return  padZero (hours); 
4747}; 
4848
49- const  getAmPm  =  () =>  (getDate ().getHours () >  12  ?  " pm"   :  " am"  );
49+ const  getAmPm  =  () =>  (getDate ().getHours () >=   12  ?  " pm"   :  " am"  );
5050
5151export  default  {
5252  name:  " vue-digital-clock"  , 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments