Example #1
0
 public static int getSeason(DateTime date)
 {
     int summer=date.IsDaylightSavingTime() ? 1 : 0;
     int season=date.Year * 2;
     if (date.IsDaylightSavingTime()) {
         season++;
     } else if (date.Month>6) {
         season += 2;
     }
     return season;
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return null;
            }

            Version v = value as Version;

            if (v == null)
            {
                throw new ArgumentException("Input value must be a Version object (it is a " + value.GetType().FullName + ")", "value");
            }

            if (v.Build != 0)
            {
                var time = new DateTime(2000, 1, 1).AddDays(v.Build).AddSeconds(v.Revision * 2);
                if (time.IsDaylightSavingTime())
                    time = time.AddHours(1);
                return time;
            }
            else
            {
                return null;
            }
        }
Example #3
0
 public static string ToShortDateTime(DateTime date, bool twoLines)
 {
     var sb = new StringBuilder();
     sb.Append(date.ToShortDateString());
     sb.Append(twoLines ? "<br />" : " ");
     sb.Append(date.ToShortTimeString());
     sb.Append(date.IsDaylightSavingTime() ? " (pdt)" : " (pst)");
     return sb.ToString();
 }
Example #4
0
        public void UtcToUserTimeZoneShouldWork()
        {
            var utcDateTime = new DateTime(2014, 6, 1, 12, 0, 0, DateTimeKind.Utc);

            Assert.IsFalse(utcDateTime.IsDaylightSavingTime());
            var dateTime = Utils.UtcToUserTimeZone(utcDateTime, "GMT Standard Time");

            Assert.IsTrue(Utils.IsGmtDaylightSavingTime(dateTime, "GMT Standard Time"));
        }
        public DateFunctionality()
        {
            DateTime dt = new DateTime(2004, 10, 17);
             Console.WriteLine("The day of {0} is {1}", dt.Date, dt.DayOfWeek);
             dt = dt.AddMonths(2);
             Console.WriteLine("Daylight savings: {0}", dt.IsDaylightSavingTime());

             TimeSpan timeSpan = new TimeSpan(4, 30, 0);
             Console.WriteLine(timeSpan);
             Console.WriteLine(timeSpan.Subtract(new TimeSpan(0,15,0)));
        }
Example #6
0
        /// <summary>
        /// Aligns a date/time with the User's preferences (if any).
        /// </summary>
        /// <param name="dateTime">The date/time to align.</param>
        /// <returns>The aligned date/time.</returns>
        public static DateTime AlignWithTimezone(DateTime dateTime)
        {
            // First, look for hard-stored user's preferences
            // If they are not available, look at the cookie

            int? tempShift = LoadTimezoneFromUserData();
            if(!tempShift.HasValue) tempShift = LoadTimezoneFromCookie();

            int shift = tempShift.HasValue ? tempShift.Value : Settings.DefaultTimezone;
            return dateTime.ToUniversalTime().AddMinutes(shift + (dateTime.IsDaylightSavingTime() ? 60 : 0));
        }
Example #7
0
        public void Print()
        {
            System.Int32 i = new System.Int32();
            i = 23;
            Console.WriteLine(i.GetHashCode());
            Console.WriteLine(i.GetType());
            Console.WriteLine(i.GetTypeCode());
            Console.WriteLine(i.ToString());
            if (i.CompareTo(20) < 0)
                Console.WriteLine("{0} < 20", i);
            else if (i.CompareTo(20) == 0)
                Console.WriteLine("i equals 20");
            else
                Console.WriteLine("i > 20");
            Console.WriteLine(System.Int32.MinValue);
            Console.WriteLine(System.Int32.MaxValue);
            Console.WriteLine(System.Double.Epsilon);
            Console.WriteLine(System.Double.PositiveInfinity);
            Console.WriteLine(System.Double.NegativeInfinity);
            Console.WriteLine(System.Boolean.FalseString);
            Console.WriteLine(System.Boolean.TrueString);

            Console.WriteLine(System.Char.IsDigit('1'));
            Console.WriteLine(System.Char.IsLetter('9'));
            Console.WriteLine(System.Char.IsWhiteSpace("naynish chaughule", 7));
            Console.WriteLine(System.Char.IsPunctuation('?'));

            //parsing
            double d = System.Double.Parse("90.35");
            Console.WriteLine(d);
            System.Int64 longVar = Convert.ToInt64("43654703826562");
            Console.WriteLine(longVar);

            Console.WriteLine(System.Guid.NewGuid());
            System.DateTime dt = new DateTime(2012, 6, 04);
            Console.WriteLine(dt.ToLongDateString());
            Console.WriteLine(DateTime.Now.ToLongTimeString());
            Console.WriteLine(dt.DayOfWeek);
            Console.WriteLine(dt.AddMonths(5).ToLongDateString());
            Console.WriteLine("{0} {1} {2}", dt.Date, dt.DayOfYear, dt.IsDaylightSavingTime());

            TimeSpan ts = new TimeSpan(24, 30, 30);
            Console.WriteLine(dt.Add(ts).ToLongDateString());
            Console.WriteLine(ts.Subtract(new TimeSpan(2,30, 45)));
            NumericsDemo();
            WorkingWithStrings();
        }
		public DateTime_type ()
		{
			// This constructor takes (year, month, day). 
			DateTime dt = new DateTime( 2015, 10, 17);

			// What day of the month is this? 
			Console.WriteLine(" The day of {0} is {1}", dt.Date, dt.DayOfWeek);

			// Month is now December. 
			dt = dt.AddMonths( 2); Console.WriteLine(" Daylight savings: {0}", dt.IsDaylightSavingTime());

			// This constructor takes (hours, minutes, seconds). 
			TimeSpan ts = new TimeSpan( 4, 30, 0); 
			Console.WriteLine( ts);

			// Subtract 15 minutes from the current TimeSpan and
			Console.WriteLine( ts.Subtract( new TimeSpan( 0, 15, 0)));

		}
        public void GetXsdtDateRepresentationForTest()
        {
            XsdtTypeConverter target = new XsdtTypeConverter();

            DateTime d = new DateTime(2007, 10, 17, 19, 42, 01); // TODO: Initialize to an appropriate value

            XsdtPrimitiveDataType dt = XsdtPrimitiveDataType.XsdtDateTime; // TODO: Initialize to an appropriate value

            XsdtAttribute attr = new XsdtAttribute(true, "dateTime"); // TODO: Initialize to an appropriate value

            string expected = "2007-10-17T19:42:01+" + ((d.IsDaylightSavingTime())?"11:00":"10:00");
            string actual;
            XsdtTypeConverter tc = new XsdtTypeConverter();
            actual = tc.GetXsdtDateRepresentationFor(d, dt, attr);

            Assert.AreEqual(expected, actual,
                            "LinqToRdf.XsdtTypeConverter.GetXsdtDateRepresentationFor did not return the expec" +
                            "ted value.");
        }
        /// <summary>
        /// Returns the versions build and revision components as a
        /// <see cref="DateTime"/>.
        /// </summary>
        /// <remarks>
        /// Note that this will only work correctly if the version was built
        /// with the automatic version number feature turned on (eg Maj.Min.*).
        /// </remarks>
        /// <param name="version">Version to get the DateTime for.</param>
        /// <returns>DateTime object for the build/revision.</returns>
        public static DateTime? GetBuildRevisionAsDateTime(Version version) {
            if (version == null) {
                return null;
            }
            DateTime dt = new DateTime(2000, 1, 1, 0, 0, 0);

            // If the start of the year is DLS but isn't now or vice versa then
            // we need to either add or subtract an hour.
            if (DateTime.Now.IsDaylightSavingTime() != dt.IsDaylightSavingTime()) {
                if (DateTime.Now.IsDaylightSavingTime()) {
                    dt = dt.AddHours(1);
                } else {
                    dt = dt.AddHours(-1);
                }
            }

            dt = dt.AddDays(version.Build);
            dt = dt.AddSeconds(version.Revision * 2);
            return dt;
        }
Example #11
0
        public IeTime56(long timestamp, TimeZone timeZone, bool invalid)
        {
            var datetime = new DateTime(timestamp);
            var ms = datetime.Millisecond + 1000*datetime.Second;

            value[0] = (byte) ms;
            value[1] = (byte) (ms >> 8);
            value[2] = (byte) datetime.Minute;

            if (invalid)
            {
                value[2] |= 0x80;
            }
            value[3] = (byte) datetime.Hour;
            if (datetime.IsDaylightSavingTime())
            {
                value[3] |= 0x80;
            }
            value[4] = (byte) (datetime.Day + ((((int) datetime.DayOfWeek + 5)%7 + 1) << 5));
            value[5] = (byte) (datetime.Month + 1);
            value[6] = (byte) (datetime.Year%100);
        }
Example #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("=> Dates and Times");

            // Этот конструктор принимает год, месяц и день
            DateTime dt = new DateTime(2014, 10, 20);

            // Какой это день месяца
            Console.WriteLine("The day of {0} is {1}", dt.Date, dt.DayOfWeek);

            // Сейчас месяц декабрь
            dt = dt.AddMonths(1);
            Console.WriteLine("Daylight savings: {0}", dt.IsDaylightSavingTime());

            // Этот конструктор принимает часы, минуты и секунды
            TimeSpan ts = new TimeSpan(8, 42, 30);

            Console.WriteLine(ts);

            // Вычесть 15 минут из текущего TimeSpan и вывести результат
            Console.WriteLine(ts.Subtract(new TimeSpan(0, 15, 0)));
            Console.ReadLine();
        }
