コード例 #1
0
ファイル: DateTime.cs プロジェクト: fjgandrade/sharpkit
 static JsImplDateTime()
 {
     MinValue = new JsDate(0).As<JsImplDateTime>();
     MinValue.setUTCFullYear(1, 0, 1);
     MaxValue = new JsDate(0).As<JsImplDateTime>();
     MaxValue.setUTCFullYear(9999, 11, 31);
 }
コード例 #2
0
   public void Filters()
   {
      describe("Filters",()=>
      {
         describe("Currency filter",()=>
         {
            it("should format numbers to money amounts",()=>
            {
               currencyFilter f = Angular.BuiltinFilters.currencyFilter;
               expect(f.Filter(0))       .toBe("$0.00");
               expect(f.Filter(5.75))    .toBe("$5.75");
               expect(f.Filter(1000000)) .toBe("$1,000,000.00");
               expect(f.Filter(-5.75))   .toBe("($5.75)");
               expect(f.Filter(5.753))   .toBe("$5.75");
               expect(f.Filter(5.75,"€")).toBe("€5.75");
            });
         });

         describe("Date filter",()=>
         {
            dateFilter f = Angular.BuiltinFilters.dateFilter;
            JsDate d = new JsDate(1972,4,3);

            it("should format dates to U.S. format",()=>{ expect(f.Filter(d)).toBe("May 3, 1972"); });
            it("should format short dates",()=>{ expect(f.Filter(d,"dd/MM/yy")).toBe("03/05/72"); });
            it("should format long dates",()=>{ expect(f.Filter(d,"dd/MM/yyyy")).toBe("03/05/1972"); });
         });      
      });
   }
コード例 #3
0
ファイル: DateTime.cs プロジェクト: fjgandrade/sharpkit
		JsImplDateTime(JsDate jsDate)
		{
			if (jsDate != null)
				this.date = jsDate;
			else
				this.date = MinValue.date;
		}
コード例 #4
0
		public void YMDHConstructorWorks() {
			var dt = new JsDate(2011, 7, 12, 13);
			Assert.AreEqual(dt.GetFullYear(), 2011);
			Assert.AreEqual(dt.GetMonth(), 7);
			Assert.AreEqual(dt.GetDate(), 12);
			Assert.AreEqual(dt.GetHours(), 13);
		}
コード例 #5
0
ファイル: DateTime.cs プロジェクト: fjgandrade/sharpkit
		public JsImplDateTime(int year, int month, int day)
		{
			this.date = new JsDate();
			Year = year;
			Month = month;
			Day = day;
		}
コード例 #6
0
ファイル: QDateTests.cs プロジェクト: CodeFork/Serenity
        public void FormatDateWorks()
        {
            var backupDec = Q.Culture.DateSeparator;
            try
            {
                Q.Culture.DateSeparator = "/";

                var date = new JsDate(2009, 0, 2, 3, 4, 5, 6); // 02.01.2009 03:04:05.006

                Assert.AreEqual(Q.FormatDate(date, "dd/MM/yyyy"), "02/01/2009", "'/': dd/MM/yyy");
                Assert.AreEqual(Q.FormatDate(date, "d/M/yy"), "2/1/09", "'/': d/M/yy");
                Assert.AreEqual(Q.FormatDate(date, "d.M.yyyy"), "2.1.2009", "'/': d.M.yyy");
                Assert.AreEqual(Q.FormatDate(date, "yyyyMMdd"), "20090102", "'/': yyyyMMdd");
                Assert.AreEqual(Q.FormatDate(date, "hh:mm tt"), "03:04 AM", "'/': hh:mm tt");
                Assert.AreEqual(Q.FormatDate(date, "yyyy-MM-ddTHH:mm:ss.fff"), "2009-01-02T03:04:05.006", "'/': yyyy-MM-ddTHH:mm:ss.fff");

                Q.Culture.DateSeparator = ".";

                Assert.AreEqual(Q.FormatDate(date, "dd/MM/yyyy"), "02.01.2009", "'.': dd/MM/yyy");
                Assert.AreEqual(Q.FormatDate(date, "d/M/yy"), "2.1.09", "'.': d/M/yy");
                Assert.AreEqual(Q.FormatDate(date, "d-M-yyyy"), "2-1-2009", "'.': d-M-yyy");
                Assert.AreEqual(Q.FormatDate(date, "yyyy-MM-ddTHH:mm:ss.fff"), "2009-01-02T03:04:05.006", "'.': yyyy-MM-ddTHH:mm:ss.fff");
            }
            finally
            {
                Q.Culture.DecimalSeparator = backupDec;
            }
        }
