// Copyright © 2017 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System;
namespace CefSharp.Internals
{
///
/// Mapping to/from CefTime
///
public static class DateTimeUtils
{
private static DateTime FirstOfTheFirstNineteenSeventy = new DateTime(1970, 1, 1, 0, 0, 0);
///
/// Converts a cef
///
/// year
/// month
/// day
/// hour
/// minute
/// second
/// millisecond
/// DateTime
public static DateTime FromCefTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
{
try
{
return new DateTime(year, month, day, hour, minute, second, millisecond);
}
catch (Exception)
{
return DateTime.MinValue;
}
}
///
/// Returns epoch (different from 01/01/1970)
///
/// datetime
/// epoch
public static double ToCefTime(DateTime dateTime)
{
var timeSpan = dateTime - FirstOfTheFirstNineteenSeventy;
return timeSpan.TotalSeconds;
}
}
}