Example #13
0
 /// <summary>
 /// Aligns a date/time with the default timezone.
 /// </summary>
 /// <param name="dateTime">The date/time to align.</param>
 /// <returns>The aligned date/time.</returns>
 public static DateTime AlignWithServerTimezone(DateTime dateTime)
 {
     return dateTime.ToUniversalTime().AddMinutes(Settings.DefaultTimezone + (dateTime.IsDaylightSavingTime() ? 60 : 0));
 }
Example #14
0
        public static void Today()
        {
            DateTime today = DateTime.Today;
            DateTime now = DateTime.Now;
            VerifyDateTime(today, now.Year, now.Month, now.Day, 0, 0, 0, 0, DateTimeKind.Local);

            today = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second, DateTimeKind.Utc);
            Assert.Equal(DateTimeKind.Utc, today.Kind);
            Assert.False(today.IsDaylightSavingTime());
        }
Example #15
0
        private DateTime AdjustTime_Win32ToDotNet(DateTime time)
        {
            // If I read a time from a file with GetLastWriteTime() (etc), I need
            // to adjust it for display in the .NET environment.
            if (time.Kind == DateTimeKind.Utc) return time;
            DateTime adjusted = time;
            if (DateTime.Now.IsDaylightSavingTime() && !time.IsDaylightSavingTime())
                adjusted = time + new System.TimeSpan(1, 0, 0);

            else if (!DateTime.Now.IsDaylightSavingTime() && time.IsDaylightSavingTime())
                adjusted = time - new System.TimeSpan(1, 0, 0);

            return adjusted;
        }
Example #16
0
        static void UseDatesAndTimes()
        {
            DateTime dt = new DateTime(2011, 10, 17);
            Console.WriteLine("The day of {0} is {1}", dt.Date, dt.DayOfWeek);

            dt = dt.AddMonths(2);
            Console.WriteLine("Daylight Savings {0}", dt.IsDaylightSavingTime());

            TimeSpan ts = new TimeSpan(4, 30, 0);
            Console.WriteLine(ts);

            Console.WriteLine(ts.Subtract(new TimeSpan(0, 15, 0)));


            Console.WriteLine();
        }
Example #17
0
		private static DateTime ConvertDateTimeToAdjustedTime(DateTime dt, ref bool isDuringDST)
		{
			DateTime returnTime = dt;

			try
			{
				bool bError = false;

				if (dt.IsDaylightSavingTime())
				{
					isDuringDST = true;
				}
				else
				{
					DateTime beginDST = new DateTime(dt.Year, 3, 1, 2, 0, 0);
					bool foundfirstsunday = false;
					bool foundsecondsunday = false;
					while (!foundsecondsunday && !bError)
					{
						if (beginDST.Month != 3)
						{
							bError = true;
						}
						else
						{
							if (beginDST.DayOfWeek == 0)
							{
								if (!foundfirstsunday)
								{
									foundfirstsunday = true;
									beginDST = beginDST.AddDays(1.0);
								}
								else
								{
									foundsecondsunday = true;
								}
							}
							else
							{
								beginDST = beginDST.AddDays(1.0);
							}
						}
					}
					DateTime endDST = new DateTime(dt.Year, 11, 1, 2, 0, 0);
					foundfirstsunday = false;
					while (!foundfirstsunday && !bError)
					{
						if (endDST.Month != 11)
						{
							bError = true;
						}
						else
						{
							if (endDST.DayOfWeek == 0)
							{
								foundfirstsunday = true;
							}
							else
							{
								endDST = endDST.AddDays(1.0);
							}
						}
					}

					if (!bError && beginDST <= dt && endDST > DateTime.Now)
					{
						returnTime = dt.AddHours(1.0);
						isDuringDST = true;
						//MessageBox.Show("yes: " + now.AddHours(1.0).ToLongTimeString());
					}
					else
					{
						//MessageBox.Show("no: " + now.ToLongTimeString());
					}
				}
			}
			catch (Exception e)
			{
				//LogHelper.LogException(e); (not in server)
				Console.WriteLine("EXCEPTION IN AdjustedDateTime: " + e.Message);
			}

			return returnTime;
		}
Example #18
0
 public static RubyArray ToArray(DateTime/*!*/ self) {
     RubyArray result = new RubyArray();
     result.Add(self.Second);
     result.Add(self.Minute);
     result.Add(self.Hour);
     result.Add(self.Day);
     result.Add(self.Month);
     result.Add(self.Year);
     result.Add((int)self.DayOfWeek);
     result.Add(self.DayOfYear);
     result.Add(self.IsDaylightSavingTime());
     result.Add(GetZone(self));
     return result;
 }           