コード例 #7
0
		public void YMDHNSConstructorWorks() {
			var dt = new JsDate(2011, 7, 12, 13, 42, 56);
			Assert.AreEqual(dt.GetFullYear(), 2011);
			Assert.AreEqual(dt.GetMonth(), 7);
			Assert.AreEqual(dt.GetDate(), 12);
			Assert.AreEqual(dt.GetHours(), 13);
			Assert.AreEqual(dt.GetMinutes(), 42);
			Assert.AreEqual(dt.GetSeconds(), 56);
		}
コード例 #8
0
 public void ConvertingMutableDateToDateReturnsANewButEqualInstance()
 {
     var mdt = new JsDate(2011, 7, 12);
     DateTime dt = (DateTime)mdt;
     Assert.IsFalse((object)dt == (object)mdt);
     Assert.AreEqual(mdt.GetFullYear(), 2011);
     Assert.AreEqual(mdt.GetMonth(), 7);
     Assert.AreEqual(mdt.GetDate(), 12);
 }
コード例 #9
0
        public static string dateToRFC3339String(JsDate date)
        {
            if (date != null ) {
                var jsonDate = date.toJSON();
                return jsonDate.substring(0, 10);
            }

            return null;
        }
コード例 #10
0
ファイル: DateTime.cs プロジェクト: fjgandrade/sharpkit
		public JsImplDateTime(int year, int month, int day, int hour, int minute, int second)
		{
			this.date = new JsDate();
			Year = year;
			Month = month;
			Day = day;
			Hour = hour;
			Minute = minute;
			Second = second;
		}
コード例 #11
0
		public void TypePropertiesAreCorrect() {
			Assert.AreEqual(typeof(JsDate).FullName, "ss.JsDate");
			Assert.IsTrue(typeof(JsDate).IsClass);
			Assert.IsTrue(typeof(IComparable<JsDate>).IsAssignableFrom(typeof(JsDate)));
			Assert.IsTrue(typeof(IEquatable<JsDate>).IsAssignableFrom(typeof(JsDate)));
			object o = new JsDate();
			Assert.IsTrue(o is JsDate);
			Assert.IsTrue(o is IComparable<JsDate>);
			Assert.IsTrue(o is IEquatable<JsDate>);

			var interfaces = typeof(JsDate).GetInterfaces();
			Assert.AreEqual(interfaces.Length, 2);
			Assert.IsTrue(interfaces.Contains(typeof(IComparable<JsDate>)));
			Assert.IsTrue(interfaces.Contains(typeof(IEquatable<JsDate>)));
		}
コード例 #12
0
ファイル: QDateTests.cs プロジェクト: volkanceylan/Serenity
        public void FormatDateWorks()
        {
            var backupDec = Q.Culture.DateSeparator;
            var backupDateFormat = Q.Culture.DateFormat;
            var backupDateTimeFormat = Q.Culture.DateTimeFormat;
            try
            {
                Q.Culture.DateSeparator = "/";
                Q.Culture.DateFormat = "dd/MM/yyyy";
                Q.Culture.DateTimeFormat = "dd/MM/yyyy HH:mm:ss";

                var date = new JsDate(2029, 0, 2, 3, 4, 5, 6); // 02.01.2029 03:04:05.006

                Assert.AreEqual(Q.FormatDate(date, "dd/MM/yyyy"), "02/01/2029", "'/': dd/MM/yyy");
                Assert.AreEqual(Q.FormatDate(date, "d/M/yy"), "2/1/29", "'/': d/M/yy");
                Assert.AreEqual(Q.FormatDate(date, "d.M.yyyy"), "2.1.2029", "'/': d.M.yyy");
                Assert.AreEqual(Q.FormatDate(date, "yyyyMMdd"), "20290102", "'/': yyyyMMdd");
                Assert.AreEqual(Q.FormatDate(date, "hh:mm tt"), "03:04 AM", "'/': hh:mm tt");
                Assert.AreEqual(Q.FormatDate(date, "yyyy-MM-ddTHH:mm:ss.fff"), "2029-01-02T03:04:05.006", "'/': yyyy-MM-ddTHH:mm:ss.fff");
                Assert.AreEqual(Q.FormatDate(date, "d"), "02/01/2029", "'/': d");
                Assert.AreEqual(Q.FormatDate(date, "g"), "02/01/2029 03:04", "'/': g");
                Assert.AreEqual(Q.FormatDate(date, "G"), "02/01/2029 03:04:05", "'/': G");
                Assert.AreEqual(Q.FormatDate(date, "s"), "2029-01-02T03:04:05", "'/': s");
                Assert.AreEqual(Q.FormatDate(date, "u"), Q.FormatISODateTimeUTC(date), "'/': u");

                Q.Culture.DateSeparator = ".";

                Assert.AreEqual(Q.FormatDate(date, "dd/MM/yyyy"), "02.01.2029", "'.': dd/MM/yyy");
                Assert.AreEqual(Q.FormatDate(date, "d/M/yy"), "2.1.29", "'.': d/M/yy");
                Assert.AreEqual(Q.FormatDate(date, "d-M-yyyy"), "2-1-2029", "'.': d-M-yyy");
                Assert.AreEqual(Q.FormatDate(date, "yyyy-MM-ddTHH:mm:ss.fff"), "2029-01-02T03:04:05.006", "'.': yyyy-MM-ddTHH:mm:ss.fff");
                Assert.AreEqual(Q.FormatDate(date, "g"), "02.01.2029 03:04", "'.': g");
                Assert.AreEqual(Q.FormatDate(date, "G"), "02.01.2029 03:04:05", "'.': G");
                Assert.AreEqual(Q.FormatDate(date, "s"), "2029-01-02T03:04:05", "'.': s");
                Assert.AreEqual(Q.FormatDate(date, "u"), Q.FormatISODateTimeUTC(date), "'.': u");
            }
            finally
            {
                Q.Culture.DecimalSeparator = backupDec;
                Q.Culture.DateFormat = backupDateFormat;
                Q.Culture.DateTimeFormat = backupDateTimeFormat;
            }
        }
