Neighbourhood.omg.lol/Models/Pic.cs
Gordon Pedersen 0c3836b0c8 Simplify and standardise a lot of the loading
I was overcomplicating everything trying to reduce the render lag.
Just simplify it a bit. It works.
2024-06-13 14:46:24 +10:00

40 lines
1.4 KiB
C#

using Markdig;
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace Neighbourhood.omg.lol.Models {
public class Pic {
public string Id { get; set; }
public string Url { get; set; }
public string Address { get; set; }
public long Created { get; set; }
public long Size { get; set; }
public string Mime { get; set; }
public string Description { get; set; }
public string DescriptionHtml { get => Description == null ? string.Empty : Markdown.ToHtml(Description); }
[JsonPropertyName("exif")]
public JsonElement ExifJson { get; set; }
public string RelativeTime {
get {
DateTimeOffset createdTime = DateTimeOffset.UnixEpoch.AddSeconds(Created);
TimeSpan offset = DateTimeOffset.UtcNow - createdTime;
var offsetString = string.Empty;
if (offset.TotalDays >= 1) offsetString = $"{Math.Floor(offset.TotalDays)} days ago";
else if (offset.TotalHours >= 1) offsetString = $"{Math.Floor(offset.TotalHours)} hours, {offset.Minutes} minutes ago";
else if (offset.TotalMinutes >= 1) offsetString = $"{Math.Floor(offset.TotalMinutes)} minutes ago";
else offsetString = $"{Math.Floor(offset.TotalSeconds)} seconds ago";
return offsetString;
}
}
}
}