Example #19
0
        public void TestSimpleFormatOfWithCustomPatternWithTimeZone()
        {
            var date = new ParseDate();
            date.Value = new MockAttribute(new Constant("04:05 +02:00"));
            date.Pattern = new MockAttribute(new Constant("HH:mm zzz"));
            date.Var = new MockAttribute(new Constant("result"));

            Assert.That(date.Evaluate(_model), Is.EqualTo(String.Empty));
            var dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 3, 5, 0);
            if (dt.IsDaylightSavingTime())
            {
                dt = dt.AddHours(1);
            }
            Assert.That(((DateTime) _model.Page["result"]), Is.EqualTo(dt));
        }
Example #20
0
 //определение критического часа дл¤ зимнего перехода (первый промежуток 2:00 - 2:59)
 public static bool IsWinterCriticalHour(DateTime time)
 {
     if ((time.IsDaylightSavingTime() != time.ToUniversalTime().Add(GetChangeDelta(time.Year)).ToLocalTime().IsDaylightSavingTime()) && (GetTimeChange(time) == TimeChangeType.WinterTime))
         return true;
     else return false;
 }
Example #21
0
        internal static DateTime TimeDateStampToDate(int timeDateStampSec)
        {
            // Convert seconds from Jan 1 1970 to DateTime ticks.  
            // The 621356004000000000L represents Jan 1 1970 as DateTime 100ns ticks.  
            DateTime ret = new DateTime((long)timeDateStampSec * 10000000 + 621356004000000000L, DateTimeKind.Utc).ToLocalTime();

            // From what I can tell TimeDateSec does not take into account daylight savings time when
            // computing the UTC time. Because of this we adjust here to get the proper local time.  
            if (ret.IsDaylightSavingTime())
                ret = ret.AddHours(-1.0);
            return ret;
        }
Example #22
0
 //TODO private
 public static string ToDatabase(DateTime value)
 {
     if (value.Kind == DateTimeKind.Utc)
         return value.ToString("yyyy-MM-dd HH:mm:ss.FFFFFF+00");
     return value.ToString("yyyy-MM-dd HH:mm:ss.FFFFFF") +
         (value.IsDaylightSavingTime() ? TimeZoneWithDaylightSaving : TimeZoneWithoutDaylightSaving);
 }
Example #23
0
 ///////////////////////////////////////////////////////////////////////
 public override bool Accept(DateTime when)
 {
     return when.IsDaylightSavingTime();
 }
        static void UseDatesAndTimes()
        {
            Console.WriteLine("=> Dates and Times:");
            // This constructor takes (year, month, day)
            DateTime dt = new DateTime(2004, 10, 17);

            // What day of the month is this?
            Console.WriteLine("The day of {0} is {1}", dt.Date, dt.DayOfWeek);
            dt = dt.AddMonths(2);  // Month is now December.
            Console.WriteLine("Daylight savings: {0}", dt.IsDaylightSavingTime());

            // This constructor takes (hours, minutes, seconds)
            TimeSpan ts = new TimeSpan(4, 30, 0);
            Console.WriteLine(ts);

            // Subtract 15 minutes from the current TimeSpan and
            // print the result.
            Console.WriteLine(ts.Subtract(new TimeSpan(0, 15, 0)));
        }
Example #25
0
 public static bool IsDST(DateTime self) {
     return self.IsDaylightSavingTime();
 }
Example #26
0
        private static void UseDatesAndTimes () {
            Console.WriteLine ("=> Dates and times:");

            var dt = new DateTime (2015, 9, 25);
            Console.WriteLine ("The day of {0} is {1}", dt.Date, dt.DayOfWeek);

            dt = dt.AddMonths (2);
            Console.WriteLine ("Daylight savings: {0}", dt.IsDaylightSavingTime ());
            Console.WriteLine ("Day of week: {0}", dt.DayOfWeek);
            Console.WriteLine ("Ticks: {0}", dt.Ticks);
            Console.WriteLine ("Kind: {0}", dt.Kind);
            Console.WriteLine ("To a Windows file time: {0}", dt.ToFileTime ());
            Console.WriteLine ("To a Windows file time UTC: {0}", dt.ToFileTimeUtc ());
            Console.WriteLine ("To string invariant culture: {0}", dt.ToString (CultureInfo.InvariantCulture));
            Console.WriteLine ("To string current culture: {0}", dt.ToString (CultureInfo.CurrentCulture));

            var ts = new TimeSpan (45, 17, 25, 45);
            Console.WriteLine ("Ts => {0}", ts);
            Console.WriteLine ("Ts subtracted 15 min => {0}", ts.Subtract (new TimeSpan (0, 15, 0)));
            Console.WriteLine ("Ts subtracted 12 days => {0}", ts.Subtract (new TimeSpan (12, 0, 0, 0)));
        }
        // If I read a time from a file with GetLastWriteTime() (etc), I need
        // to adjust it for display in the .NET environment.
        internal static DateTime AdjustTime_Forward(DateTime time)
        {
            if (time.Kind == DateTimeKind.Utc) return time;
            DateTime adjusted = time;
            if (DateTime.Now.IsDaylightSavingTime() && !time.IsDaylightSavingTime())
                adjusted = time + new System.TimeSpan(1, 0, 0);

            else if (!DateTime.Now.IsDaylightSavingTime() && time.IsDaylightSavingTime())
                adjusted = time - new System.TimeSpan(1, 0, 0);

            return adjusted;
        }
