44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
|
|
namespace mbts {
|
|
public static class GlobalExtensions {
|
|
public static string fmt(this string input, params object[] vals) {
|
|
return string.Format(input, vals);
|
|
}
|
|
public static string Repeat(this string s, uint count) {
|
|
if (count == 0) return "";
|
|
if (count == 1) return s;
|
|
if (count == 2) return s + s;
|
|
StringBuilder sb = new StringBuilder();
|
|
for (int x = 0; x < count; ++x) {
|
|
sb.Append(s);
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
public static T choose<T>(this Random r, IEnumerable<T> range) {
|
|
var index = r.Next(0, range.Count());
|
|
return range.Skip(index).First();
|
|
}
|
|
|
|
[DllImport("libspark")]
|
|
private static extern void ll_to_parts(UInt64 ll_time, out int year, out int month, out int day, out int hour, out int minute, out int second, out int ms);
|
|
|
|
public static DateTime lldatetime(this ulong ll) {
|
|
int year, month, day, hour, minute, second, ms;
|
|
ll_to_parts(ll, out year, out month, out day, out hour, out minute, out second, out ms);
|
|
if (year > 0) {
|
|
return new DateTime(year, month, day, hour, minute, second, ms, DateTimeKind.Utc).ToLocalTime();
|
|
}
|
|
return DateTime.MinValue;
|
|
}
|
|
|
|
public static DateTime lldatetime(this long ll) { return ((ulong)ll).lldatetime(); }
|
|
|
|
}
|
|
}
|
|
|