コード例 #13
0
ファイル: QMethodTests.cs プロジェクト: CodeFork/Serenity
        public void ToJSONWorks()
        {
            Assert.AreEqual(Q.ToJSON(12345), "12345", "Number");

            Assert.AreEqual(Q.ToJSON("abcd\"'e"), "\"abcd\\\"'e\"", "String");

            var date = new JsDate(2013, 12, 27, 16, 19, 35, 345);
            Assert.AreEqual(Q.ToJSON(date), "\"" + Q.Externals.FormatISODateTimeUTC(date) + "\"", "Date/Time");

            Assert.AreEqual(Q.ToJSON(12345.6780), "12345.678", "Double");

            object o = new { num = 5, str = "abc", date = date };

            string json = Q.ToJSON(o);
            Assert.IsTrue(Script.TypeOf(json) == "string", "Ensure serialized object is string");

            var deserialized = jQuery.ParseJson(json);
            o.As<dynamic>().date = Q.Externals.FormatISODateTimeUTC(date);
            Assert.AreEqual(deserialized, o, "Compare original object and deserialization");
        }
コード例 #14
0
        public static object clone(object obj)
        {
            if ( ( obj == null) || ( JsContext.@typeof( obj ) != "object" ) ) {
                return obj;
            }

            //Dates
            if ( obj is JsDate ) {
                var copy = new JsDate();
                copy.setTime( obj.As<JsDate>().getTime() );
                return copy;
            }

            //Array
            if (obj is JsArray) {
                var copy = new JsArray();
                var current = obj.As<JsArray>();

                for (var i = 0; i < current.length; i++ ) {
                    copy[ i ] = clone( current[ i ] );
                }

                return copy;
            }

            //Object
            if (obj is JsObject) {
                var copy = new JsObject();
                var current = obj.As<JsObject>();

                foreach (var key in current ) {
                    if ( current.hasOwnProperty( key )) {
                        copy[ key ] = clone( current[ key ] );
                    }
                }

                return copy;
            }

            return null;
        }
コード例 #15
0
        /// <summary>
        /// Gets the offset in minutes from UTC for a certain date.
        /// </summary>
        private static int GetDateOffset(JsDate date)
        {
            var offset = -date.getTimezoneOffset();

            return(offset);
        }
コード例 #16
0
        public void SetUtcSecondsWorks() {
			var dt = new JsDate(JsDate.Utc(2000, 0, 1));
			dt.SetUtcSeconds(23);
			Assert.AreEqual(dt.GetUtcSeconds(), 23);
        }
コード例 #17
0
        public void SetUtcMillisecondsWorks() {
			var dt = new JsDate(JsDate.Utc(2000, 0, 1));
			dt.SetUtcMilliseconds(435);
			Assert.AreEqual(dt.GetUtcMilliseconds(), 435);
        }
