ITimeSystem.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. namespace Jint.Runtime;
  2. /// <summary>
  3. /// Date related operations that can replaced with implementation that can handle also full IANA data as recommended
  4. /// by the JS spec. Jint comes with <see cref="DefaultTimeSystem"/> which is based on built-in data which might be incomplete.
  5. /// </summary>
  6. /// <remarks>
  7. /// This interface intentionally uses long instead of DateTime/DateTimeOffset as DateTime/DateTimeOffset cannot handle
  8. /// neither negative years nor the date range that JS can.
  9. /// </remarks>
  10. public interface ITimeSystem
  11. {
  12. /// <summary>
  13. /// Return the default time zone system is using. Usually <see cref="TimeZoneInfo.Local"/>, but can be altered via
  14. /// engine configuration, see <see cref="Options.TimeZone"/>.
  15. /// </summary>
  16. TimeZoneInfo DefaultTimeZone { get; }
  17. /// <summary>
  18. /// Tries to parse given time presentation string as JS date presentation based on epoch.
  19. /// </summary>
  20. /// <param name="date">Date/time to parse.</param>
  21. /// <param name="epochMilliseconds">The milliseconds since the UNIX epoch, can be negative for values before 1970.</param>
  22. /// <returns>true, if succeeded.</returns>
  23. bool TryParse(string date, out long epochMilliseconds);
  24. /// <summary>
  25. /// Retrieves UTC offset for given date presented as milliseconds since the Unix epoch.
  26. /// Defaults to using <see cref="TimeZoneInfo.GetUtcOffset(System.DateTimeOffset)"/> using the configured time zone.
  27. /// </summary>
  28. /// <param name="epochMilliseconds">Date as milliseconds since the Unix epoch, may be negative (for instants before the epoch).</param>
  29. /// <seealso cref="TimeZone"/>
  30. public TimeSpan GetUtcOffset(long epochMilliseconds);
  31. }