Example #28
0
 static int Main()
 {
     string[] args = Environment.GetCommandLineArgs();
     foreach (string arg in args)
         Console.WriteLine("arg: {0}", arg);
     foreach (string drive in Environment.GetLogicalDrives())
         Console.WriteLine("drive: {0}", drive);
     Console.WriteLine("OS: {0}", Environment.OSVersion);
     Console.WriteLine("number of processors: {0}", Environment.ProcessorCount);
     Console.WriteLine(".NET version: {0}", Environment.Version);
     Console.WriteLine();
     Console.WriteLine("the value 99999 in various formats:");
     Console.WriteLine("c format: {0:c}", 99999);
     Console.WriteLine("d9 format: {0:d9}", 99999);
     Console.WriteLine("f3 format: {0:f3}", 99999);
     Console.WriteLine("n format: {0:n}", 99999);
     Console.WriteLine("E format: {0:E}", 99999);
     Console.WriteLine("e format: {0:e}", 99999);
     Console.WriteLine("X format: {0:X}", 99999);
     Console.WriteLine("x format: {0:x}", 99999);
     Console.WriteLine();
     bool _0_переменная = true;
     Boolean ネ = new Boolean();
     Console.WriteLine("{0} {1}", _0_переменная, ネ);
     Console.WriteLine();
     Console.WriteLine("12.GetHashCode() = {0}", 12.GetHashCode());
     Console.WriteLine("12.Equals(21) = {0}", 12.Equals(21));
     Console.WriteLine("12.ToString() = {0}", 12.ToString());
     Console.WriteLine("12.GetType() = {0}", 12.GetType());
     Console.WriteLine();
     Console.WriteLine("double.MinValue = {0}", double.MinValue);
     Console.WriteLine("double.MaxValue = {0}", double.MaxValue);
     Console.WriteLine("double.Epsilon = {0}", double.Epsilon);
     Console.WriteLine("double.NegativeInfinity = {0}", double.NegativeInfinity);
     Console.WriteLine("double.PositiveInfinity = {0}", double.PositiveInfinity);
     Console.WriteLine(0.0 / 0.0);
     Console.WriteLine(double.IsNaN(0.0 / 0.0));
     Console.WriteLine();
     char symbol_a = 'a';
     Console.WriteLine("char.IsDigit(symbol_a): {0}", char.IsDigit(symbol_a));
     Console.WriteLine("char.IsLetter(symbol_a): {0}", char.IsLetter(symbol_a));
     Console.WriteLine("char.IsWhiteSpace(\"hello there\", 5): {0}", char.IsWhiteSpace("hello there", 5));
     Console.WriteLine("char.IsWhiteSpace(\"hello there\", 6): {0}", char.IsWhiteSpace("hello there", 6));
     Console.WriteLine("char.IsPunctuation(\"?\"): {0}", char.IsPunctuation('?'));
     Console.WriteLine();
     Console.WriteLine("bool.Parse(\"True\"): {0}", bool.Parse("True"));
     Console.WriteLine("double.Parse(\"99.884\"): {0}", double.Parse("99.884"));
     Console.WriteLine();
     DateTime date_time = new DateTime(2015, 10, 17);
     Console.WriteLine("the day of {0} is {1}", date_time.Date, date_time.DayOfWeek);
     date_time.AddMonths(2);
     Console.WriteLine("daylight savings: {0}", date_time.IsDaylightSavingTime());
     TimeSpan time_span = new TimeSpan(0, 29, 0);
     Console.WriteLine(time_span);
     Console.WriteLine(time_span.Subtract(new TimeSpan(0, 15, 0)));
     Console.WriteLine();
     BigInteger biggy = BigInteger.Parse("9999999999999999999999999999999999999999999999999");
     Console.WriteLine("is biggy an even value? {0}", biggy.IsEven);
     Console.WriteLine("is biggy a power of 2? {0}", biggy.IsPowerOfTwo);
     BigInteger really_big = biggy * BigInteger.Parse("88888888888888888888888888888888888888888888");
     Console.WriteLine("value of really_big is {0}", really_big);
     Console.WriteLine();
     Console.WriteLine("programming the " + "psychodrill");
     Console.WriteLine(@"this is a vary
         very
             very
                 long string"); // дословная строка
     Console.WriteLine(@"everybody loves ""Hello, World""");
     Console.WriteLine();
     string s_1 = "hello";
     Console.WriteLine(@"s_1 == ""hello"": {0}", s_1 == "hello");
     s_1 = "world";
     Console.WriteLine();
     StringBuilder sb = new StringBuilder("good games", 40);
     sb.Append("\n");
     sb.AppendLine("morrowind");
     sb.AppendLine("gothic");
     sb.AppendLine("N" + "+");
     Console.WriteLine(sb.ToString());
     sb.Replace("+", " game");
     Console.WriteLine(sb.ToString());
     Console.WriteLine("sb contains {0} chars", sb.Length);
     Console.WriteLine();
     short numb1 = 30000, numb2 = 30000;
     short answer = unchecked((short) Add(numb1, numb2)); // явное приведение типа
     Console.WriteLine("{0} + {1} = {2}", numb1, numb2, answer);
     Console.WriteLine();
     byte b1 = 100, b2 = 250;
     unchecked // обход проверки переполнения
     {
         byte sum = (byte) Add(b1, b2);
         Console.WriteLine("sum = {0}", sum);
     }
     Console.WriteLine();
     var v_1 = 0;
     var v_2 = true;
     var v_3 = "v_3";
     Console.WriteLine("v_1 is a {0}", v_1.GetType().Name);
     Console.WriteLine("v_2 is a {0}", v_2.GetType().Name);
     Console.WriteLine("v_2 is a {0}", v_3.GetType().Name);
     Console.WriteLine();
     int[][] array_1 = new int[3][]; // зубчатый массив
     for(int i = 0; i < array_1.Length; i++)
     {
         array_1[i] = new int[1 + 2 * i];
         for (int j = 0; j < array_1[i].Length; j++)
             array_1[i][j] = i * 3 + j;
     }
     for (int i = 0; i < array_1.Length; i++)
     {
         for (int j = 0; j < array_1[i].Length; j++)
             Console.Write(" {0} ", array_1[i][j]);
         Console.Write('\n');
     }
     Console.WriteLine();
     int[][] array_2 = new int [][]
     {
         new int[] {0, 1, 2},
         new int[] {3, 4},
         new int[] {5, 6, 7, 8}
     };
     for (int i = 0; i < array_1.Length; i++)
     {
         for (int j = 0; j < array_2[i].Length; j++)
             Console.Write(" {0} ", array_2[i][j]);
         Console.Write('\n');
     }
     Console.ReadLine();
     return -1;
 }
Example #29
0
        public static string[] OSGetDateTimeFormats(DateTime dt, char format, DateTimeFormatInfo dtfi)
        {
#if TEMP
            string[] results = null;
            string[] formats = null;
            ResetDatesAndTimes();

            PropertyInfo cultureName = typeof(DateTimeFormatInfo).GetProperty("CultureName", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
            string cultureStr = (string)cultureName.GetValue(dtfi, null);
            uint culture = (uint)LCIDFromCultureName(cultureStr);

            if (Utilities.IsWindows)
            {
                switch (format)
                {
                    case 'd':
                        EnumDateFormats(new DateTimeFormatDelegate(GetDateFormats), culture, (uint)(DateFormatFlags.DATE_SHORTDATE));
                        results = new string[Dates.Count];
                        for (int i = 0; i < Dates.Count; i++) { results[i] = dt.ToString(Dates[i], dtfi); }
                        break;
                    case 'D':
                        EnumDateFormats(new DateTimeFormatDelegate(GetDateFormats), culture, (uint)(DateFormatFlags.DATE_LONGDATE));
                        results = new string[Dates.Count];
                        for (int i = 0; i < Dates.Count; i++) { results[i] = dt.ToString(Dates[i], dtfi); }
                        break;
                    case 'f':
                    case 'F':
                        EnumDateFormats(new DateTimeFormatDelegate(GetDateFormats), culture, (uint)(DateFormatFlags.DATE_LONGDATE));
                        EnumTimeFormats(new DateTimeFormatDelegate(GetTimeFormats), culture, (uint)(TimeFormatFlags.TIME_LONGTIME));
                        formats = ComposeDatesAndTimes();
                        results = new string[formats.Length];
                        for (int i = 0; i < formats.Length; i++) { results[i] = dt.ToString(formats[i], dtfi); }
                        break;
                    case 'g':
                    case 'G':
                        EnumDateFormats(new DateTimeFormatDelegate(GetDateFormats), culture, (uint)(DateFormatFlags.DATE_SHORTDATE));
                        EnumTimeFormats(new DateTimeFormatDelegate(GetTimeFormats), culture, (uint)(TimeFormatFlags.TIME_LONGTIME));
                        formats = ComposeDatesAndTimes();
                        results = new string[formats.Length];
                        for (int i = 0; i < formats.Length; i++) { results[i] = dt.ToString(formats[i], dtfi); }
                        break;
                    case 't':
                    case 'T':
                        EnumTimeFormats(new DateTimeFormatDelegate(GetTimeFormats), culture, (uint)(TimeFormatFlags.TIME_LONGTIME));
                        results = new string[Times.Count];
                        for (int i = 0; i < Times.Count; i++) { results[i] = dt.ToString(Times[i], dtfi); }
                        break;
                    case 'y':
                    case 'Y':
                        EnumDateFormats(new DateTimeFormatDelegate(GetDateFormats), culture, (uint)(DateFormatFlags.DATE_YEARMONTH));
                        results = new string[Dates.Count];
                        for (int i = 0; i < Dates.Count; i++) { results[i] = dt.ToString(Dates[i], dtfi); }
                        break;
                    case 'U':
                        DateTime universalTime = dt.ToUniversalTime();
                        return OSGetDateTimeFormats(universalTime, 'F', dtfi);
                    case 'm':
                    case 'M':
                    case 'r':
                    case 'R':
                    case 'o':
                    case 'O':
                    case 's':
                    case 'u':
                        results = new String[] { OSDateToString(dt, format.ToString(), dtfi) };
                        break;
                }
            }
            else
            {
                // Work around a Mac OS bug that only is present in local time without custom format strings (so not O and s)
                if (format != 's' && char.ToUpper(format, CultureInfo.InvariantCulture) != 'O' && dt.IsDaylightSavingTime()) dt = dt - new TimeSpan(1, 0, 0);
                switch (format)
                {
                    case 'd':
                        results = new string[1];
                        results[0] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterShortStyle, CFDateFormatterStyle.kCFDateFormatterNoStyle);
                        break;
                    case 'D':
                        results = new string[3];
                        results[0] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterFullStyle, CFDateFormatterStyle.kCFDateFormatterNoStyle);
                        results[1] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterLongStyle, CFDateFormatterStyle.kCFDateFormatterNoStyle);
                        results[2] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterMediumStyle, CFDateFormatterStyle.kCFDateFormatterNoStyle);
                        break;
                    case 'f':
                    case 'F':
                        results = new string[12];
                        results[0] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterFullStyle, CFDateFormatterStyle.kCFDateFormatterFullStyle);
                        results[1] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterFullStyle, CFDateFormatterStyle.kCFDateFormatterLongStyle);
                        results[2] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterFullStyle, CFDateFormatterStyle.kCFDateFormatterMediumStyle);
                        results[3] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterFullStyle, CFDateFormatterStyle.kCFDateFormatterShortStyle);
                        results[4] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterLongStyle, CFDateFormatterStyle.kCFDateFormatterFullStyle);
                        results[5] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterLongStyle, CFDateFormatterStyle.kCFDateFormatterLongStyle);
                        results[6] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterLongStyle, CFDateFormatterStyle.kCFDateFormatterMediumStyle);
                        results[7] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterLongStyle, CFDateFormatterStyle.kCFDateFormatterShortStyle);
                        results[8] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterMediumStyle, CFDateFormatterStyle.kCFDateFormatterFullStyle);
                        results[9] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterMediumStyle, CFDateFormatterStyle.kCFDateFormatterLongStyle);
                        results[10] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterMediumStyle, CFDateFormatterStyle.kCFDateFormatterMediumStyle);
                        results[11] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterMediumStyle, CFDateFormatterStyle.kCFDateFormatterShortStyle);
                        break;
                    case 'g':
                    case 'G':
                        results = new string[4];
                        results[0] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterShortStyle, CFDateFormatterStyle.kCFDateFormatterFullStyle);
                        results[1] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterShortStyle, CFDateFormatterStyle.kCFDateFormatterLongStyle);
                        results[2] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterShortStyle, CFDateFormatterStyle.kCFDateFormatterMediumStyle);
                        results[3] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterShortStyle, CFDateFormatterStyle.kCFDateFormatterShortStyle);
                        break;
                    case 't':
                    case 'T':
                        results = new string[4];
                        results[0] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterNoStyle, CFDateFormatterStyle.kCFDateFormatterFullStyle);
                        results[1] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterNoStyle, CFDateFormatterStyle.kCFDateFormatterLongStyle);
                        results[2] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterNoStyle, CFDateFormatterStyle.kCFDateFormatterMediumStyle);
                        results[3] = GetMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterNoStyle, CFDateFormatterStyle.kCFDateFormatterShortStyle);
                        break;
                    case 'U':
                        results = new string[12];
                        results[0] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterFullStyle, CFDateFormatterStyle.kCFDateFormatterFullStyle);
                        results[1] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterFullStyle, CFDateFormatterStyle.kCFDateFormatterLongStyle);
                        results[2] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterFullStyle, CFDateFormatterStyle.kCFDateFormatterMediumStyle);
                        results[3] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterFullStyle, CFDateFormatterStyle.kCFDateFormatterShortStyle);
                        results[4] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterLongStyle, CFDateFormatterStyle.kCFDateFormatterFullStyle);
                        results[5] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterLongStyle, CFDateFormatterStyle.kCFDateFormatterLongStyle);
                        results[6] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterLongStyle, CFDateFormatterStyle.kCFDateFormatterMediumStyle);
                        results[7] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterLongStyle, CFDateFormatterStyle.kCFDateFormatterShortStyle);
                        results[8] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterMediumStyle, CFDateFormatterStyle.kCFDateFormatterFullStyle);
                        results[9] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterMediumStyle, CFDateFormatterStyle.kCFDateFormatterLongStyle);
                        results[10] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterMediumStyle, CFDateFormatterStyle.kCFDateFormatterMediumStyle);
                        results[11] = GetUnivMacDateTimeString(dt, cultureStr, CFDateFormatterStyle.kCFDateFormatterMediumStyle, CFDateFormatterStyle.kCFDateFormatterShortStyle);
                        break;
                    case 'y':
                    case 'Y':
                    case 'm':
                    case 'M':
                    case 'r':
                    case 'R':
                    case 'o':
                    case 'O':
                    case 's':
                    case 'u':
                        results = new String[] { OSDateToString(dt, format.ToString(), dtfi) };
                        break;
                }
            }

            return results;
