public virtual void testMyDateLong() { long timeMilli = 1008745211300L; // 2001-12-19T07:00:11+00:00 JDFDate date = new JDFDate(timeMilli); Assert.IsTrue(date.TimeInMillis == timeMilli, "Bug " + date.TimeInMillis + " is not equal to 1008745211000L"); string strDate = date.DateTimeISO; JDFDate date2 = new JDFDate("2001-12-19T07:00:11.300+00:00"); string strDate2 = date2.DateTimeISO; Assert.AreEqual(date, date2, "Bug " + strDate + " is not equal to " + strDate2); JDFDate date3 = new JDFDate("2001-12-19T07:00:11.300-00:00"); string strDate3 = date3.DateTimeISO; Assert.AreEqual(date, date3, "Bug " + strDate + " is not equal to " + strDate3); JDFDate date4 = new JDFDate("2001-12-19T07:00:11.300Z"); string strDate4 = date4.DateTimeISO; Assert.AreEqual(date, date4, "Bug " + strDate + " is not equal to " + strDate4); }
public virtual void testAddOffset() { JDFDate date1 = new JDFDate(); JDFDate date2 = new JDFDate(date1); Assert.AreEqual(0, date1.CompareTo(date2)); date2.addOffset(0, 0, 0, 1); // it is now later Assert.AreEqual(-1, date1.ToString().CompareTo(date2.ToString())); date1.addOffset(0, 0, 24, 0); // it is now later Assert.AreEqual(0, date1.ToString().CompareTo(date2.ToString())); Assert.AreEqual(0, date1.CompareTo(date2)); date2.addOffset(60, 0, 0, 1); // it is now later date1.addOffset(0, 1, 24, 0); // it is now later Assert.AreEqual(0, date1.CompareTo(date2)); date2.addOffset(0, 60, 0, 1); // it is now later date1.addOffset(0, 0, 25, 0); // it is now later Assert.AreEqual(0, date1.CompareTo(date2)); JDFDate date = new JDFDate("2007-09-26T11:43:10+03:00"); date.addOffset(0, 0, 0, 1); // it is now later Assert.AreEqual("2007-09-27T11:43:10+03:00", date.DateTimeISO); date.addOffset(0, 0, 0, 1); // it is now later Assert.AreEqual("2007-09-28T11:43:10+03:00", date.DateTimeISO); date.addOffset(2, 0, 0, 0); // it is now later Assert.AreEqual("2007-09-28T11:43:12+03:00", date.DateTimeISO); Assert.AreEqual("2007-09-28", date.DateISO); date.addOffset(0, 0, 0, 4); // it is now later Assert.AreEqual("2007-10-02", date.DateISO); }
public virtual void testPerformance() { testWritePerformance(); long write = JDFDate.ToMillisecs(DateTime.Now); AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "performance.mjm"); long getMP = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("get multipart time: " + (getMP - write)); Attachment bp = MimeUtil.GetPartByCID(mp, "bigger.pdf"); long getCID = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("get big time: " + (getCID - getMP)); Assert.IsNotNull(bp); Assert.AreEqual("bigger.pdf", bp.Name); FileInfo outFile = FileUtil.streamToFile(bp.ContentStream, sm_dirTestDataTemp + "performance.pdf"); Assert.IsNotNull(outFile); // // * InputStream is=bp.getInputStream(); byte[] b=new byte[1000]; int l=0; // * while (true) { int i=is.read(b); if(i<=0) break; l+=i; } // long extract = JDFDate.ToMillisecs(DateTime.Now); //System.out.println("extracted "+l+" bytes in time: "+(extract-getCID)) // ; Console.WriteLine("extracted bytes in time: " + (extract - getCID)); }
public virtual void testTimeZone() { TimeZone t = TimeZone.CurrentTimeZone; JDFDate d = new JDFDate(); Assert.AreEqual((int)t.GetUtcOffset(DateTime.Now).TotalMilliseconds, d.TimeZoneOffsetInMillis); }
public virtual void testURLPerformance() { // testWritePerformance(); try { long write = JDFDate.ToMillisecs(DateTime.Now); AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "performance.mjm"); long getMP = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("get multipart time: " + (getMP - write)); Attachment bp = MimeUtil.GetPartByCID(mp, "bigger.pdf"); long getCID = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("get big time: " + (getCID - getMP)); Assert.IsNotNull(bp); Assert.AreEqual("bigger.pdf", bp.Name); HttpWebRequest uc = MimeUtil.writeToURL(mp, "http://localhost:8080/JDFUtility/dump"); Stream @is = uc.GetRequestStream(); IOUtils.CopyStream(@is, System.Console.OpenStandardOutput()); @is.Close(); Console.WriteLine(); // System.out.println("extracted "+l+" bytes in time: "+(extract- // getCID)); long extract = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("sent bytes in time: " + (extract - getCID)); } catch (Exception) { // nop } }
public virtual void testEquals() { JDFDate date1 = new JDFDate(); JDFDate date2 = new JDFDate(date1); Assert.AreEqual(date1, date2); Assert.IsTrue(date1.Equals(date2)); }
public virtual void testdateTimeZone() { JDFDate date = new JDFDate(); string strDate = date.DateTimeISO; JDFDate date2 = new JDFDate(strDate); Assert.AreEqual(date, date2); }
/// /// <summary> * true, if this is after other, also true if other==null /// * </summary> /// * <param name="other"> /// * @return </param> /// public virtual bool after(JDFDate other) { if (other == null) { return(true); } return(this.m_DateTimeOffset > other.m_DateTimeOffset); }
/// /// * <returns> the GregorianCalendar for this date </returns> /// //public virtual GregorianCalendar getCalendar() //{ // GregorianCalendar gregorianCalendar = new GregorianCalendar(new SimpleTimeZone(m_TimeZoneOffsetInMillis, JDFConstants.EMPTYSTRING)); // gregorianCalendar.setTimeInMillis(getTimeInMillis()); // return gregorianCalendar; //} /// /// <summary> * true, if this is before other, also true if other==null /// * </summary> /// * <param name="other"> JDFDate to compare </param> /// * <returns> true if this is before other </returns> /// public virtual bool before(JDFDate other) { if (other == null) { return(true); } return(this.m_DateTimeOffset < other.m_DateTimeOffset); }
/// /// * <param name="other"> the date to clone </param> /// public JDFDate(JDFDate other) : this() { if (other != null) { m_DateTimeOffset = other.m_DateTimeOffset; } }
/// /// <summary> * creates a duration from two dates; may be negative if start later end /// * </summary> /// * <param name="start"> the starting point </param> /// * <param name="end"> the end point /// * </param> /// public JDFDuration(JDFDate start, JDFDate end) { if (start == null || end == null) { return; } m_lDuration = (end.TimeInMillis - start.TimeInMillis) / 1000.0; }
public virtual void testdateOnly() { JDFDate date = new JDFDate(); string strDate = date.DateTimeISO; date = new JDFDate("2006-11-26"); strDate = date.DateTimeISO; Assert.AreEqual("2006-11-26T00:00:00" + new JDFDate().TimeZoneISO, strDate, "Bug " + strDate); }
public virtual void testWritePerformance() { long start = JDFDate.ToMillisecs(DateTime.Now); string big = sm_dirTestData + "big.pdf"; string bigger = sm_dirTestDataTemp + "bigger.pdf"; JDFDoc docJMF = new JDFDoc("JMF"); docJMF.setOriginalFileName("JMF.jmf"); JDFJMF jmf = docJMF.getJMFRoot(); JDFCommand com = (JDFCommand)jmf.appendMessageElement(JDFMessage.EnumFamily.Command, JDFMessage.EnumType.SubmitQueueEntry); com.appendQueueSubmissionParams().setURL("TheJDF"); FileInfo fBigger = new FileInfo(bigger); SupportClass.FileSupport.CreateNewFile(fBigger); FileStream fis = new FileStream(big, FileMode.Open); FileStream fos = new FileStream(bigger, FileMode.Create); byte[] b = new byte[10000]; while (true) { int i = fis.Read(b, 0, 10000); if (i <= 0) { break; } for (int j = 0; j < 3; j++) { fos.Write(b, 0, i); } } fis.Close(); fos.Flush(); fos.Close(); JDFDoc doc = new JDFDoc("JDF"); doc.setOriginalFileName("JDF.jdf"); JDFNode n = doc.getJDFRoot(); n.setType(EnumType.Interpreting); JDFRunList rl = (JDFRunList)n.addResource(ElementName.RUNLIST, EnumUsage.Input); rl.addPDF(StringUtil.uncToUrl(bigger, false), 0, -1); long setup = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("Setup time: " + (setup - start)); AttachmentCollection m = MimeUtil.buildMimePackage(null, doc, true); long build = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("Build time: " + (build - setup)); Assert.IsNotNull(MimeUtil.writeToFile(m, sm_dirTestDataTemp + "performance.mjm", null)); long write = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("Write time: " + (write - build)); }
public virtual void testCompareString() { JDFDate date1 = new JDFDate(); JDFDate date2 = new JDFDate(); Assert.AreEqual(date1.CompareTo(date2), 0); date2.addOffset(0, 0, 0, 1); // it is now later Assert.IsTrue(date1.CompareTo(date2.DateTimeISO) < 0); Assert.IsTrue(date2.CompareTo(date1.DateTimeISO) > 0); }
public virtual void testCompare() { JDFDate date1 = new JDFDate(); JDFDate date2 = new JDFDate(); Assert.AreEqual(0, new JDFDate().Compare(date1, date2)); date2.addOffset(0, 0, 0, 1); // it is now later Assert.IsTrue(new JDFDate().Compare(date1, date2) < 0); Assert.IsTrue(new JDFDate().Compare(date2, date1) > 0); Assert.IsTrue(new JDFDate().Compare(date2, date2) == 0); }
public virtual void testPerformanceGet() { long write = JDFDate.ToMillisecs(DateTime.Now); AttachmentCollection mp = MimeUtil.GetMultiPart(sm_dirTestDataTemp + "performance.mjm"); long getMP = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("get multipart time: " + (getMP - write)); Attachment bp = MimeUtil.GetPartByCID(mp, "bigger.pdf"); long getCID = JDFDate.ToMillisecs(DateTime.Now); Console.WriteLine("get big time: " + (getCID - getMP)); Assert.IsNotNull(bp); Assert.AreEqual("bigger.pdf", bp.Name); }
public virtual void testMyDateTime() { JDFDate[] v = new JDFDate[100000]; JDFDate d = new JDFDate(); for (int i = 0; i < 100000; i++) { v[i] = d; d.addOffset(0, 0, 1, 0); d = new JDFDate(d.DateTimeISO); if (i > 0) { Assert.IsTrue(d.after(v[i - 1])); } } }
// // * (non-Javadoc) // * // * @see org.cip4.jdflib.util.HotFolderListener#hotFile(java.io.FileInfo) // public virtual void hotFile(FileInfo hotFile) { bool zapp = false; if (bZapp) { try { hotFile.Delete(); zapp = true; } catch (Exception) { } } Console.WriteLine(JDFDate.ToMillisecs(DateTime.Now) + " " + hotFile.FullName + "," + zapp); }
/// /// <summary> * Compares two JDFDates for equality.<br> /// * The result is <code>true</code> if and only if the argument is not <code>null</code> and is a /// * <code>JDFDate</code> object that represents the same point in time, to the millisecond, as this object. /// * <p> /// * Thus, two <code>JDFDate</code> objects are equal if and only if the <code>getTimeInMillis</code> method returns /// * the same <code>long</code> value for both. </summary> /// public bool Equals(JDFDate other) { if (this == other) { return(true); } if (other == null) { return(false); } if (other.GetType() != this.GetType()) { return(false); } return((this.m_DateTimeOffset.UtcTicks / TimeSpan.TicksPerSecond) == (other.m_DateTimeOffset.UtcTicks / TimeSpan.TicksPerSecond)); }
public virtual void testSort() { JDFDate[] a = new JDFDate[10]; JDFDate date1 = new JDFDate(); for (int i = 0; i < 10; i++) { JDFDate date2 = new JDFDate(date1); date2.addOffset(10 * (i % 3) + i, 0, 0, 0); a[i] = date2; } System.Array.Sort(a); for (int i = 0; i < 9; i++) { Assert.IsTrue(a[i].CompareTo(a[i + 1]) < 0); } }
public virtual void testGetFormattedDateTime() { const string dateString = "2008-12-19T07:00:11.300+00:00"; JDFDate date = new JDFDate(dateString); Assert.AreEqual("2008", date.getFormattedDateTime("yyyy")); Assert.AreEqual("12", date.getFormattedDateTime("MM")); // .NET second fractions are fff instead of SSS. Assert.AreEqual("300", date.getFormattedDateTime("fff")); // test for milliseconds // milliseconds // No .NET equivalent to S. will test f instead. //Assert.AreEqual("300", date.getFormattedDateTime("S")); // test for milliseconds // milliseconds Assert.AreEqual("3", date.getFormattedDateTime("%f")); //test for tenths of a second. // .NET timezone offsets are zzz instead of ZZ. Assert.AreEqual(dateString, date.getFormattedDateTime("yyyy'-'MM'-'dd'T'HH:mm:ss.fffzzz")); Assert.AreEqual(dateString, date.getFormattedDateTime("yyyy-MM-dd'T'HH:mm:ss.fffzzz")); Assert.AreEqual("12 19-07:00:11", date.getFormattedDateTime("MM dd-HH:mm:ss")); }
/// /// <summary> * Tests if this date is after the specified date. /// * </summary> /// * <param name="x"> the date you wish to know if it is later than this </param> /// * <returns> true if and only if the instant represented by this Date object is strictly later than the instant /// * represented by x; false otherwise. </returns> /// public virtual bool isLater(JDFDate x) { return(this.m_DateTimeOffset > x.m_DateTimeOffset); }
/// /// <summary> * Tests if this date is before the specified date. /// * </summary> /// * <param name="x"> the date you wish to know if it is eariler than this </param> /// * <returns> true if and only if the instant of time represented by this Date object is strictly earlier than the /// * instant represented by x; false otherwise. </returns> /// public virtual bool isEarlier(JDFDate x) { return(this.m_DateTimeOffset < x.m_DateTimeOffset); }
public virtual void testBadDate() { JDFDate date; try { date = new JDFDate("1999+09-26T11:43:10+03:00"); Assert.Fail("date exception: " + date); } catch (FormatException) { // } try { date = new JDFDate("1999"); Assert.Fail("date exception: " + date); } catch (FormatException) { // } try { date = new JDFDate((string)null); } catch (FormatException) { Assert.Fail("date exception: "); } try { date = new JDFDate("1975-01-01T20:00:10.5"); Assert.Fail("date exception: " + date); } catch (FormatException) { // } try { date = new JDFDate("2004-11-26T11:43:10.33-03"); Assert.Fail("date exception: " + date); } catch (FormatException) { // } try { date = new JDFDate("2004-11-26T11:43:10.-0300"); Assert.Fail("date exception: " + date); } catch (FormatException) { // } }
public virtual void testGetDateTime() { JDFDate date = new JDFDate("2008-12-19T07:00:11.300+00:00"); Assert.AreEqual("20081219070011", date.DateTime); }
// (non-Javadoc) // } // * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) // public virtual int Compare(JDFDate d0, JDFDate d1) { return(ContainerUtil.compare(d0, d1)); }
public virtual void testdateTimeISO() { JDFDate date = new JDFDate(); string strDate = date.DateTimeISO; // summer date = new JDFDate("1999-09-26T11:43:10+03:00"); strDate = date.DateTimeISO; Assert.IsTrue(strDate.Equals("1999-09-26T11:43:10+03:00"), "Bug " + strDate + " is not equal to 1999-09-26T11:43:10+03:00"); date = new JDFDate("1999-09-26T11:43:10-03:00"); strDate = date.DateTimeISO; Assert.IsTrue(strDate.Equals("1999-09-26T11:43:10-03:00"), "Bug " + strDate + " is not equal to 1999-09-26T11:43:10-03:00"); // winter date = new JDFDate("1999-11-26T11:43:10+03:00"); strDate = date.DateTimeISO; Assert.IsTrue(strDate.Equals("1999-11-26T11:43:10+03:00"), "Bug " + strDate + " is not equal to 1999-11-26T11:43:10+03:00"); date = new JDFDate("1999-11-26T11:43:10-03:00"); strDate = date.DateTimeISO; Assert.IsTrue(strDate.Equals("1999-11-26T11:43:10-03:00"), "Bug " + strDate + " is not equal to 1999-11-26T11:43:10-03:00"); // note the various A,c zulu etc times below date = new JDFDate("1999-11-26T11:43:10a"); strDate = date.DateTimeISO; Assert.AreEqual("1999-11-26T11:43:10+01:00", strDate, "Bug "); date = new JDFDate("1999-11-26T11:43:10C"); strDate = date.DateTimeISO; Assert.AreEqual("1999-11-26T11:43:10+03:00", strDate, "Bug "); date = new JDFDate("1999-11-26T11:43:10Z"); strDate = date.DateTimeISO; Assert.AreEqual("1999-11-26T11:43:10+00:00", strDate, "Bug "); date = new JDFDate("1999-11-26T11:43:10i"); strDate = date.DateTimeISO; Assert.AreEqual("1999-11-26T11:43:10+09:00", strDate, "Bug "); date = new JDFDate("1999-11-26T11:43:10K"); strDate = date.DateTimeISO; Assert.AreEqual("1999-11-26T11:43:10+10:00", strDate, "Bug "); date = new JDFDate("1999-11-26T11:43:10M"); strDate = date.DateTimeISO; Assert.AreEqual("1999-11-26T11:43:10+12:00", strDate, "Bug "); date = new JDFDate("1999-11-26T11:43:10N"); strDate = date.DateTimeISO; Assert.AreEqual("1999-11-26T11:43:10-01:00", strDate, "Bug "); date = new JDFDate("1999-11-26T11:43:10V"); strDate = date.DateTimeISO; Assert.AreEqual("1999-11-26T11:43:10-09:00", strDate, "Bug "); date = new JDFDate("1999-11-26T11:43:10W"); strDate = date.DateTimeISO; Assert.AreEqual("1999-11-26T11:43:10-10:00", strDate, "Bug "); date = new JDFDate("1999-11-26T11:43:10Y"); strDate = date.DateTimeISO; Assert.AreEqual("1999-11-26T11:43:10-12:00", strDate, "Bug "); date = new JDFDate("1999-11-26T11:43:10.123Y"); strDate = date.DateTimeISO; Assert.AreEqual("1999-11-26T11:43:10-12:00", strDate, "Bug "); date = new JDFDate("1999-11-26T11:43:10.12345-03:00"); strDate = date.DateTimeISO; Assert.IsTrue(strDate.Equals("1999-11-26T11:43:10-03:00"), "Bug " + strDate + " is not equal to 1999-11-26T11:43:10-03:00"); date = new JDFDate("2004-11-26T11:43:10.-03:00"); strDate = date.DateTimeISO; Assert.IsTrue(strDate.Equals("2004-11-26T11:43:10-03:00"), "Bug " + strDate + " is not equal to 2004-11-26T11:43:10-03:00"); // date = new JDFDate("2004-11-26T11:43:10"); // Assert.IsNotNull(date); // strDate = date.DateTimeISO; }