sourcegit/src/Models/User.cs

27 lines
836 B
C#
Raw Normal View History

2021-04-29 05:05:55 -07:00
using System;
2020-07-03 00:24:31 -07:00
using System.Text.RegularExpressions;
2021-04-29 05:05:55 -07:00
namespace SourceGit.Models {
2020-07-03 00:24:31 -07:00
/// <summary>
2021-04-29 05:05:55 -07:00
/// Git用户
2020-07-03 00:24:31 -07:00
/// </summary>
public class User {
2021-04-29 05:05:55 -07:00
private static readonly Regex REG_FORMAT = new Regex(@"\w+ (.*) <(.*)> (\d{10}) [\+\-]\d+");
2020-07-03 00:24:31 -07:00
public string Name { get; set; } = "";
public string Email { get; set; } = "";
public string Time { get; set; } = "";
public void Parse(string data) {
2021-04-29 05:05:55 -07:00
var match = REG_FORMAT.Match(data);
2020-07-03 00:24:31 -07:00
if (!match.Success) return;
var time = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(int.Parse(match.Groups[3].Value));
Name = match.Groups[1].Value;
Email = match.Groups[2].Value;
Time = time.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
}
}
}