#else
            throw new NotImplementedException();
#endif
        }
Example #30
0
		public void Format_Date1()
		{
			DateTime d = new DateTime (2006, 6, 19, 14, 22, 35, 78);

			Assert.AreEqual("6/19/2006 2:22:35 PM",Strings.Format(d, "General Date"));	
			Assert.AreEqual("6/19/2006 2:22:35 PM",Strings.Format(d, "G"));	

			Assert.AreEqual("Monday, June 19, 2006",Strings.Format(d, "Long Date"));
			Assert.AreEqual("Monday, June 19, 2006",Strings.Format(d, "D"));	
			
			Assert.AreEqual("Monday, June 19, 2006",Strings.Format(d, "Medium Date"));

			Assert.AreEqual("6/19/2006",Strings.Format(d, "Short Date"));
			Assert.AreEqual("6/19/2006",Strings.Format(d, "d"));

			Assert.AreEqual("2:22:35 PM",Strings.Format(d, "Long Time"));	
			Assert.AreEqual("2:22:35 PM",Strings.Format(d, "T"));

			Assert.AreEqual("2:22:35 PM",Strings.Format(d, "Medium Time"));	

			Assert.AreEqual("2:22 PM",Strings.Format(d, "Short Time"));	
			Assert.AreEqual("2:22 PM",Strings.Format(d, "t"));	

			Assert.AreEqual("Monday, June 19, 2006 2:22:35 PM",Strings.Format(d, "F"));
			Assert.AreEqual("Monday, June 19, 2006 2:22 PM",Strings.Format(d, "f"));

			Assert.AreEqual("6/19/2006 2:22 PM",Strings.Format(d, "g"));

			Assert.AreEqual("June 19",Strings.Format(d, "M"));
			Assert.AreEqual("June 19",Strings.Format(d, "m"));

			Assert.AreEqual("Mon, 19 Jun 2006 14:22:35 GMT",Strings.Format(d, "R"));
			Assert.AreEqual("Mon, 19 Jun 2006 14:22:35 GMT",Strings.Format(d, "r"));

			Assert.AreEqual("2006-06-19T14:22:35",Strings.Format(d, "s"));

#if FIXME // FIXME - these scenario is timezone specific
			if (d.IsDaylightSavingTime ()) {
				Assert.AreEqual("Monday, June 19, 2006 11:22:35 AM", Strings.Format (d, "U"));	
			} else {
				Assert.AreEqual("Monday, June 19, 2006 12:22:35 PM",Strings.Format(d, "U"));
			}
#endif

			Assert.AreEqual("2006-06-19 14:22:35Z",Strings.Format(d, "u"));

			Assert.AreEqual("June, 2006",Strings.Format(d, "Y"));
			Assert.AreEqual("June, 2006",Strings.Format(d, "y"));
				

			Assert.IsTrue(Strings.Format(DateTime.Now, "D") == Strings.Format(DateTime.Now, "Long Date"));
		}