 	__host__ __device__
 	int16_t operator()(int64_t unixTime) // unixTime is milliseconds since the UNIX epoch
 	{
-		int totalDays = 719469 + unixTime/86400000;
-
-		int year = 400*totalDays/146097;
-		totalDays -= (365*year + year/4 - year/100 + year/400);
-		int month = (totalDays*5 + 457)/153;
-
-		int day = totalDays - ((153*month - 457)/5);
-
-		if (day == 0){
-			month--;
-			day = totalDays - ((153*month - 457)/5);
-		}
-		return day;
+		const int z = ((unixTime >= 0 ? unixTime : unixTime - 86399999) / 86400000) + 719468;
+		const int era = (z >= 0 ? z : z - 146096) / 146097;
+		const unsigned doe = static_cast<unsigned>(z - era * 146097);          // [0, 146096]
+		const unsigned yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365;  // [0, 399]
+		const int y = static_cast<int>(yoe) + era * 400;
+		const unsigned doy = doe - (365*yoe + yoe/4 - yoe/100);                // [0, 365]
+		const unsigned mp = (5*doy + 2)/153;                                   // [0, 11]
+		return doy - (153*mp+2)/5 + 1;                             // [1, 31]
 	}
 };
 

	__host__ __device__
	int16_t operator()(int64_t unixTime) // unixTime is milliseconds since the UNIX epoch
	{
		int totalDays = 719469 + unixTime/86400000;
		int year = 400*totalDays/146097;
		totalDays -= (365*year + year/4 - year/100 + year/400);
		int month = (totalDays*5 + 457)/153;
		if ((totalDays - ((153*month - 457)/5)) == 0){
			month--;
		}
		if(month > 12){
			year++;
		}
		return year;
	}
};


	__host__ __device__
	int16_t operator()(int64_t unixTime) // unixTime is milliseconds since the UNIX epoch
	{
		const int z = ((unixTime >= 0 ? unixTime : unixTime - 86399999) / 86400000) + 719468;
		const int era = (z >= 0 ? z : z - 146096) / 146097;
		const unsigned doe = static_cast<unsigned>(z - era * 146097);          // [0, 146096]
		const unsigned yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365;  // [0, 399]
		const int y = static_cast<int>(yoe) + era * 400;
		const unsigned doy = doe - (365*yoe + yoe/4 - yoe/100);                // [0, 365]
		const unsigned mp = (5*doy + 2)/153;                                   // [0, 11]
		const unsigned d = doy - (153*mp+2)/5 + 1;                             // [1, 31]
		return mp + (mp < 10 ? 3 : -9);                            // [1, 12]

	}
};

