aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/IO/SharpCifs/Util/Sharpen/SimpleDateFormat.cs
blob: 35334b4f2a919f5193447c87c0b9e3201d3795ba (plain)
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 System;
using System.Globalization;

namespace SharpCifs.Util.Sharpen
{
    public class SimpleDateFormat : DateFormat
	{
		string _format;

		CultureInfo Culture {
			get; set;
		}

		bool Lenient {
			get; set;
		}
		
		public SimpleDateFormat (): this ("g")
		{
		}

		public SimpleDateFormat (string format): this (format, CultureInfo.CurrentCulture)
		{
		}

		public SimpleDateFormat (string format, CultureInfo c)
		{
			Culture = c;
			this._format = format.Replace ("EEE", "ddd");
			this._format = this._format.Replace ("Z", "zzz");
			SetTimeZone (TimeZoneInfo.Local);
		}

		public bool IsLenient ()
		{
			return Lenient;
		}

		public void SetLenient (bool lenient)
		{
			Lenient = lenient;
		}

		public override DateTime Parse (string value)
		{
		    if (IsLenient ())
				return DateTime.Parse (value);
		    return DateTime.ParseExact (value, _format, Culture);
		}

	    public override string Format (DateTime date)
		{
			date += GetTimeZone().BaseUtcOffset;
			return date.ToString (_format);
		}
		
		public string Format (long date)
		{
			return Extensions.MillisToDateTimeOffset (date, (int)GetTimeZone ().BaseUtcOffset.TotalMinutes).DateTime.ToString (_format);
		}
	}
}