﻿using System;

namespace Criteo.Profiling.Tracing.Utils
{
    internal static class TimeUtils
    {

        private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

        public static DateTime UtcNow
        {
            get
            {
                return HighResolutionDateTime.IsAvailable ? HighResolutionDateTime.UtcNow : DateTime.UtcNow;
            }
        }

        /// <summary>
        /// Create a UNIX timestamp from a UTC date time. Time is expressed in microseconds and not seconds.
        /// </summary>
        /// <see href="https://en.wikipedia.org/wiki/Unix_time"/>
        /// <param name="utcDateTime"></param>
        /// <returns></returns>
        public static long ToUnixTimestamp(DateTime utcDateTime)
        {
            return (long)(utcDateTime.Subtract(Epoch).TotalMilliseconds * 1000L);
        }
    }
}

﻿using System;

namespace Criteo.Profiling.Tracing.Utils
{
    public static class TimeUtils
    {

        private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

        public static DateTime UtcNow
        {
            get
            {
                return HighResolutionDateTime.IsAvailable ? HighResolutionDateTime.UtcNow : DateTime.UtcNow;
            }
        }

        /// <summary>
        /// Create a UNIX timestamp from a UTC date time. Time is expressed in microseconds and not seconds.
        /// </summary>
        /// <see href="https://en.wikipedia.org/wiki/Unix_time"/>
        /// <param name="utcDateTime"></param>
        /// <returns></returns>
        public static long ToUnixTimestamp(DateTime utcDateTime)
        {
            return (long)(utcDateTime.Subtract(Epoch).TotalMilliseconds * 1000L);
        }
    }
}

Change time utils visibility from internal to public
Change time utils visibility from internal to public

Change-Id: Ifc984cd613e3daeea243467392652c5efd9ba34b
