Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Realms;
- namespace Calculator2
- {
- public class MyDate : RealmObject
- {
- public int Day { get; set; }
- public int Month { get; set; }
- public int Year { get; set; }
- public int Hour { get; set; }
- public int Minute { get; set; }
- public int Second { get; set; }
- public string Type { get; set; }
- public override string ToString()
- {
- return Month + "." + Day + "." + Year + " " + Hour + "." + Minute + "." + Second + " " + Type;
- }
- public MyDate(string s)
- {
- string[] str = s.Split(' ');
- string[] Date = str[0].Split(new Char[] { '.', '/', ':' });
- string[] Time = str[1].Split(new Char[] { '.', '/', ':' });
- Day = Int32.Parse(Date[1]);
- Month = Int32.Parse(Date[0]);
- Year = Int32.Parse(Date[2]);
- Hour = Int32.Parse(Time[0]);
- Minute = Int32.Parse(Time[1]);
- Second = Int32.Parse(Time[2]);
- if (str.Length == 3)
- Type = str[2];
- else
- Type = "24";
- }
- public MyDate()
- {
- }
- public static long DateToLong (MyDate a)
- {
- int[] CntDay = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- long ans = 0;
- ans += 6940 * 24 * 60 * 60;
- for (int i = 0; i < 12; ++i) {
- if (i + 1 < a.Month)
- ans += CntDay[i] * 24 * 60 * 60;
- }
- for (int i = 1; i <= 31; ++i)
- {
- if (i < a.Day)
- ans += 24 * 60 * 60;
- }
- for (int i = 1; i <= 24; ++i)
- {
- if (i <= a.Hour)
- ans += 60 * 60;
- }
- for (int i = 1; i < 60; ++i)
- {
- if (i <= a.Minute)
- ans += 60;
- }
- ans += a.Second;
- return ans;
- }
- public static string TimeToString(long val, int type)
- {
- long seconds = 0, hours = 0, minutes = 0, days = 0;
- if (type == 1 || type == 2)
- {
- if (val > 365 * 24 * 60 * 60)
- {
- if (type == 1)
- return "Вы не курили больше года!";
- else
- return "Вы не пили больше года!";
- }
- }
- if (val / (60 * 60 * 24) > 0) {
- days = val / (60 * 60 * 24);
- val -= days * 60 * 60 * 24;
- }
- if (val / (60 * 60) > 0)
- {
- hours = val / (60 * 60);
- val -= hours * 60 * 60;
- }
- if (val / (60) > 0)
- {
- minutes = val / (60);
- val -= minutes * 60;
- }
- if (val > 0)
- {
- seconds = val;
- }
- string StrType = "";
- if (type == 1)
- StrType = "сигареты:";
- if (type == 2)
- StrType = "кружки:";
- if (type == 3)
- StrType = "сигаретами:";
- if (type == 4)
- StrType = "кружками:";
- if (type == 5)
- StrType = "сигареты";
- if (type == 6)
- StrType = "кружки";
- if (type == 1 || type == 2)
- {
- return $"С последней {StrType} {days}д {hours}ч {minutes}м {seconds}с!";
- }
- if (type == 3 || type == 4)
- {
- return $"Среднее время между {StrType} {days}д {hours}ч {minutes}м {seconds}с!";
- }
- if (type == 5 || type == 6)
- {
- return $"С первой {StrType} прошло: {days}д {hours}ч {minutes}м {seconds}с!";
- }
- if (type == 7)
- {
- return $"Максимальный промежуток воздержания: {days}д {hours}ч {minutes}м {seconds}с!";
- }
- if (type == 8)
- {
- return $"Длительность курения последней сигареты: {days}д {hours}ч {minutes}м {seconds}с!";
- }
- if (type == 9)
- {
- return $"Длительность последнего принятия алкоголя: {days}д {hours}ч {minutes}м {seconds}с!";
- }
- return "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement