< Summary

Class:DateSeparatorEntry
Assembly:ChatHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ChatWidgetHUD/DateSeparatorEntry.cs
Covered lines:11
Uncovered lines:14
Coverable lines:25
Total lines:73
Line coverage:44% (11 of 25)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Populate(...)0%110100%
SetFadeout(...)0%6200%
FadeOut()0%12300%
GetDateFormat(...)0%440100%
GetDateTimeFromUnixTimestampMilliseconds(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ChatWidgetHUD/DateSeparatorEntry.cs

#LineLine coverage
 1using System;
 2using System.Globalization;
 3using TMPro;
 4using UnityEngine;
 5
 6/// <summary>
 7/// Special type of entry to be used as date separator in chat conversations.
 8/// </summary>
 9public class DateSeparatorEntry : ChatEntry
 10{
 11    [SerializeField] internal TextMeshProUGUI title;
 12
 13    private DateTime timestamp;
 14    private ChatEntryModel chatEntryModel;
 15
 016    public override ChatEntryModel Model => chatEntryModel;
 17
 18    public override void Populate(ChatEntryModel model)
 19    {
 220        chatEntryModel = model;
 221        title.text = GetDateFormat(GetDateTimeFromUnixTimestampMilliseconds(model.timestamp));
 222    }
 23
 24    public override void SetFadeout(bool enabled)
 25    {
 026        if (!enabled)
 27        {
 028            group.alpha = 1;
 029            fadeEnabled = false;
 030            return;
 31        }
 32
 033        fadeEnabled = true;
 034    }
 35
 36    public override void FadeOut()
 37    {
 038        if (!gameObject.activeInHierarchy)
 39        {
 040            group.alpha = 0;
 041            return;
 42        }
 43
 044        if (previewInterpolationAlphaRoutine != null)
 045            StopCoroutine(previewInterpolationAlphaRoutine);
 46
 047        previewInterpolationAlphaRoutine = StartCoroutine(InterpolateAlpha(0, 0.5f));
 048    }
 49
 50    private string GetDateFormat(DateTime date)
 51    {
 252        string result = string.Empty;
 53
 254        if (date.Year == DateTime.Now.Year &&
 55            date.Month == DateTime.Now.Month &&
 56            date.Day == DateTime.Now.Day)
 57        {
 158            result = "Today";
 159        }
 60        else
 61        {
 162            result = date.ToString("D", DateTimeFormatInfo.InvariantInfo);
 63        }
 64
 265        return result;
 66    }
 67
 68    private DateTime GetDateTimeFromUnixTimestampMilliseconds(ulong milliseconds)
 69    {
 270        DateTime result = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
 271        return result.AddMilliseconds(milliseconds);
 72    }
 73}