Downloads containing SEdatetime.asc

Downloads
Name Author Game Mode Rating
JJ2+ Only: Find It Out (Single Player)Featured Download Superjazz Single player 9.1 Download file

File preview

namespace se {
class Duration {
	private int64 value;
	Duration(int64 ms = 0) {
		value = ms;
	}
	Duration(const Duration& other) {
		value = other.value;
	}
	Duration opNeg() const {
		return Duration(-value);
	}
	bool opEquals(const Duration& other) const {
		return value == other.value;
	}
	int opCmp(const Duration& other) const {
		int64 otherVal = other.value;
		return value > otherVal ? 1 : value < otherVal ? -1 : 0;
	}
	Duration opAdd(const Duration& other) const {
		return Duration(value + other.value);
	}
	Duration opSub(const Duration& other) const {
		return Duration(value - other.value);
	}
	Duration opMul(int64 other) const {
		return Duration(value * other);
	}
	Duration opMul(double other) const {
		return Duration(int64(value * other));
	}
	Duration opMul_r(int64 other) const {
		return Duration(value * other);
	}
	Duration opMul_r(double other) const {
		return Duration(int64(value * other));
	}
	Duration opDiv(int64 other) const {
		return Duration(value / other);
	}
	Duration opDiv(double other) const {
		return Duration(int64(value / other));
	}
	double opDiv(const Duration& other) const {
		return value / double(other.value);
	}
	Duration opMod(const Duration& other) const {
		return Duration(value % other.value);
	}
	Duration& opAddAssign(const Duration& other) {
		value += other.value;
		return this;
	}
	Duration& opSubAssign(const Duration& other) {
		value -= other.value;
		return this;
	}
	Duration& opMulAssign(int64 other) {
		value *= other;
		return this;
	}
	Duration& opMulAssign(double other) {
		value = int64(value * other);
		return this;
	}
	Duration& opDivAssign(int64 other) {
		value /= other;
		return this;
	}
	Duration& opDivAssign(double other) {
		value = int64(value / other);
		return this;
	}
	Duration& opModAssign(const Duration& other) {
		value %= other.value;
		return this;
	}
	int64 inMilliseconds() const {
		return value;
	}
	double inSeconds() const {
		return value / 1000.0;
	}
	double inMinutes() const {
		return value / 60000.0;
	}
	double inHours() const {
		return value / 3600000.0;
	}
	double inDays() const {
		return value / 86400000.0;
	}
	string format(const string &in s) const {
		string result;
		uint length = s.length();
		uint64 uValue = value >= 0 ? value : -value;
		uint64 toWrite = 0;
		bool normalText = true;
		for (uint i = 0; i < length; i++) {
			if (normalText) {
				if (s[i] == 37)
					normalText = false;
				else
					result += s.substr(i, 1);
			} else {
				switch (s[i]) {
					case 37:
						result += '%';
						break;
					case 43:
						if (value > 0)
							result += '+';
						else if (value < 0)
							result += '-';
						break;
					case 45:
						if (value < 0)
							result += '-';
						break;
					case 68:
						toWrite = uValue / 86400000;
						result += formatUInt(toWrite);
						break;
					case 72:
						toWrite = uValue / 3600000;
						result += formatUInt(toWrite);
						break;
					case 77:
						toWrite = uValue / 60000;
						result += formatUInt(toWrite);
						break;
					case 80:
						if (toWrite != 1)
							result += 'S';
						break;
					case 83:
						toWrite = uValue / 1000;
						result += formatUInt(toWrite);
						break;
					case 88:
						toWrite = uValue;
						result += formatUInt(toWrite);
						break;
					case 104:
						toWrite = uValue / 3600000 % 24;
						result += formatUInt(toWrite, '0', 2);
						break;
					case 109:
						toWrite = uValue / 60000 % 60;
						result += formatUInt(toWrite, '0', 2);
						break;
					case 112:
						if (toWrite != 1)
							result += 's';
						break;
					case 115:
						toWrite = uValue / 1000 % 60;
						result += formatUInt(toWrite, '0', 2);
						break;
					case 120:
						toWrite = uValue % 1000;
						result += formatUInt(toWrite, '0', 3);
						break;
				}
				normalText = true;
			}
		}
		return result;
	}
}
class TimePoint {
	private int64 value;
	TimePoint(int64 ms = 0) {
		value = ms;
	}
	TimePoint(const TimePoint& other) {
		value = other.value;
	}
	bool opEquals(const TimePoint& other) const {
		return value == other.value;
	}
	int opCmp(const TimePoint& other) const {
		int64 otherVal = other.value;
		return value > otherVal ? 1 : value < otherVal ? -1 : 0;
	}
	TimePoint opAdd(const Duration& other) const {
		return TimePoint(value + other.inMilliseconds());
	}
	TimePoint opAdd_r(const Duration& other) const {
		return TimePoint(value + other.inMilliseconds());
	}
	TimePoint opSub(const Duration& other) const {
		return TimePoint(value - other.inMilliseconds());
	}
	Duration opSub(const TimePoint& other) const {
		return Duration(value - other.value);
	}
	TimePoint& opAddAssign(const Duration& other) {
		value += other.inMilliseconds();
		return this;
	}
	TimePoint& opSubAssign(const Duration& other) {
		value -= other.inMilliseconds();
		return this;
	}
	Duration timeSinceEpoch() const {
		return Duration(value);
	}
}
class Date {
	private int64 year;
	private int month, day, weekday, yearday, hour, minute, second, millisecond;
	Date(const TimePoint& time) {
		const array<int> dayInMonth = {31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29};
		Duration timeSinceEpoch = time - TimePoint(951868800000);
		int64 ms = timeSinceEpoch.inMilliseconds();
		int64 days = ms / 86400000;
		ms %= 86400000;
		if (ms < 0) {
			ms += 86400000;
			days--;
		}
		millisecond = ms % 1000;
		ms /= 1000;
		second = ms % 60;
		ms /= 60;
		minute = ms % 60;
		hour = ms / 60;
		weekday = (days + 3) % 7;
		if (weekday < 0)
			weekday += 7;
		int64 qc = days / 146097;
		days %= 146097;
		if (days < 0) {
			days += 146097;
			qc--;
		}
		int c = days / 36524;
		if (c == 4)
			c--;
		days -= c * 36524;
		int q = days / 1461;
		if (q == 25)
			q--;
		days -= q * 1461;
		year = days / 365;
		if (year == 4)
			year--;
		day = days - year * 365;
		int leap = year == 0 && (q != 0 || c == 0) ? 1 : 0;
		yearday = day + leap + 59;
		if (yearday >= 365 + leap)
			yearday -= 365 + leap;
		year += q * 4 + c * 100 + qc * 400 + 2000;
		for (month = 0; day >= dayInMonth[month]; month++) {
			day -= dayInMonth[month];
		}
		day++;
		month += 2;
		if (month >= 12) {
			month -= 12;
			year++;
		}
	}
	int64 getYear() const {
		return year;
	}
	int getMonth() const {
		return month;
	}
	int getDayOfMonth() const {
		return day;
	}
	int getDayOfWeek() const {
		return weekday;
	}
	int getDayOfYear() const {
		return yearday;
	}
	int getHour() const {
		return hour;
	}
	int getMinute() const {
		return minute;
	}
	int getSecond() const {
		return second;
	}
	int getMillisecond() const {
		return millisecond;
	}
	string format(const string &in s) const {
		const array<string> monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
		const array<string> dayNames = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
		string result;
		uint length = s.length();
		bool normalText = true;
		for (uint i = 0; i < length; i++) {
			if (normalText) {
				if (s[i] == 37)
					normalText = false;
				else
					result += s.substr(i, 1);
			} else {
				switch (s[i]) {
					case 37:
						result += '%';
						break;
					case 65:
						result += dayNames[weekday];
						break;
					case 68:
						result += formatInt(yearday + 1);
						break;
					case 72:
						result += formatInt(hour);
						break;
					case 77:
						result += formatInt(month + 1);
						break;
					case 78:
						result += monthNames[month];
						break;
					case 79:
						result += formatInt(month + 1, '0', 2);
						break;
					case 87:
						result += formatInt(weekday + 1);
						break;
					case 89:
						result += formatInt(year);
						break;
					case 97:
						result += dayNames[weekday].substr(0, 3);
						break;
					case 98:
						result += formatInt(day, '0', 2);
						break;
					case 100:
						result += formatInt(day);
						break;
					case 104:
						result += formatInt(hour, '0', 2);
						break;
					case 109:
						result += formatInt(minute, '0', 2);
						break;
					case 110:
						result += monthNames[month].substr(0, 3);
						break;
					case 111:
						result += formatInt(day) + (day > 3 && day < 20 ? "th" : day % 10 == 1 ? "st" : day % 10 == 2 ? "nd" : "th");
						break;
					case 115:
						result += formatInt(second, '0', 2);
						break;
					case 120:
						result += formatInt(millisecond, '0', 3);
						break;
					case 121:
						result += year > 0 ? formatInt(year) : formatInt(1 - year) + " BC";
						break;
				}
				normalText = true;
			}
		}
		return result;
	}
}
namespace time {
	TimePoint now() {
		return TimePoint(::jjUnixTimeMs());
	}
	TimePoint epoch() {
		return TimePoint(0);
	}
}
}