This repository was archived by the owner on Jan 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUtils.cs
More file actions
62 lines (52 loc) · 1.61 KB
/
Copy pathUtils.cs
File metadata and controls
62 lines (52 loc) · 1.61 KB
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
using StardewModdingAPI.Utilities;
using System;
using System.Collections.Generic;
using System.Text;
namespace PurrplingCore
{
static class Utils
{
private static bool TryParseRelativeDate(string strDate, out SDate date)
{
switch (strDate)
{
case "today":
date = SDate.Now();
break;
case "yesterday":
date = SDate.Now().AddDays(-1);
break;
case "tomorrow":
date = SDate.Now().AddDays(1);
break;
default:
date = null;
break;
}
return date != null;
}
public static SDate ParseDate(string strDate)
{
string[] s = strDate.Split(' ');
if (TryParseRelativeDate(strDate, out SDate date))
return date;
if (s.Length == 2)
return new SDate(Convert.ToInt32(s[0]), s[1]);
if (s.Length != 3 || !s[2].StartsWith("Y"))
throw new ParseDateException("Input date string has wrong format!");
return new SDate(
Convert.ToInt32(s[0]),
s[1],
Convert.ToInt32(s[2].Substring(1))
);
}
public static string CutText(string text, int maxChars)
{
if (text.Length < maxChars)
return text;
if (maxChars < 3)
return "...";
return text.Substring(0, maxChars - 3) + "...";
}
}
}