-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from lastbattle/staging
Staging
- Loading branch information
Showing
11 changed files
with
259 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* Copyright (C) 2020 LastBattle | ||
* https://github.com/lastbattle/Harepacker-resurrected | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Data; | ||
|
||
namespace HaRepacker.Converter | ||
{ | ||
/// <summary> | ||
/// Converts a ulong integer to a string seperated by commas | ||
/// </summary> | ||
public class IntegerULongCommasConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | ||
{ | ||
ulong value_ = (ulong)value; | ||
|
||
return value_.ToString("N0"); | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | ||
{ | ||
return 0; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* Copyright (C) 2020 LastBattle | ||
* https://github.com/lastbattle/Harepacker-resurrected | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Data; | ||
|
||
namespace HaRepacker.Converter | ||
{ | ||
/// <summary> | ||
/// Convert ticks to human readable relative time | ||
/// </summary> | ||
public class TicksToRelativeTimeConverter : IValueConverter | ||
{ | ||
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | ||
{ | ||
long ticks = (long)value; | ||
|
||
const int SECOND = 1; | ||
const int MINUTE = 60 * SECOND; | ||
const int HOUR = 60 * MINUTE; | ||
const int DAY = 24 * HOUR; | ||
const int MONTH = 30 * DAY; | ||
|
||
var ts = new TimeSpan(ticks); | ||
double delta = Math.Abs(ts.TotalSeconds); | ||
|
||
if (delta < 1 * MINUTE) | ||
return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago"; | ||
|
||
if (delta < 2 * MINUTE) | ||
return "a minute ago"; | ||
|
||
if (delta < 45 * MINUTE) | ||
return ts.Minutes + " minutes ago"; | ||
|
||
if (delta < 90 * MINUTE) | ||
return "an hour ago"; | ||
|
||
if (delta < 24 * HOUR) | ||
return ts.Hours + " hours ago"; | ||
|
||
if (delta < 48 * HOUR) | ||
return "yesterday"; | ||
|
||
if (delta < 30 * DAY) | ||
return ts.Days + " days ago"; | ||
|
||
if (delta < 12 * MONTH) | ||
{ | ||
int months = (int) (Math.Floor((double)ts.Days / 30)); | ||
return months <= 1 ? "one month ago" : months + " months ago"; | ||
} | ||
else | ||
{ | ||
int years = (int) (Math.Floor((double)ts.Days / 365)); | ||
return years <= 1 ? "one year ago" : years + " years ago"; | ||
} | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | ||
{ | ||
return 0; // faek value | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.