-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.cs
73 lines (64 loc) · 1.52 KB
/
Utils.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System.Globalization;
namespace ImportWLK
{
static internal class Utils
{
public static DateTime DdmmyyStrToDate(string d)
{
if (DateTime.TryParseExact(d, "dd/MM/yy", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var result))
{
return result;
}
return DateTime.MinValue;
}
public static DateTime GetDateTime(DateTime date, string time, int rolloverHr)
{
var tim = time.Split(':');
var timOnly = new TimeSpan(int.Parse(tim[0]), int.Parse(tim[1]), 0);
var dat = date.Add(timOnly);
if (rolloverHr != 0 && timOnly.Hours < rolloverHr)
{
dat.AddDays(1);
}
return dat;
}
public static bool TryDetectNewLine(string path, out string newLine)
{
using var fs = File.OpenRead(path);
char prevChar = '\0';
// read the first 1000 characters to try and find a newLine
for (var i = 0; i < 1000; i++)
{
int b;
if ((b = fs.ReadByte()) == -1)
break;
char curChar = (char) b;
if (curChar == '\n')
{
newLine = prevChar == '\r' ? "\r\n" : "\n";
return true;
}
prevChar = curChar;
}
// Returning false means could not determine linefeed convention
newLine = Environment.NewLine;
return false;
}
/// <summary>
/// Convert altitude from user units to metres
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static double AltitudeM(double altitude)
{
if (Program.Cumulus.AltitudeInFeet)
{
return altitude * 0.3048;
}
else
{
return altitude;
}
}
}
}