diff --git a/DBClasses.cs b/DBClasses.cs index 10f8db1..7836403 100644 --- a/DBClasses.cs +++ b/DBClasses.cs @@ -20,27 +20,29 @@ namespace CryptoCalc public string DBSaveDataString => $"({Regex.Replace(DBVariables, "@", "")}) values ({DBVariables})"; public int Index { get; set; } - public int Year { get; set; } - public int Month { get; set; } - public int Day { get; set; } - public int Hour { get; set; } - public int Minute { get; set; } - public int Second { get; set; } - public string DateTimeString { get; set; } + public long UnixTime { get; set; } #endregion #region Functions - public void SaveDateTime() + public void SaveUnixTimeNow() { - Year = DateTime.Now.Year; - Month = DateTime.Now.Month; - Day = DateTime.Now.Day; - Hour = DateTime.Now.Hour; - Minute = DateTime.Now.Minute; - Second = DateTime.Now.Second; - DateTimeString = DateTime.Now.ToString(); + UnixTime = (long)DateTime.UtcNow.Subtract(DateTime.UnixEpoch).TotalSeconds; + } + + public long GetUnixTime(DateTime dateTime) + { + return (long)dateTime.Subtract(DateTime.UnixEpoch).TotalSeconds; + } + + public DateTime GetUTCTimeFromUnixTime(long _unix) + { + return DateTime.UnixEpoch.AddSeconds(_unix).ToUniversalTime(); + } + public DateTime GetLocalTimeFromUnixTime(long _unix) + { + return DateTime.UnixEpoch.AddSeconds(_unix).ToLocalTime(); } #endregion @@ -70,7 +72,7 @@ namespace CryptoCalc public Transaction(string _currency, float _amount, string _type) { - SaveDateTime(); + SaveUnixTimeNow(); Currency = _currency; Amount = _amount; TransactionType = _type; @@ -83,7 +85,7 @@ namespace CryptoCalc public Transaction(string _currency, float _amount, string _type, string _feeCurrency, float _feeAmount) { - SaveDateTime(); + SaveUnixTimeNow(); Currency = _currency; Amount = _amount; TransactionType = _type; @@ -102,13 +104,7 @@ namespace CryptoCalc private void SetDBStrings() { DBVariables = - $"@{nameof(Year)}," - + $"@{nameof(Month)}," - + $"@{nameof(Day)}," - + $"@{nameof(Hour)}," - + $"@{nameof(Minute)}," - + $"@{nameof(Second)}," - + $"@{nameof(DateTimeString)}," + $"@{nameof(UnixTime)}," + $"@{nameof(Currency)}," + $"@{nameof(Amount)}," + $"@{nameof(TransactionType)}," @@ -118,7 +114,7 @@ namespace CryptoCalc + $"@{nameof(Note)}"; } - public string FullInfo => $"{ Index.ToString() } { DateTimeString } { Currency } { Amount } { TransactionType }"; + public string FullInfo => $"{ Index.ToString() } { GetLocalTimeFromUnixTime(UnixTime) } { Currency } { Amount } { TransactionType }"; #endregion } @@ -130,9 +126,7 @@ namespace CryptoCalc public override string DBVariables { get => base.DBVariables; set => base.DBVariables = value; } public override string DBTableName => "Wallets"; - public int CreationYear { get; set; } - public int CreationMonth { get; set; } - public int CreationDay { get; set; } + public long UnixTimeCreated { get; set; } public string Platform { get; set; } public string Name { get; set; } public string Currency { get; set; } @@ -148,10 +142,8 @@ namespace CryptoCalc public Wallet(int _year, int _month, int _day, string _platform, string _name, string _currency, float _balance, int _default, string _note) { - SaveDateTime(); - CreationYear = _year; - CreationMonth = _month; - CreationDay = _day; + SaveUnixTimeNow(); + UnixTimeCreated = GetUnixTime(new DateTime(_year, _month, _day)); Platform = _platform; Name = _name; Currency = _currency; @@ -169,16 +161,8 @@ namespace CryptoCalc private void SetDBStrings() { DBVariables = - $"@{nameof(Year)}," - + $"@{nameof(Month)}," - + $"@{nameof(Day)}," - + $"@{nameof(Hour)}," - + $"@{nameof(Minute)}," - + $"@{nameof(Second)}," - + $"@{nameof(DateTimeString)}," - + $"@{nameof(CreationYear)}," - + $"@{nameof(CreationMonth)}," - + $"@{nameof(CreationDay)}," + $"@{nameof(UnixTime)}," + + $"@{nameof(UnixTimeCreated)}," + $"@{nameof(Platform)}," + $"@{nameof(Name)}," + $"@{nameof(Currency)}," diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 2243c8f..bf7b6b5 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -38,7 +38,7 @@ namespace CryptoCalc transactions = DBInteraction.LoadTransactions(); foreach (Transaction x in transactions) { - Debug.WriteLine($"{x.DateTimeString} *** {x.Currency} - {x.Amount}"); + Debug.WriteLine($"{x.GetLocalTimeFromUnixTime(x.UnixTime)} *** {x.Currency} - {x.Amount}"); } } private void searchButton_Click(object sender, RoutedEventArgs e) @@ -54,7 +54,7 @@ namespace CryptoCalc private Transaction DummyTransaction() { Transaction t = new(); - t.SaveDateTime(); + t.SaveUnixTimeNow(); t.Currency = "SOL"; t.Amount = Convert.ToSingle(30 * rand.NextDouble()); t.TransactionType = "BUY"; @@ -66,12 +66,10 @@ namespace CryptoCalc private Wallet DummyWallet() { Wallet w = new(); - w.SaveDateTime(); - w.CreationYear = 2017; - w.CreationMonth = 08; - w.CreationDay = 20; + w.SaveUnixTimeNow(); + w.UnixTimeCreated = w.GetUnixTime(new DateTime(2018,10,1)); w.Platform = "Ledger"; - w.Name = "TestWalled"; + w.Name = "TestWallet"; w.Currency = "SOL"; w.Balance = Convert.ToSingle(30 * rand.NextDouble()); w.DefaultWallet = 0; diff --git a/data.db b/data.db deleted file mode 100644 index df345eb..0000000 Binary files a/data.db and /dev/null differ diff --git a/transactions.db b/transactions.db index 5b55604..a3b99f3 100644 Binary files a/transactions.db and b/transactions.db differ diff --git a/wallets.db b/wallets.db index b50993f..979886f 100644 Binary files a/wallets.db and b/wallets.db differ