Refactor date/time format constants
This commit is contained in:
		@@ -38,7 +38,7 @@ namespace PluralKit.Bot
 | 
			
		||||
                TimeZone = system.UiTz,
 | 
			
		||||
                Members = members,
 | 
			
		||||
                Switches = switches,
 | 
			
		||||
                Created = system.Created.ToString(Formats.TimestampExportFormat, null),
 | 
			
		||||
                Created = Formats.TimestampExportFormat.Format(system.Created),
 | 
			
		||||
                LinkedAccounts = (await _systems.GetLinkedAccountIds(system)).ToList()
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
@@ -48,20 +48,20 @@ namespace PluralKit.Bot
 | 
			
		||||
            Id = member.Hid,
 | 
			
		||||
            Name = member.Name,
 | 
			
		||||
            Description = member.Description,
 | 
			
		||||
            Birthday = member.Birthday?.ToString(Formats.DateExportFormat, null),
 | 
			
		||||
            Birthday = member.Birthday != null ? Formats.DateExportFormat.Format(member.Birthday.Value) : null,
 | 
			
		||||
            Pronouns = member.Pronouns,
 | 
			
		||||
            Color = member.Color,
 | 
			
		||||
            AvatarUrl = member.AvatarUrl,
 | 
			
		||||
            Prefix = member.Prefix,
 | 
			
		||||
            Suffix = member.Suffix,
 | 
			
		||||
            Created = member.Created.ToString(Formats.TimestampExportFormat, null),
 | 
			
		||||
            Created = Formats.TimestampExportFormat.Format(member.Created),
 | 
			
		||||
            MessageCount = await _members.MessageCount(member)
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        private async Task<DataFileSwitch> ExportSwitch(PKSwitch sw) => new DataFileSwitch
 | 
			
		||||
        {
 | 
			
		||||
            Members = (await _switches.GetSwitchMembers(sw)).Select(m => m.Hid).ToList(),
 | 
			
		||||
            Timestamp = sw.Timestamp.ToString(Formats.TimestampExportFormat, null)
 | 
			
		||||
            Timestamp = Formats.TimestampExportFormat.Format(sw.Timestamp)
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        public async Task<ImportResult> ImportSystem(DataFileSystem data, PKSystem system)
 | 
			
		||||
@@ -120,8 +120,7 @@ namespace PluralKit.Bot
 | 
			
		||||
 | 
			
		||||
                if (dataMember.Birthday != null)
 | 
			
		||||
                {
 | 
			
		||||
                    var birthdayParse = LocalDatePattern.CreateWithInvariantCulture(Formats.DateExportFormat)
 | 
			
		||||
                        .Parse(dataMember.Birthday);
 | 
			
		||||
                    var birthdayParse = Formats.DateExportFormat.Parse(dataMember.Birthday);
 | 
			
		||||
                    member.Birthday = birthdayParse.Success ? (LocalDate?) birthdayParse.Value : null;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,8 @@ namespace PluralKit
 | 
			
		||||
        public string UiTz { get; set; }
 | 
			
		||||
 | 
			
		||||
        public int MaxMemberNameLength => Tag != null ? 32 - Tag.Length - 1 : 32;
 | 
			
		||||
 | 
			
		||||
        public DateTimeZone Zone => DateTimeZoneProviders.Tzdb.GetZoneOrNull(UiTz);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class PKMember
 | 
			
		||||
 
 | 
			
		||||
@@ -223,9 +223,11 @@ namespace PluralKit
 | 
			
		||||
 | 
			
		||||
    public static class Formats
 | 
			
		||||
    {
 | 
			
		||||
        public static string DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
 | 
			
		||||
        public static string DateExportFormat = "yyyy-MM-dd";
 | 
			
		||||
        public static string TimestampExportFormat = "g";
 | 
			
		||||
        public static string DurationFormat = "D'd' h'h' m'm' s's'";
 | 
			
		||||
        public static InstantPattern InstantDateTimeFormat = InstantPattern.CreateWithInvariantCulture("yyyy-MM-dd HH:mm:ss");
 | 
			
		||||
        public static InstantPattern TimestampExportFormat = InstantPattern.CreateWithInvariantCulture("g");
 | 
			
		||||
        public static LocalDatePattern DateExportFormat = LocalDatePattern.CreateWithInvariantCulture("yyyy-MM-dd");
 | 
			
		||||
        public static DurationPattern DurationFormat = DurationPattern.CreateWithInvariantCulture("D'd' h'h' m'm' s's'");
 | 
			
		||||
        public static LocalDateTimePattern LocalDateTimeFormat = LocalDateTimePattern.CreateWithInvariantCulture("yyyy-MM-dd HH:mm:ss");
 | 
			
		||||
        public static ZonedDateTimePattern ZonedDateTimeFormat = ZonedDateTimePattern.CreateWithInvariantCulture("yyyy-MM-dd HH:mm:ss x", DateTimeZoneProviders.Tzdb);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user