public void DateTimeTest(DateTime[] value)
        {
            // VB6 has a 1 ms resolution
            if (value != null)
                value = value.Select(dt => dt.RoundToMillisecond()).ToArray();

            Utils.CheckSerializeDeserialize(value);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var dates = new DateTime[3]{new DateTime(2016,12,1), new DateTime(2017, 4, 13), new DateTime(2019,8,21)};
            var values = new double[3] { 1, 4, 6 };

            // A) interpolate using Datetime.Ticks()
            // b) using DateTime.ToOADate (removes millisconds) -- @@

            var valD = dates.Select(t => t.ToOADate());

            var interpol = Interpolate.Linear(valD, values);

            Console.WriteLine(interpol.Interpolate(new DateTime(2017, 3, 31).ToOADate()));
            Console.ReadLine();

                    

        }
예제 #3
0
		/// <summary>
		/// Drops all entries related to operations listed in the table.
		/// </summary>
		/// <param name="toDelete">The fileset entries to delete</param>
		/// <param name="transaction">The transaction to execute the commands in</param>
		/// <returns>A list of filesets to delete</returns>
		public IEnumerable<KeyValuePair<string, long>> DropFilesetsFromTable(DateTime[] toDelete, System.Data.IDbTransaction transaction)
		{
			using(var cmd = m_connection.CreateCommand())
			{
				cmd.Transaction = transaction;

				var q = "";
				foreach(var n in toDelete)
					if (q.Length == 0)
						q = "?";
					else
						q += ",?";
						
				//First we remove unwanted entries
				cmd.ExecuteNonQuery(@"DELETE FROM ""FilesetEntry"" WHERE ""FilesetID"" IN (SELECT ""ID"" FROM ""Fileset"" WHERE ""Timestamp"" IN (" + q + @")) ", toDelete.Select(x => NormalizeDateTimeToEpochSeconds(x)).Cast<object>().ToArray());
				var deleted = cmd.ExecuteNonQuery(@"DELETE FROM ""Fileset"" WHERE ""ID"" NOT IN (SELECT DISTINCT ""FilesetID"" FROM ""FilesetEntry"") ");
	
				if (deleted != toDelete.Length)
					throw new Exception(string.Format("Unexpected number of deleted filesets {0} vs {1}", deleted, toDelete.Length));
	
				//Then we delete anything that is no longer being referenced
				cmd.ExecuteNonQuery(@"DELETE FROM ""File"" WHERE ""ID"" NOT IN (SELECT DISTINCT ""FileID"" FROM ""FilesetEntry"") ");
				cmd.ExecuteNonQuery(@"DELETE FROM ""Metadataset"" WHERE ""ID"" NOT IN (SELECT DISTINCT ""MetadataID"" FROM ""File"") ");
				cmd.ExecuteNonQuery(@"DELETE FROM ""Blockset"" WHERE ""ID"" NOT IN (SELECT DISTINCT ""BlocksetID"" FROM ""File"" UNION SELECT DISTINCT ""BlocksetID"" FROM ""Metadataset"") ");
				cmd.ExecuteNonQuery(@"DELETE FROM ""BlocksetEntry"" WHERE ""BlocksetID"" NOT IN (SELECT DISTINCT ""ID"" FROM ""Blockset"") ");
				cmd.ExecuteNonQuery(@"DELETE FROM ""BlocklistHash"" WHERE ""BlocksetID"" NOT IN (SELECT DISTINCT ""ID"" FROM ""Blockset"") ");
				
				//We save the block info for the remote files, before we delete it
				cmd.ExecuteNonQuery(@"INSERT INTO ""DeletedBlock"" (""Hash"", ""Size"", ""VolumeID"") SELECT ""Hash"", ""Size"", ""VolumeID"" FROM ""Block"" WHERE ""ID"" NOT IN (SELECT DISTINCT ""BlockID"" AS ""BlockID"" FROM ""BlocksetEntry"" UNION SELECT DISTINCT ""ID"" FROM ""Block"", ""BlocklistHash"" WHERE ""Block"".""Hash"" = ""BlocklistHash"".""Hash"") ");
				cmd.ExecuteNonQuery(@"DELETE FROM ""Block"" WHERE ""ID"" NOT IN (SELECT DISTINCT ""BlockID"" FROM ""BlocksetEntry"" UNION SELECT DISTINCT ""ID"" FROM ""Block"", ""BlocklistHash"" WHERE ""Block"".""Hash"" = ""BlocklistHash"".""Hash"") ");		
	
				//Find all remote filesets that are no longer required, and mark them as delete
				var updated = cmd.ExecuteNonQuery(@"UPDATE ""RemoteVolume"" SET ""State"" = ? WHERE ""Type"" = ? AND ""State"" IN (?, ?) AND ""ID"" NOT IN (SELECT ""VolumeID"" FROM ""Fileset"") ", RemoteVolumeState.Deleting.ToString(), RemoteVolumeType.Files.ToString(), RemoteVolumeState.Uploaded.ToString(), RemoteVolumeState.Verified.ToString());
	
				if (deleted != updated)
					throw new Exception(string.Format("Unexpected number of remote volumes marked as deleted. Found {0} filesets, but {1} volumes", deleted, updated));
	
				using (var rd = cmd.ExecuteReader(@"SELECT ""Name"", ""Size"" FROM ""RemoteVolume"" WHERE ""Type"" = ? AND ""State"" = ? ", RemoteVolumeType.Files.ToString(), RemoteVolumeState.Deleting.ToString()))
				while (rd.Read())
					yield return new KeyValuePair<string, long>(rd.GetValue(0).ToString(), Convert.ToInt64(rd.GetValue(1)));
			}
		}
 private DateTime[] EventFilterBuilder(DateTime[] eventDates, RetrieveEventDataDelegate retrieveDataForEvents)
 {
     // post filter events
     // with the above event dates from preselection, we filter out the ones match in post filter condition
     var eventBuilder = Singleton<EventFilterBuilder>.Instance;
     eventBuilder.eventDates = eventDates.Select(e => e.Date).ToArray();   // we only need the date without time when using it for filter event.
     var filteredEventDates = eventBuilder.GenerateFilteredDates(GiveMeEventSelectorVM().BuildEventsPostFilterGroup(retrieveDataForEvents));
     return filteredEventDates;
 }
        private Tuple<MonthCodeYear, int> SetFirstDayMonthCodeAndRollDates(DateTime[] rollDates, DateTime firstDate)
        {
            var closestRollDate = rollDates.Select(d => new{date=d, diff=(d - firstDate).TotalDays})
                                            .OrderBy(s => s.diff)
                                            .Where(result => result.diff > 0)
                                            .Select(a => a.date).FirstOrDefault();

            var closestRollDateIndex = Array.IndexOf(rollDates, closestRollDate);

            // the below logic may need to be reviewed. How do we compute exactly what the current contract is without market information
            // different market has different rolldates. the below way has the assumption that works for US and German market

            // if the date is in the same month as upcoming roll date, we wait unti the roll date so we use the last contract
            // eg. if roll date is 8 Mar, and we are on 1 Mar, we still use Mar contract and use Jun contract after 8 Mar.            
            var contractMonthCode = FutureBondLookup.GetQuarterlyContractMonth(firstDate);
            if (firstDate < closestRollDate && firstDate.Month == closestRollDate.Month)
            {
                // use the prev contract
                contractMonthCode = contractMonthCode.GetMonthOffset(-3);
            }

            return new Tuple<MonthCodeYear, int>(contractMonthCode, closestRollDateIndex);
        }
예제 #6
0
        private ChartLayerAppearance AddScatterSeries(DateTime[] dates_, double[] values_, string desc_, Color color_,
            int yAxisExtent_, string yLabelFormat_, object nanREplaceValue_ = null,
            NullHandling nullHandling_ = NullHandling.Zero, string[] pointLabels_ = null,
            SymbolIcon icon = SymbolIcon.Circle)
        {
            if (lineChartDataDisplay1.DataTableKeys.Contains(desc_))
                desc_ = desc_ + "(2)";

            if(ViewModel.HasTechnicals)
                return lineChartDataDisplay1.AddScatterSeries(dates_.Select(d => d.ToString("dd MMM yy")).ToArray(), values_, desc_, color_, yAxisExtent_, yLabelFormat_, nanREplaceValue_, nullHandling_, icon: icon);
            else
                return lineChartDataDisplay1.AddScatterSeries(dates_, values_, desc_, color_, yAxisExtent_, yLabelFormat_, nanREplaceValue_, nullHandling_, icon: icon);

        }
예제 #7
0
파일: MinTest.cs 프로젝트: ELN/UniLinq
        public void TestTSourceWithSelector()
        {
            // NonNullable -> Nullable
            IEnumerable<DateTime> dateTimes = new DateTime[]{
                new DateTime (2014, 3, 21),
                new DateTime (2014, 6, 21),
                new DateTime (2014, 9, 23),
                new DateTime (2014, 12, 22),
            };
            Assert.That (dateTimes.Min (it => it.ToString ()), Is.EqualTo ("03/21/2014 00:00:00"));

            // NonNullable -> NonNullable
            IEnumerable<long> dateTimeTics = dateTimes.Select (it => it.Ticks);
            Assert.That (dateTimeTics.Min (it => new DateTime (it)), Is.EqualTo (new DateTime(2014, 3, 21)));

            IEnumerable<string> strings = new string[] {
                "Cube",
                "Sphere",
                "Capsule",
                "Cylinder",
                "Plane",
                "Quad"
            };
            // Nullable -> NonNullable
            Assert.That (strings.Min (it => it.Length), Is.EqualTo (4));
            // Nullable -> Nullable
            Assert.That (strings.Min (it => it.ToUpper ()), Is.EqualTo ("CAPSULE"));
        }
예제 #8
0
 public OctavePlot( DateTime[] dataX, double[] dataY)
     : this(dataX.Select(t => (double)t.Ticks).ToArray(), dataY)
 {
     someOtherCommands = "datalabels={"+
         String.Join(",",GenerateDateXTicks(8,dataX).Select(s => "'"+s+"'"))+
         "};set(gca(),'xticklabel',datalabels);";
 }
예제 #9
0
파일: MapTests.cs 프로젝트: joeriks/FnX
 public void ReturnWhateverSelect()
 {
     var x = new DateTime(2012, 1, 1);
     var y = x.Select(self => new { self.Day });
     Assert.AreEqual(1, y.Day);
 }
예제 #10
0
파일: QuyetDinh.cs 프로젝트: Fucmeo/ou-qlns
 public bool Add_ThanhLapDV(string[] m_TenDV_Ten, string[] m_TenDVTat_Ten,
                                         int[] m_IDDVCha, string[] m_GhiChu, DateTime[] m_NgayHieuLuc)
 {
     IDataParameter[] paras = new IDataParameter[13]{
         new NpgsqlParameter("p_ma_qd",ma_qd + "_" + ngay_hieu_luc.Value.ToString("ddMMyyyy")),
         new NpgsqlParameter("p_ten_qd",ten_qd),
         new NpgsqlParameter("path",path),
         new NpgsqlParameter("path_mo_ta",pathmota),
         new NpgsqlParameter("p_ngay_ky",ngay_ky),
         new NpgsqlParameter("p_ngay_hieu_luc",ngay_hieu_luc),
         new NpgsqlParameter("p_ngay_het_han",ngay_het_han),
         new NpgsqlParameter("p_mo_ta",mota),
         new NpgsqlParameter("p_ten_don_vi_moi",m_TenDV_Ten),
         new NpgsqlParameter("p_ten_dv_moi_viet_tat",m_TenDVTat_Ten),
         new NpgsqlParameter("p_truc_thuoc_don_vi",m_IDDVCha),
         new NpgsqlParameter("p_tu_ngay",m_NgayHieuLuc.Select( a => a.ToString("d", CultureInfo.CreateSpecificCulture("vi-VN"))).ToArray()),  // format : mm/dd/yyyy),
         new NpgsqlParameter("p_ghi_chu",m_GhiChu)
     };
     try
     {
         dp.executeScalarProc("sp1_insert_thanh_lap_dv", paras);
         return true;
     }
     catch (Exception)
     {
         throw;
     }
 }