Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. unsigned int get_day(unsigned int timestamp)
  2. {
  3. time_t t = timestamp;
  4. struct tm * timeval = gmtime(&t);
  5. return timeval->tm_wday;//0 = sun
  6. }
  7.  
  8. unsigned int get_start_of_day(unsigned int timestamp)
  9. {
  10. int day_of_w = get_day(timestamp);
  11. while(get_day(timestamp-3600) == day_of_w) timestamp -= 3600;
  12. while(get_day(timestamp-60) == day_of_w) timestamp -= 60;
  13. while(get_day(timestamp-1) == day_of_w) timestamp--;
  14.  
  15. return timestamp;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement