A universal calendar entry. This can describe a date in any supported calendar type.
示例#1
0
        public static void Execute(CommandExecutionContext *context)
        {
            SharpOS.Kernel.Foundation.Time time = new SharpOS.Kernel.Foundation.Time();
            byte *    rawbuf = stackalloc byte [50];
            PString8 *pstr   = PString8.Wrap(rawbuf, 50);

            if (context->parameters->Compare("--hw") == 0)
            {
                Clock.GetHardwareTime(time);
            }
            else
            {
                Clock.GetCurrentTime(time);
            }

            time.ToString(pstr);
            TextMode.WriteLine(pstr);
        }
示例#2
0
文件: Clock.cs 项目: sharpos/SharpOS
		/// <summary>
		/// Retrieves the current hardware time. If this is not possible,
		/// this method returns false.
		/// </summary>
		public static bool GetHardwareTime (Time time)
		{
			bool result = false;
			ulong ct = 0;

			if (time == null)
				throw new ArgumentNullException ("time");

			time.Calendar = CalendarManager.GetCalendar (Calendar);

			result = RTC.Read (out time.Year, out time.Month, out time.Day, out time.Hour,
					out time.Minute, out time.Second);
			time.DayOfWeek = time.Calendar.GetDayOfWeek (time);
			time.Calendar.AddStrings (time);

			ct = time.Ticks;

			if (HardwareIsUTC && Timezone != 0) {
				ct = SharpOS.Kernel.Foundation.Timezone.Localize (ct, Timezone);
				time.Set (ct);
			}

			return result;
		}
示例#3
0
文件: Clock.cs 项目: sharpos/SharpOS
		/// <summary>
		/// Retrieves the system boot time.
		/// </summary>
		public unsafe static void GetBootTime (Time time)
		{
			if (currentTime == null)
				throw new Exception ("Clock has not been setup yet");
			if (time == null)
				throw new ArgumentNullException ("time");

			time.Set (bootTime);
		}
示例#4
0
文件: Clock.cs 项目: sharpos/SharpOS
		public unsafe static ulong GetCurrentTimestamp ()
		{
			Time time;

			if (currentTime == null)
				throw new Exception ("Clock has not been setup yet");

			time = new Time ();
			GetCurrentTime (time);

			try {
				return time.Ticks;
			} finally {
				Runtime.Free (time);
			}
		}
示例#5
0
文件: Clock.cs 项目: sharpos/SharpOS
		public unsafe static Time GetCurrentTime ()
		{
			Time time = new Time ();
			GetCurrentTime (time);
			return time;
		}
示例#6
0
文件: Clock.cs 项目: sharpos/SharpOS
		/// <summary>
		/// Initializes the system clock. First the hardware time is read
		/// and stored as the boot time and current time. The times are
		/// stored as 64-bit unsigned integers with 100-nanosecond ticks
		/// since the epoch (January 1, 0001, 00:00:00). A handler is added
		/// to the system timer event which updates the current time and
		/// handles periodic synchronization with the hardware time. The
		/// amount added to the current time per timer fire is relevant
		/// to the frequency reportedly used by the system timer.
		/// </summary>
		public static unsafe void Setup ()
		{
			Time time = null;
			EventRegisterStatus st = EventRegisterStatus.Success;

			// Read the hardware time

			currentTime = new Time ();
			GetHardwareTime (currentTime);
			bootTime = GetCurrentTimestamp ();

			// Install the clock handler

			st = Timer.RegisterTimerEvent (Stubs.GetFunctionPointer (CLOCK_HANDLER));

			if (st != EventRegisterStatus.Success)
				Diagnostics.Error ("Failed to register clock handler");

			// Debug

			time = currentTime;

			TextMode.Write ("Current time: ");
			TextMode.Write (time.Year);
			TextMode.Write ("/");
			TextMode.Write (time.Month);
			TextMode.Write ("/");
			TextMode.Write (time.Day);
			TextMode.Write (" ");
			TextMode.Write (time.Hour);
			TextMode.Write (":");
			TextMode.Write (time.Minute);
			TextMode.Write (":");
			TextMode.Write (time.Second);
			TextMode.WriteLine ();

			internalTime = new Time ();
		}
示例#7
0
文件: Clock.cs 项目: sharpos/SharpOS
		/// <summary>
		/// Retrieves the current hardware time as a timestamp. If this is not possible,
		/// this method returns 0.
		/// </summary>
		public static unsafe ulong GetHardwareTimestamp ()
		{
			Time time = new Time ();

			try {
				return (GetHardwareTime (time) ? time.Ticks : 0);
			} finally {
				Runtime.Free (time);
			}
		}
示例#8
0
文件: Time.cs 项目: sharpos/SharpOS
		public unsafe Time Clone ()
		{
			Time newTime = new Time ();

			newTime.Year = this.Year;
			newTime.Month = this.Month;
			newTime.MonthString = this.MonthString;
			newTime.Day = this.Day;
			newTime.Hour = this.Hour;
			newTime.Minute = this.Minute;
			newTime.Second = this.Second;
			newTime.Millisecond = this.Millisecond;
			newTime.Nanosecond = this.Nanosecond;
			newTime.DayOfWeek = this.DayOfWeek;
			newTime.DayOfWeekString = this.DayOfWeekString;
			newTime.CurrentTimezone = this.CurrentTimezone;
			newTime.TimezoneString = this.TimezoneString;

			return newTime;
		}
