Last active
          August 29, 2015 14:12 
        
      - 
      
- 
        Save keelii/55b2cb3c4d87de846a8e to your computer and use it in GitHub Desktop. 
    how many weeks from now to sometime
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function nWeekFromNow(ts) { | |
| var now = new Date(); | |
| now.setHours(0); | |
| now.setMinutes(0); | |
| now.setSeconds(0); | |
| now.setMilliseconds(0); | |
| var nowTS = now.getTime(); | |
| var nowDay = now.getDay() || 7; | |
| var startTS = nowTS - (nowDay - 1) * 24 * 60 * 60 * 1000; | |
| var nWeek = Math.ceil( Math.abs(startTS - ts) / 1000 / 60 / 60 / 24 / 7 ); | |
| return ts >= startTS ? 0 : nWeek; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment