RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Issue with TimeClock, Can someone Help? :)

Ravenal

Knight
So do i just look up DateTime???

Cuz it told me this, which i am like HUH!?

PHP:
class DateTimeTester {

    static bool RoughlyEquals(DateTime time, DateTime timeWithWindow, int windowInSeconds, int frequencyInSeconds)
    {

            long delta = (long)((TimeSpan)(timeWithWindow - time)).TotalSeconds % frequencyInSeconds;

            delta = delta > windowInSeconds ? frequencyInSeconds - delta : delta;

            return Math.Abs(delta) < windowInSeconds;

    }

    public static void Main() 
    {
            int window = 10;
            int freq = 60 * 60 * 2; // 2 hours;

            DateTime d1 = DateTime.Now;

            DateTime d2 = d1.AddSeconds(2 * window);
            DateTime d3 = d1.AddSeconds(-2 * window);
            DateTime d4 = d1.AddSeconds(window / 2);
            DateTime d5 = d1.AddSeconds(-window / 2);

            DateTime d6 = (d1.AddHours(2)).AddSeconds(2 * window);
            DateTime d7 = (d1.AddHours(2)).AddSeconds(-2 * window);
            DateTime d8 = (d1.AddHours(2)).AddSeconds(window / 2);
            DateTime d9 = (d1.AddHours(2)).AddSeconds(-window / 2);

            Console.WriteLine("d1 ~= d1 [true]: " + RoughlyEquals(d1, d1, window, freq));
            Console.WriteLine("d1 ~= d2 [false]: " + RoughlyEquals(d1, d2, window, freq));
            Console.WriteLine("d1 ~= d3 [false]: " + RoughlyEquals(d1, d3, window, freq));
            Console.WriteLine("d1 ~= d4 [true]: " + RoughlyEquals(d1, d4, window, freq));
            Console.WriteLine("d1 ~= d5 [true]: " + RoughlyEquals(d1, d5, window, freq));

            Console.WriteLine("d1 ~= d6 [false]: " + RoughlyEquals(d1, d6, window, freq));
            Console.WriteLine("d1 ~= d7 [false]: " + RoughlyEquals(d1, d7, window, freq));
            Console.WriteLine("d1 ~= d8 [true]: " + RoughlyEquals(d1, d8, window, freq));
            Console.WriteLine("d1 ~= d9 [true]: " + RoughlyEquals(d1, d9, window, freq));


    }
}
 

Ravenal

Knight
ok i found this now. is this what i should be looking at??? to make?

PHP:
using System;
using System.Globalization;


public class SamplesCalendar  {

   public static void Main()  {

      // Sets a DateTime to April 3, 2002 of the Gregorian calendar.
      DateTime myDT = new DateTime( 2002, 4, 3, new GregorianCalendar() );

      // Uses the default calendar of the InvariantCulture.
      Calendar myCal = CultureInfo.InvariantCulture.Calendar;

      // Displays the values of the DateTime.
      Console.WriteLine( "April 3, 2002 of the Gregorian calendar:" );
      DisplayValues( myCal, myDT );

      // Adds 5 to every component of the DateTime.
      myDT = myCal.AddYears( myDT, 5 );
      myDT = myCal.AddMonths( myDT, 5 );
      myDT = myCal.AddWeeks( myDT, 5 );
      myDT = myCal.AddDays( myDT, 5 );
      myDT = myCal.AddHours( myDT, 5 );
      myDT = myCal.AddMinutes( myDT, 5 );
      myDT = myCal.AddSeconds( myDT, 5 );
      myDT = myCal.AddMilliseconds( myDT, 5 );

      // Displays the values of the DateTime.
      Console.WriteLine( "After adding 5 to each component of the DateTime:" );
      DisplayValues( myCal, myDT );

   }

   public static void DisplayValues( Calendar myCal, DateTime myDT )  {
      Console.WriteLine( "   Era:          {0}", myCal.GetEra( myDT ) );
      Console.WriteLine( "   Year:         {0}", myCal.GetYear( myDT ) );
      Console.WriteLine( "   Month:        {0}", myCal.GetMonth( myDT ) );
      Console.WriteLine( "   DayOfYear:    {0}", myCal.GetDayOfYear( myDT ) );
      Console.WriteLine( "   DayOfMonth:   {0}", myCal.GetDayOfMonth( myDT ) );
      Console.WriteLine( "   DayOfWeek:    {0}", myCal.GetDayOfWeek( myDT ) );
      Console.WriteLine( "   Hour:         {0}", myCal.GetHour( myDT ) );
      Console.WriteLine( "   Minute:       {0}", myCal.GetMinute( myDT ) );
      Console.WriteLine( "   Second:       {0}", myCal.GetSecond( myDT ) );
      Console.WriteLine( "   Milliseconds: {0}", myCal.GetMilliseconds( myDT ) );
      Console.WriteLine();
   }

}


/*
This code produces the following output.

April 3, 2002 of the Gregorian calendar:
   Era:          1
   Year:         2002
   Month:        4
   DayOfYear:    93
   DayOfMonth:   3
   DayOfWeek:    Wednesday
   Hour:         0
   Minute:       0
   Second:       0
   Milliseconds: 0

After adding 5 to each component of the DateTime:
   Era:          1
   Year:         2007
   Month:        10
   DayOfYear:    286
   DayOfMonth:   13
   DayOfWeek:    Saturday
   Hour:         5
   Minute:       5
   Second:       5
   Milliseconds: 5

*/
 

Ravenal

Knight
So if i want

Code:
private static DateTime WorldStart = new DateTime( 1997, 9, 1 );

to be this

Code:
private static DateTime WorldStart = new DateTime( 22878, 1, 1 );

I gotta fix this???

PHP:
public static void GetTime( Map map, int x, int y, out int hours, out int minutes, out int totalMinutes )
		{
			TimeSpan timeSpan = DateTime.Now - WorldStart;

			totalMinutes = (int)(timeSpan.TotalSeconds / SecondsPerALMinute);

			if ( map != null )
				totalMinutes += map.MapIndex * 320;

			totalMinutes += x / 16;

			hours = (totalMinutes / 60) % 24;
			minutes = totalMinutes % 60;
		}
 
What you need to do is change the variable type in your code from TimeSpan to something that can hold more than 24 hours in it.

Why do you use TimeSpan instead of DateTime?
 

Ravenal

Knight
so should i not use DateTime.Now, and just get rid of it and just use WorldTime???

so like this?

PHP:
public const double SecondsPerALMinute = 4;
public const double MinutesPerALDay = SecondsPerALMinute * 24;

private static DateTime WorldStart = new DateTime( 22585, 1, 1 );
PHP:
public static void GetTime( Map map, int x, int y, out int hours, out int minutes, out int totalMinutes )
		{
			TimeSpan timeSpan = WorldStart;

			totalMinutes = (int)(timeSpan.TotalSeconds / SecondsPerALMinute);

			if ( map != null )
				totalMinutes += map.MapIndex * 320;

			totalMinutes += x / 16;

			hours = (totalMinutes / 60) % 24;
			minutes = totalMinutes % 60;
		}
 

Ravenal

Knight
so do this?

PHP:
public static void GetTime( Map map, int x, int y, out int hours, out int minutes, out int totalMinutes )
		{
			DateTime.Now - WorldStart;

			totalMinutes = (int)(SecondsPerALMinute);

			if ( map != null )
				totalMinutes += map.MapIndex * 320;

			totalMinutes += x / 16;

			hours = (totalMinutes / 60) % 24;
			minutes = totalMinutes % 60;
		}
 

Ravenal

Knight
I change it and it gives me this error :p

Code:
 - Error: Scripts\Items\Skill Items\Tinkering\Clocks.cs: CS0029: (line 74, colum
n 24) Cannot implicitly convert type 'System.TimeSpan' to 'System.DateTime'
 
Gather 'round kids, it's time for an important lesson!

Don't always take other people's word for it, especially when you've seen the be wrong at other stuff.

I did some double-checking, and it turns out that TimeSpan is NOT limited to a 24-hour period. It also has a convenient little member called days.

Okay, change it back into a TimeSpan, figure out how many ALdays have passed since midnight, then figure out how many ALdays are contained in the days field.
 

Ravenal

Knight
Okay this is the exact List of our Awakenlands Days, Year, Months and Hours, Seconds, and Minutes of our time and our world time....

PHP:
1 Min of ALMinute = 4 Seconds Real Time
60 Mins of ALMinutes = 240 Seconds Real Time
24 Hours of ALMinutes  = 5760 Seconds Real Time
42 Days of ALMinutes = 241920 Seconds Real Time
11 Months of ALMinutes = 2661120 Seconds Real Time
1 Year of ALMinutes = 2661120 Seconds Real Time

1 Hour of ALHours = 4 Minutes Real Time
24 Hours of ALHours = 240 Minutes Real Time
42 Days of ALHours = 5760 Minutes Real Time
11 Months of ALHours = 241920 Minutes Real Time
1 Year of ALHours = 241920 Minutes Real Time

1 Days of ALDays = 10 Hours of Real Time
42 Days of ALDays = 137 Hours of Real Time
11 Months of ALDays = 21993 Hours of Real Time
1 Year of ALDays = 21993 Hours of Real Time

1 Month of ALMonth = 3 Days of Real Time
11 Months of ALMonths = 33 Days of Real Time
1 Year of ALMonths = 33 Days of Real Time

1 Year of ALYears = 1 Month and 3 Days of Real Time
 
Top