ITimeZoneService.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Ryujinx.Core.OsHle.Ipc;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace Ryujinx.Core.OsHle.Services.Time
  5. {
  6. class ITimeZoneService : IpcService
  7. {
  8. private Dictionary<int, ServiceProcessRequest> m_Commands;
  9. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  10. private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  11. public ITimeZoneService()
  12. {
  13. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  14. {
  15. { 101, ToCalendarTimeWithMyRule }
  16. };
  17. }
  18. public long ToCalendarTimeWithMyRule(ServiceCtx Context)
  19. {
  20. long PosixTime = Context.RequestData.ReadInt64();
  21. DateTime CurrentTime = Epoch.AddSeconds(PosixTime).ToLocalTime();
  22. Context.ResponseData.Write((ushort)CurrentTime.Year);
  23. Context.ResponseData.Write((byte)CurrentTime.Month);
  24. Context.ResponseData.Write((byte)CurrentTime.Day);
  25. Context.ResponseData.Write((byte)CurrentTime.Hour);
  26. Context.ResponseData.Write((byte)CurrentTime.Minute);
  27. Context.ResponseData.Write((byte)CurrentTime.Second);
  28. Context.ResponseData.Write((byte)0);
  29. /* Thanks to TuxSH
  30. struct CalendarAdditionalInfo {
  31. u32 tm_wday; //day of week [0,6] (Sunday = 0)
  32. s32 tm_yday; //day of year [0,365]
  33. struct timezone {
  34. char[8] tz_name;
  35. bool isDaylightSavingTime;
  36. s32 utcOffsetSeconds;
  37. };
  38. };
  39. */
  40. Context.ResponseData.Write((int)CurrentTime.DayOfWeek);
  41. Context.ResponseData.Write(CurrentTime.DayOfYear);
  42. //TODO: Find out the names used.
  43. Context.ResponseData.Write(new byte[8]);
  44. Context.ResponseData.Write((byte)(CurrentTime.IsDaylightSavingTime() ? 1 : 0));
  45. Context.ResponseData.Write((int)TimeZoneInfo.Local.GetUtcOffset(CurrentTime).TotalSeconds);
  46. return 0;
  47. }
  48. }
  49. }