Ejemplo n.º 1
0
 public void testEquality()
 {
     Assert.IsTrue(HTime.make(1, 2, 3, 4).hequals(HTime.make(1, 2, 3, 4)));
     Assert.IsFalse(HTime.make(1, 2, 3, 4).hequals(HTime.make(9, 2, 3, 4)));
     Assert.IsFalse(HTime.make(1, 2, 3, 4).hequals(HTime.make(1, 9, 3, 4)));
     Assert.IsFalse(HTime.make(1, 2, 3, 4).hequals(HTime.make(1, 2, 9, 9)));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the Click event of the Pause And Remind control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void PauseAndRemindIn_Click(object sender, EventArgs e)
        {
            TimerFile.Instance.addEndItem();
            string newInterval = ((ToolStripMenuItem)sender).Text;

            Program.LaunchProjectFormIn(HTime.inMilliseconds(newInterval));
        }
Ejemplo n.º 3
0
 public void testCompare()
 {
     Assert.IsTrue(HTime.make(0, 0, 0, 0).CompareTo(HTime.make(0, 0, 0, 9)) < 0);
     Assert.IsTrue(HTime.make(0, 0, 0, 0).CompareTo(HTime.make(0, 0, 1, 0)) < 0);
     Assert.IsTrue(HTime.make(0, 1, 0, 0).CompareTo(HTime.make(0, 0, 0, 0)) > 0);
     Assert.IsTrue(HTime.make(0, 0, 0, 0).CompareTo(HTime.make(2, 0, 0, 0)) < 0);
     Assert.AreEqual(HTime.make(2, 0, 0, 0).CompareTo(HTime.make(2, 0, 0, 0)), 0);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Handles the Enter key event for the textbox of a new time interval for manual reminder
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void NewInterval_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         TimerFile.Instance.addEndItem();
         string newInterval = ((ToolStripTextBox)sender).Text;
         Program.LaunchProjectFormIn(HTime.inMilliseconds(newInterval));
         ((ContextMenuStrip)((ToolStripDropDownMenu)(((ToolStripTextBox)sender).Owner)).OwnerItem.Owner).Close();
     }
 }
Ejemplo n.º 5
0
        private void remindLater_button_Click(object sender, EventArgs e)
        {
            // TODO: a better interval parser than <int><space><unit>
            int interval = 0;
            string laterText = later_comboBox.Text.Trim();

            interval = HTime.inMilliseconds(laterText, Ini.GetString("Values", "DefaultReminderUnit", "seconds"));

            Program.LaunchProjectFormIn(interval);
            this.Close();
        }
Ejemplo n.º 6
0
 public void testZinc()
 {
     verifyZinc(HTime.make(2, 3), "02:03:00");
     verifyZinc(HTime.make(2, 3, 4), "02:03:04");
     verifyZinc(HTime.make(2, 3, 4, 5), "02:03:04.005");
     verifyZinc(HTime.make(2, 3, 4, 56), "02:03:04.056");
     verifyZinc(HTime.make(2, 3, 4, 109), "02:03:04.109");
     verifyZinc(HTime.make(2, 3, 10, 109), "02:03:10.109");
     verifyZinc(HTime.make(2, 10, 59), "02:10:59");
     verifyZinc(HTime.make(10, 59, 30), "10:59:30");
     verifyZinc(HTime.make(23, 59, 59, 999), "23:59:59.999");
     verifyZinc(HTime.make(3, 20, 0), "03:20:00");
     Assert.IsTrue(HTime.make("10:04:19.181511").hequals(HTime.make(10, 04, 19, 181)));
 }
Ejemplo n.º 7
0
        public static void LaunchReminder(string interval, string text)
        {
            int   inter         = HTime.inMilliseconds(interval);
            Timer reminderTimer = new Timer();

            reminderTimer.Interval = inter;
            reminderTimer.Start();

            reminderTimer.Tick += (sender, eventArgs) =>
            {
                reminderTimer.Stop();
                MessageBox.Show(text, "Reminder (" + interval + ")");
            };
        }
Ejemplo n.º 8
0
 // we don't require hour to be two digits and we don't require seconds
 private HaystackToken time(StringBuilder s, bool addSeconds)
 {
     // Java use to bubble Parse exception as err - this just accepts that the debug printing
     //  will be done by the user of this toolkit.
     if (s[1] == ':')
     {
         s.Insert(0, '0');
     }
     if (addSeconds)
     {
         s.Append(":00");
     }
     m_val = HTime.make(s.ToString());
     return(HaystackToken.time);
 }
Ejemplo n.º 9
0
        public void testTime()
        {
            HaystackToken time = HaystackToken.time;

            verifyToks("8:30", new object[] { time, HTime.make(8, 30) });
            verifyToks("20:15", new object[] { time, HTime.make(20, 15) });
            verifyToks("00:00", new object[] { time, HTime.make(0, 0) });
            verifyToks("00:00:00", new object[] { time, HTime.make(0, 0, 0) });
            verifyToks("01:02:03", new object[] { time, HTime.make(1, 2, 3) });
            verifyToks("23:59:59", new object[] { time, HTime.make(23, 59, 59) });
            verifyToks("12:00:12.9", new object[] { time, HTime.make(12, 00, 12, 900) });
            verifyToks("12:00:12.99", new object[] { time, HTime.make(12, 00, 12, 990) });
            verifyToks("12:00:12.999", new object[] { time, HTime.make(12, 00, 12, 999) });
            verifyToks("12:00:12.000", new object[] { time, HTime.make(12, 00, 12, 0) });
            verifyToks("12:00:12.001", new object[] { time, HTime.make(12, 00, 12, 1) });
        }
Ejemplo n.º 10
0
        public void testWriter()
        {
            HGridBuilder gb = new HGridBuilder();

            gb.addCol("a");
            gb.addCol("b");
            gb.addRow(new HVal[] { HNA.VAL, HBool.TRUE }); // Original Unit test had null - this is not valid
            gb.addRow(new HVal[] { HMarker.VAL, HNA.VAL });
            gb.addRow(new HVal[] { HRemove.VAL, HNA.VAL });
            gb.addRow(new HVal[] { HStr.make("test"), HStr.make("with:colon") });
            gb.addRow(new HVal[] { HNum.make(12), HNum.make(72.3, "\u00b0F") });
            gb.addRow(new HVal[] { HNum.make(double.NegativeInfinity), HNum.make(Double.NaN) });
            gb.addRow(new HVal[] { HDate.make(2015, 6, 9), HTime.make(1, 2, 3) });
            var tz = HTimeZone.make("UTC", true);

            gb.addRow(new HVal[] { HDateTime.make(634429600180690000L, tz), HUri.make("foo.txt") });
            gb.addRow(new HVal[] { HRef.make("abc"), HRef.make("abc", "A B C") });
            gb.addRow(new HVal[] { HBin.make("text/plain"), HCoord.make(90, -123) });
            HGrid grid = gb.toGrid();

            string actual = HJsonWriter.gridToString(grid);

            // System.out.println(actual);
            string[] lines = actual.Split('\n');
            Assert.AreEqual(lines[0], "{");
            Assert.AreEqual(lines[1], "\"meta\": {\"ver\":\"2.0\"},");
            Assert.AreEqual(lines[2], "\"cols\":[");
            Assert.AreEqual(lines[3], "{\"name\":\"a\"},");
            Assert.AreEqual(lines[4], "{\"name\":\"b\"}");
            Assert.AreEqual(lines[5], "],");
            Assert.AreEqual(lines[6], "\"rows\":[");
            Assert.AreEqual(lines[7], "{\"a\":\"z:\", \"b\":true},");
            Assert.AreEqual(lines[8], "{\"a\":\"m:\", \"b\":\"z:\"},");
            Assert.AreEqual(lines[9], "{\"a\":\"x:\", \"b\":\"z:\"},");
            Assert.AreEqual(lines[10], "{\"a\":\"test\", \"b\":\"s:with:colon\"},");
            Assert.AreEqual(lines[11], "{\"a\":\"n:12\", \"b\":\"n:72.3 \u00b0F\"},");
            Assert.AreEqual(lines[12], "{\"a\":\"n:-INF\", \"b\":\"n:NaN\"},");
            Assert.AreEqual(lines[13], "{\"a\":\"d:2015-06-09\", \"b\":\"h:01:02:03\"},");
            Assert.AreEqual(lines[14], "{\"a\":\"t:2011-06-06T12:26:58.069Z UTC\", \"b\":\"u:foo.txt\"},");
            Assert.AreEqual(lines[15], "{\"a\":\"r:abc\", \"b\":\"r:abc A B C\"},");
            Assert.AreEqual(lines[16], "{\"a\":\"b:text/plain\", \"b\":\"c:90.0,-123.0\"}");
            Assert.AreEqual(lines[17], "]");
            Assert.AreEqual(lines[18], "}");
        }
