Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FromSi/9047cc22b6d1ef291c5f4642bd4c9180 to your computer and use it in GitHub Desktop.
Save FromSi/9047cc22b6d1ef291c5f4642bd4c9180 to your computer and use it in GitHub Desktop.
/// Получить объект с процентами текущей даты.
getDateNowInfoList() {
/// Ответ метода.
var answer = {};
/// Дата прям сецчас.
DateTime nowDate = new DateTime.now();
/// Добавить день.
answer['day'] = getPercentEnd(
getPercentFull(nowDate, getFutureDateDay(nowDate)),
getTimeFullDay(nowDate));
/// Добавить месяц.
answer['month'] = getPercentEnd(
getPercentFull(nowDate, getFutureDateMonth(nowDate)),
getTimeFullMonth(nowDate));
/// Добавить год.
answer['year'] = getPercentEnd(
getPercentFull(nowDate, getFutureDateYear(nowDate)),
getTimeFullYear(nowDate));
return answer;
}
/// Получить полный процент окончания текущего (Или дня, или месяца, или года).
///
/// Атрибуты функции:
/// Тип[DateTime] Атрибут[now] - принимает текущую дату пользователя;
/// Тип[int] Атрибут[future] - принимает будущую дату пользователя.
getPercentFull(DateTime now, int future) {
return future - now.millisecondsSinceEpoch;
}
/// Получить дату на один день больше.
///
/// Атрибуты функции:
/// Тип[DateTime] Атрибут[now] - принимает текущую дату пользователя.
getFutureDateDay(DateTime now) {
DateTime today = new DateTime(now.year, now.month, now.day);
return today.add(new Duration(days: 1)).millisecondsSinceEpoch;
}
/// Получить дату на один месяц больше.
///
/// Атрибуты функции:
/// Тип[DateTime] Атрибут[now] - принимает текущую дату пользователя.
getFutureDateMonth(DateTime now) {
return new DateTime(now.year, now.month + 1, 1).millisecondsSinceEpoch;
}
/// Получить дату на один год больше.
///
/// Атрибуты функции:
/// Тип[DateTime] Атрибут[now] - принимает текущую дату пользователя.
getFutureDateYear(DateTime now) {
return new DateTime(now.year + 1, 1, 1).millisecondsSinceEpoch;
}
/// Получить миллисекунды полный день.
///
/// Атрибуты функции:
/// Тип[DateTime] Атрибут[now] - принимает текущую дату пользователя.
getTimeFullDay(DateTime now) {
int dateA = new DateTime(now.year, 1, 1).millisecondsSinceEpoch;
int dateB = new DateTime(now.year, 1, 2).millisecondsSinceEpoch;
return dateB - dateA;
}
/// Получить в миллисекундах полный месяц.
///
/// Атрибуты функции:
/// Тип[DateTime] Атрибут[now] - принимает текущую дату пользователя.
getTimeFullMonth(DateTime now) {
int dateA = new DateTime(now.year, now.month, 1).millisecondsSinceEpoch;
int dateB = new DateTime(now.year, now.month + 1, 1).millisecondsSinceEpoch;
return dateB - dateA;
}
/// Получить в миллисекундах полный год.
///
/// Атрибуты функции:
/// Тип[DateTime] Атрибут[now] - принимает текущую дату пользователя.
getTimeFullYear(DateTime now) {
int dateA = new DateTime(now.year, 1, 1).millisecondsSinceEpoch;
int dateB = new DateTime(now.year + 1, 1, 1).millisecondsSinceEpoch;
return dateB - dateA;
}
/// Получить процент окончательного завершения (Или дня, или месяца, или года).
///
/// Атрибуты функции:
/// Тип[int] Атрибут[percentFull] - принимает окончание текущей даты;
/// Тип[int] Атрибут[timeFull] - принимает полное время текущей даты.
getPercentEnd(int percentFull, int timeFull) {
double answer = percentFull.abs() / timeFull.abs();
answer = 1 - answer;
return (answer * 100).toInt() / 100;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment