| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | /// <summary> |
| | 6 | | /// Special type of entry to be used as date separator in chat conversations. |
| | 7 | | /// </summary> |
| | 8 | | public class DateSeparatorEntry : MonoBehaviour |
| | 9 | | { |
| | 10 | | public struct Model |
| | 11 | | { |
| | 12 | | public DateTime date; |
| | 13 | | } |
| | 14 | |
|
| 0 | 15 | | public Model model { get; private set; } |
| | 16 | |
|
| | 17 | | [SerializeField] internal TextMeshProUGUI title; |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Configures the separator entry with the date information. |
| | 21 | | /// </summary> |
| | 22 | | /// <param name="dateSeparatorModel">DateSeparatorEntry.Model</param> |
| | 23 | | public void Populate(Model dateSeparatorModel) |
| | 24 | | { |
| 3 | 25 | | model = dateSeparatorModel; |
| 3 | 26 | | title.text = GetDateFormat(dateSeparatorModel.date); |
| 3 | 27 | | } |
| | 28 | |
|
| | 29 | | private string GetDateFormat(DateTime date) |
| | 30 | | { |
| 3 | 31 | | string result = string.Empty; |
| | 32 | |
|
| 3 | 33 | | if (date.Year == DateTime.Now.Year && |
| | 34 | | date.Month == DateTime.Now.Month && |
| | 35 | | date.Day == DateTime.Now.Day) |
| | 36 | | { |
| 0 | 37 | | result = "Today"; |
| 0 | 38 | | } |
| | 39 | | else |
| | 40 | | { |
| 3 | 41 | | result = date.ToLongDateString(); |
| | 42 | | } |
| | 43 | |
|
| 3 | 44 | | return result; |
| | 45 | | } |
| | 46 | | } |