示例#9
0
文件: Time.cs 项目: sharpos/SharpOS
		public unsafe void Set (Time other)
		{
			if (other == null)
				throw new ArgumentNullException ("other");

			this.Year = other.Year;
			this.Month = other.Month;
			this.MonthString = other.MonthString;
			this.Day = other.Day;
			this.DayOfWeekString = other.DayOfWeekString;
			this.DayOfWeek = other.DayOfWeek;
			this.Hour = other.Hour;
			this.Minute = other.Minute;
			this.Second = other.Second;
			this.Millisecond = other.Millisecond;
			this.Nanosecond = other.Nanosecond;
			this.CurrentTimezone = other.CurrentTimezone;
		}
示例#10
0
		public void AddSeconds (Time time, int seconds)
		{
			if (time == null)
				throw new ArgumentNullException ("time");

			time.Second += seconds;

			if (time.Second > 59) {
				time.Minute += time.Second / 60;
				time.Second = time.Second % 60;
			}

			if (time.Minute > 59) {
				time.Hour += time.Minute / 60;
				time.Minute = time.Minute % 60;
			}

			if (time.Hour > 23) {
				time.Day += time.Hour / 24;
				time.Hour = time.Hour % 24;
			}

			if (time.Day >= GetMonthDays ((uint)time.Month, (uint)time.Year)) {
				int days = time.Day - (int)GetMonthDays ((uint)time.Month, (uint)time.Year);

				while (days >= GetMonthDays ((uint)time.Month, (uint)time.Year)) {
					time.Month++;
					days -= (int)GetMonthDays ((uint)time.Month, (uint)time.Year);
				}
			}

			if (time.Month > 12) {
				time.Year += time.Month / 12;
				time.Month = time.Month % 12;
			}

			time.MonthString = GetMonthString ((uint)time.Month);
			time.DayOfWeek = GetDayOfWeek (time);
			time.DayOfWeekString = GetDayOfWeekString ((uint)time.DayOfWeek);
		}
示例#11
0
		public void AddStrings (Time time)
		{
			time.MonthString = GetMonthString ((uint) time.Month);
			time.DayOfWeekString = GetDayOfWeekString ((uint) time.DayOfWeek);
		}
示例#12
0
		public void DecodeTimestamp (ulong timestamp, Time out_time)
		{
			ulong remaining = timestamp;

			if (out_time == null)
				throw new ArgumentNullException ("out_time");

			// init

			out_time.Year = (int) Timestamp.EpochYear;
			out_time.Day = out_time.Month = 1;
			out_time.Hour = out_time.Minute =
				out_time.Second = out_time.Millisecond = out_time.Nanosecond =
				out_time.DayOfWeek = 0;
			out_time.CurrentTimezone = 0;

			while (remaining > 0) {
				uint yearDays = GetYearDays ((uint)out_time.Year);
				uint monthDays = GetMonthDays ((uint)out_time.Month);

				// if this is a leap year and we are in February, add a day

				if (IsLeapYear ((uint)out_time.Year) && out_time.Month == 1)
					monthDays += 1;

				// take a chunk out of `remaining'

				if (remaining > (yearDays * Timestamp.DayUnit)) {
					// add a year

					out_time.Year++;
					remaining -= (yearDays * Timestamp.DayUnit);
					continue;
				} else if (remaining > (monthDays * Timestamp.DayUnit)) {
					// add a month

					out_time.Month++;
					remaining -= (monthDays * Timestamp.DayUnit);
				} else if (remaining >= Timestamp.DayUnit) {
					out_time.Day++;
					remaining -= Timestamp.DayUnit;
				} else if (remaining >= Timestamp.HourUnit) {
					out_time.Hour++;
					remaining -= Timestamp.HourUnit;
				} else if (remaining >= Timestamp.MinuteUnit) {
					out_time.Minute++;
					remaining -= Timestamp.MinuteUnit;
				} else if (remaining >= Timestamp.SecondUnit) {
					out_time.Second++;
					remaining -= Timestamp.SecondUnit;
				} else if (remaining >= Timestamp.MillisecondUnit) {
					out_time.Millisecond++;
					remaining -= Timestamp.MillisecondUnit;
				} else {
					out_time.Nanosecond = (int) remaining;
					remaining = 0;
				}
			}

			out_time.MonthString = GetMonthString ((uint)out_time.Month);
			out_time.DayOfWeek = GetDayOfWeek (out_time);
			out_time.DayOfWeekString = GetDayOfWeekString ((uint)out_time.DayOfWeek);
		}
示例#13
0
		public int GetDayOfWeek (Time time)
		{
			int dayOfWeek;

			if (time == null)
				throw new ArgumentNullException ("time");

			dayOfWeek  = time.Year + (time.Year / 4);
			dayOfWeek -= time.Year / 100;
			dayOfWeek += time.Year / 400;
			dayOfWeek += time.Day;
			dayOfWeek += GetMonthPseudoNumber((uint)time.Month, (uint)time.Year);
			dayOfWeek  = dayOfWeek % 7;

			return dayOfWeek;
		}
示例#14
0
		// Mon Jan  7 04:01:28 EST 2008

		public ulong EncodeTimestamp (Time time)
		{
			ulong timestamp = 0;

			if (time == null)
				throw new ArgumentNullException ("time");

			// encode years

			for (uint x = 1; x < time.Year; ++x) {
				timestamp += GetYearDays (x) * Timestamp.DayUnit;
			}

			// encode months

			for (uint x = 1; x < time.Month; ++x)
				timestamp += GetMonthDays (x, (uint)time.Year) * Timestamp.DayUnit;

			// encode days

			timestamp += (ulong) time.Day * Timestamp.DayUnit;
			timestamp += (ulong) time.Hour * Timestamp.HourUnit;
			timestamp += (ulong) time.Minute * Timestamp.MinuteUnit;
			timestamp += (ulong) time.Second * Timestamp.SecondUnit;
			timestamp += (ulong) time.Millisecond * Timestamp.MillisecondUnit;
			timestamp += (ulong) time.Nanosecond;

			return timestamp;
		}