view include/core/date.h @ 337:a7d4e5107531

dep/animone: REFACTOR ALL THE THINGS 1: animone now has its own syntax divergent from anisthesia, making different platforms actually have their own sections 2: process names in animone are now called `comm' (this will probably break things). this is what its called in bsd/linux so I'm just going to use it everywhere 3: the X11 code now checks for the existence of a UTF-8 window title and passes it if available 4: ANYTHING THATS NOT LINUX IS 100% UNTESTED AND CAN AND WILL BREAK! I still actually need to test the bsd code. to be honest I'm probably going to move all of the bsds into separate files because they're all essentially different operating systems at this point
author Paper <paper@paper.us.eu.org>
date Wed, 19 Jun 2024 12:51:15 -0400
parents b5d6c27c308f
children
line wrap: on
line source

#ifndef MINORI_CORE_DATE_H_
#define MINORI_CORE_DATE_H_

#include "json/json_fwd.hpp"

#include "core/time.h"

#include <optional>
#include <string>

class QDate;

/* TODO: refactor constructors, as they aren't meant
 * to be used in this way and may cause problems down
 * the line */

class Date {
public:
	using Year = unsigned int;
	using Day = unsigned char;
	enum class Month {
		Jan = 0,
		Feb,
		Mar,
		Apr,
		May,
		Jun,
		Jul,
		Aug,
		Sep,
		Oct,
		Nov,
		Dec
	};

	Date();
	Date(Year y);
	Date(Year y, Month m, Day d);
	Date(const std::string& str);
	Date(const QDate& date);
	Date(const nlohmann::json& json);
	Date(Time::Timestamp timestamp);

	bool IsValid() const;

	void SetYear(Year y);
	void SetMonth(Month m);
	void SetDay(Day d);

	void VoidYear();
	void VoidMonth();
	void VoidDay();

	std::optional<Year> GetYear() const;
	std::optional<Month> GetMonth() const;
	std::optional<Day> GetDay() const;
	QDate GetAsQDate() const;
	nlohmann::json GetAsAniListJson() const;

private:
	std::optional<Year> year;
	std::optional<Month> month;
	std::optional<Day> day;
};

#endif // MINORI_CORE_DATE_H_