Ejemplo n.º 11
0
        public void testTicks()
        {
            HDate     date    = HDate.make(2014, 12, 24);
            HTime     time    = HTime.make(11, 12, 13, 456);
            HTimeZone newYork = HTimeZone.make("New_York", false);

            // Ignore issues with locally installed timezones.
            if (newYork == null)
            {
                return;
            }
            long utcTicks = 635550163334560000L; //635550163334560000

            HDateTime a = HDateTime.make(date, time, newYork);
            //  Not valid for us - HDateTime b = HDateTime.make(date, time, newYork, a.tzOffset);
            HDateTime c = HDateTime.make(utcTicks, newYork);
            HDateTime d = HDateTime.make("2014-12-24T11:12:13.456-05:00 New_York", false);

            Assert.AreEqual(a.Ticks, utcTicks);
            //Not Valid for us - Assert.AreEqual(b.millis(), utcTicks);
            Assert.AreEqual(c.Ticks, utcTicks);
            Assert.AreEqual(d.Ticks, utcTicks);
        }
Ejemplo n.º 12
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Debug.WriteLineIf(iniFile == null || iniFile == "", "Ini file was not well defined.");
            Ini.SetFile(iniFile);

            // Show the system tray icon.
            using (ProcessIcon pi = new ProcessIcon())
            {
                checkFiles();

                pi.Display();
                string remindIn = Ini.GetString("StartupReminder", "Interval", "5 mins");
                LaunchProjectFormIn(HTime.inMilliseconds(remindIn));

                AutoSave.Start();

                // Make sure the application runs!
                Debug.WriteLine("Start application.");
                Application.Run();
            }
        }
        public void testRange()
        {
            HTimeZone ny = HTimeZone.make("New_York", false);

            // Ignore issues with locally installed timezones.
            if (ny == null)
            {
                return;
            }
            HDate     today     = HDate.today();
            HDate     yesterday = today.minusDays(1);
            HDate     x         = HDate.make(2011, 7, 4);
            HDate     y         = HDate.make(2011, 11, 4);
            HDateTime xa        = HDateTime.make(x, HTime.make(2, 30), ny);
            HDateTime xb        = HDateTime.make(x, HTime.make(22, 5), ny);

            verifyRange(HDateTimeRange.make("today", ny), today, today);
            verifyRange(HDateTimeRange.make("yesterday", ny), yesterday, yesterday);
            verifyRange(HDateTimeRange.make("2011-07-04", ny), x, x);
            verifyRange(HDateTimeRange.make("2011-07-04,2011-11-04", ny), x, y);
            verifyRange(HDateTimeRange.make("" + xa + "," + xb, ny), xa, xb);

            HDateTimeRange r = HDateTimeRange.make(xb.ToString(), ny);

            Assert.IsTrue(r.Start.hequals(xb));
            Assert.IsTrue(r.End.date.hequals(today));
            Assert.IsTrue(r.End.TimeZone.hequals(ny));

            // this week
            HDate sun = today;
            HDate sat = today;

            while (sun.weekday() > DayOfWeek.Sunday)
            {
                sun = sun.minusDays(1);
            }
            while (sat.weekday() < DayOfWeek.Saturday)
            {
                sat = sat.plusDays(1);
            }
            verifyRange(HDateTimeRange.thisWeek(ny), sun, sat);

            // this month
            HDate first = today;
            HDate last  = today;

            while (first.Day > 1)
            {
                first = first.minusDays(1);
            }
            while (last.Day < DateTime.DaysInMonth(today.Year, today.Month))
            {
                last = last.plusDays(1);
            }
            verifyRange(HDateTimeRange.thisMonth(ny), first, last);

            // this year
            first = HDate.make(today.Year, 1, 1);
            last  = HDate.make(today.Year, 12, 31);
            verifyRange(HDateTimeRange.thisYear(ny), first, last);

            // last week
            HDate prev = today.minusDays(7);

            sun = prev;
            sat = prev;
            while (sun.weekday() > DayOfWeek.Sunday)
            {
                sun = sun.minusDays(1);
            }
            while (sat.weekday() < DayOfWeek.Saturday)
            {
                sat = sat.plusDays(1);
            }
            verifyRange(HDateTimeRange.lastWeek(ny), sun, sat);

            // last month
            last = today;
            while (last.Month == today.Month)
            {
                last = last.minusDays(1);
            }
            first = HDate.make(last.Year, last.Month, 1);
            verifyRange(HDateTimeRange.lastMonth(ny), first, last);

            // last year
            first = HDate.make(today.Year - 1, 1, 1);
            last  = HDate.make(today.Year - 1, 12, 31);
            verifyRange(HDateTimeRange.lastYear(ny), first, last);
        }
Ejemplo n.º 14
0
        public void testDateTime()
        {
            HaystackToken dt     = HaystackToken.dateTime;
            HTimeZone     ny     = HTimeZone.make("New_York", false);
            HTimeZone     utc    = HTimeZone.UTC;
            HTimeZone     london = HTimeZone.make("London", false);

            // Ignore issues with locally installed timezones.
            if (ny != null)
            {
                verifyToks("2016-01-13T09:51:33-05:00 New_York", new object[] { dt, HDateTime.make(2016, 1, 13, 9, 51, 33, ny /*, tzOffset(-5, 0)*/) });
                verifyToks("2016-01-13T09:51:33.353-05:00 New_York", new object[] { dt, HDateTime.make(HDate.make(2016, 1, 13), HTime.make(9, 51, 33, 353), ny /*, tzOffset(-5, 0)*/) });
            }
            verifyToks("2010-12-18T14:11:30.924Z", new object[] { dt, HDateTime.make(HDate.make(2010, 12, 18), HTime.make(14, 11, 30, 924), utc) });
            verifyToks("2010-12-18T14:11:30.924Z UTC", new object[] { dt, HDateTime.make(HDate.make(2010, 12, 18), HTime.make(14, 11, 30, 924), utc) });
            // Ignore issues with locally installed timezones.
            if (london != null)
            {
                verifyToks("2010-12-18T14:11:30.924Z London", new object[] { dt, HDateTime.make(HDate.make(2010, 12, 18), HTime.make(14, 11, 30, 924), london) });
            }
            // Apparently PST8PDT is not valid in java? - Not tested for windows either
            //    verifyToks("2015-01-02T06:13:38.701-08:00 PST8PDT", new Object[] {dt, HDateTime.make(HDate.make(2015,1,2), HTime.make(6,13,38,701), HTimeZone.make("PST8PDT"), tzOffset(-8,0))});
            var tz = HTimeZone.make("GMT+5", false);

            // Ignore issues with locally installed timezones.
            if (tz != null)
            {
                verifyToks("2010-03-01T23:55:00.013-05:00 GMT+5", new object[] { dt, HDateTime.make(HDate.make(2010, 3, 1), HTime.make(23, 55, 0, 13), tz /*, tzOffset(-5, 0)*/) });
            }
            tz = HTimeZone.make("GMT-10", false);
            // Ignore issues with locally installed timezones.
            if (tz != null)
            {
                verifyToks("2010-03-01T23:55:00.013+10:00 GMT-10 ", new object[] { dt, HDateTime.make(HDate.make(2010, 3, 1), HTime.make(23, 55, 0, 13), tz /*, tzOffset(10, 0)*/) });
            }
        }
Ejemplo n.º 15
0
        public static void LaunchProjectFormIn(string interval)
        {
            int inter = HTime.inMilliseconds(interval);

            LaunchProjectFormIn(inter);
        }
        public void testRange()
        {
            HTimeZone ny = HTimeZone.make("New_York", false);

            // Ignore issues with locally installed timezones.
            if (ny == null)
            {
                return;
            }
            HDate     today     = HDate.today();
            HDate     yesterday = today.minusDays(1);
            HDate     x         = HDate.make(2011, 7, 4);
            HDate     y         = HDate.make(2011, 11, 4);
            HDateTime xa        = HDateTime.make(x, HTime.make(2, 30), ny);
            HDateTime xb        = HDateTime.make(x, HTime.make(22, 5), ny);

            // this week
            HDate sun = today;
            HDate sat = today;

            while (sun.weekday() > DayOfWeek.Sunday)
            {
                sun = sun.minusDays(1);
            }
            while (sat.weekday() < DayOfWeek.Saturday)
            {
                sat = sat.plusDays(1);
            }
            verifyRange(HDateTimeRange.thisWeek(ny), sun, sat);

            // this month
            HDate first = today;
            HDate last  = today;

            while (first.Day > 1)
            {
                first = first.minusDays(1);
            }
            while (last.Day < DateTime.DaysInMonth(today.Year, today.Month))
            {
                last = last.plusDays(1);
            }
            verifyRange(HDateTimeRange.thisMonth(ny), first, last);

            // this year
            first = HDate.make(today.Year, 1, 1);
            last  = HDate.make(today.Year, 12, 31);
            verifyRange(HDateTimeRange.thisYear(ny), first, last);

            // last week
            HDate prev = today.minusDays(7);

            sun = prev;
            sat = prev;
            while (sun.weekday() > DayOfWeek.Sunday)
            {
                sun = sun.minusDays(1);
            }
            while (sat.weekday() < DayOfWeek.Saturday)
            {
                sat = sat.plusDays(1);
            }
            verifyRange(HDateTimeRange.lastWeek(ny), sun, sat);

            // last month
            last = today;
            while (last.Month == today.Month)
            {
                last = last.minusDays(1);
            }
            first = HDate.make(last.Year, last.Month, 1);
            verifyRange(HDateTimeRange.lastMonth(ny), first, last);

            // last year
            first = HDate.make(today.Year - 1, 1, 1);
            last  = HDate.make(today.Year - 1, 12, 31);
            verifyRange(HDateTimeRange.lastYear(ny), first, last);
        }
Ejemplo n.º 17
0
 public void testDateTime()
 {
     verifyParse("foo < 2009-10-30", HFilter.lt("foo", HDate.make("2009-10-30")));
     verifyParse("foo < 08:30:00", HFilter.lt("foo", HTime.make("08:30:00")));
     verifyParse("foo < 13:00:00", HFilter.lt("foo", HTime.make("13:00:00")));
 }