コード例 #18
0
        public void SetUtcHoursWorks() {
			var dt = new JsDate(JsDate.Utc(2000, 0, 1));
			dt.SetUtcHours(11);
			Assert.AreEqual(dt.GetUtcHours(), 11);
        }
コード例 #19
0
        public void SetUtcMinutesWorks() {
			var dt = new JsDate(JsDate.Utc(2000, 0, 1));
			dt.SetUtcMinutes(34);
			Assert.AreEqual(dt.GetUtcMinutes(), 34);
        }
コード例 #20
0
		public void ToLocaleTimeStringWorks() {
			var dt = new JsDate(2011, 7, 12, 13, 42);
			var s = dt.ToLocaleTimeString();
			Assert.IsTrue(s.IndexOf("2011") < 0 && s.IndexOf("42") >= 0);
		}
コード例 #21
0
		public void SetUtcDateWorks() {
			var dt = new JsDate(JsDate.Utc(2000, 0, 1));
			dt.SetUtcDate(12);
			Assert.AreEqual(dt.GetUtcDate(), 12);
        }
コード例 #22
0
        public void SetUtcFullYearWithOneParameterWorks() {
			var dt = new JsDate(JsDate.Utc(2000, 0, 1));
			dt.SetUtcFullYear(2021);
			Assert.AreEqual(dt.GetUtcFullYear(), 2021);
        }
コード例 #23
0
        public void SetUtcFullYearWithThreeParametersWorks() {
			var dt = new JsDate(JsDate.Utc(2000, 0, 1));
			dt.SetUtcFullYear(2021, 7, 13);
			Assert.AreEqual(dt.GetUtcFullYear(), 2021);
			Assert.AreEqual(dt.GetUtcMonth(), 7);
			Assert.AreEqual(dt.GetUtcDate(), 13);
        }
コード例 #24
0
        public void SetFullYearWithTwoParametersWorks() {
			var dt = new JsDate(2000, 0, 1);
			dt.SetFullYear(2021, 7);
			Assert.AreEqual(dt.GetFullYear(), 2021);
			Assert.AreEqual(dt.GetMonth(), 7);
        }
コード例 #25
0
        public void SetTimeWorks() {
			var dt = new JsDate();
			dt.SetTime(3498302349234L);
			Assert.AreEqual(dt.GetTime(), 3498302349234L);
        }
コード例 #26
0
		public void StringConstructorWorks() {
			var dt = new JsDate("Aug 12, 2012");
			Assert.AreEqual(dt.GetFullYear(), 2012);
			Assert.AreEqual(dt.GetMonth(), 7);
			Assert.AreEqual(dt.GetDate(), 12);
		}
コード例 #27
0
		public void MillisecondSinceEpochConstructorWorks() {
			var dt = new JsDate(1440L * 60 * 500 * 1000);
			Assert.AreEqual(dt.GetFullYear(), 1971);
		}
コード例 #28
0
		public void GetUtcDayWorks() {
			var dt = new JsDate(JsDate.Utc(2011, 7, 12, 13, 42, 56, 345));
			Assert.AreEqual(dt.GetUtcDay(), 5);
		}
コード例 #29
0
 public DateTime(JsDate value, DateTimeKind kind = DateTimeKind.Unspecified)
 {
     this.value = value;
     this.kind  = kind;
 }
コード例 #30
0
        public void SetUtcMonthWorks() {
			var dt = new JsDate(JsDate.Utc(2000, 0, 1));
			dt.SetUtcMonth(3);
			Assert.AreEqual(dt.GetUtcMonth(), 3);
        }
コード例 #31
0
		private void AssertDateUtc(JsDate dt, int year, int month, int day, int hours, int minutes, int seconds, int milliseconds) {
			Assert.AreEqual(dt.GetUtcFullYear(), year);
			Assert.AreEqual(dt.GetUtcMonth(), month);
			Assert.AreEqual(dt.GetUtcDate(), day);
			Assert.AreEqual(dt.GetUtcHours(), hours);
			Assert.AreEqual(dt.GetUtcMinutes(), minutes);
			Assert.AreEqual(dt.GetUtcSeconds(), seconds);
			Assert.AreEqual(dt.GetUtcMilliseconds(), milliseconds);
		}
コード例 #32
0
		public void DefaultConstructorReturnsTodaysDate() {
			var dt = new JsDate();
			Assert.IsTrue(dt.GetFullYear() > 2011);
		}