Hacker News new | past | comments | ask | show | jobs | submit login

I wear Xiaomi's Amazfit Pro 3R. Digital. Wrist band. Hung at midnight of 29th Feb today. Did a bunch of factory reset but didn't recover. And then recovered at the morning of 1st of March.

Date is relatively simple.

    days_in_month(year, month) :
      if(month==2) return days_in_feb(year)
      //all other months have constant number of days, always.

    days_in_feb(year,month) :
      if(!(year % 400)) return 29;
      if(!(year % 100)) return 28;
      if(!(year % 4)) return 29; 
      return 28;
And you are done for all Gregorian years.



your function returns 29 days for every year not divisible by 400


!(x % y) is the same as (x % y == 0), which means the remainder is zero, so x is divisible by y.

So it returns 29 if divisible by 400, 28 if divisible by 100, etc.


Oops, you are absolutely correct!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: