public override string ToString()
        {
            string result = null;

            switch (SelectedIndex)
            {
            case 1:
                string          dateFormat = string.Empty;
                string          timeFormat = string.Empty;
                Regex           r1         = new Regex(@"(y*[-\/]*M*[-\/]*[Dd]*)(M*[-\/]*[Dd]*[-\/]*y*)([Dd]*[-\/]*M*[-\/]*y*)([Hh]*[:]*m*[:]*s*[ ]*t*)");
                MatchCollection mc         = r1.Matches(DateTimeFormat);
                foreach (Match match in mc)
                {
                    if (match.Value.Trim().Length > 0 && match.Value.Contains('d'))
                    {
                        dateFormat = match.Value;
                    }
                    if (match.Value.Trim().Length > 0 && match.Value.Contains('m'))
                    {
                        timeFormat = match.Value;
                    }
                }
                System.TimeZone zone    = System.TimeZone.CurrentTimeZone;
                TimeSpan        span    = zone.GetUtcOffset(DateTime.Now);
                DateTime        dtLocal = DateTime.Now.Add(TimeZone.UtcOffset - span);
                // if GAT is behind Now, return +1
                int addDays = ExactTimeValidDays;
                if (ExactTimeValidDays == 0 && DateTime.Parse(dtLocal.ToShortTimeString()) >= DateTime.Parse(ExactTime.ToShortTimeString()))
                {
                    addDays = 1;
                }

                result  = DateTimeFormat.Replace(dateFormat, dtLocal.AddDays(addDays).ToString(dateFormat));
                result  = result.Replace(timeFormat, ExactTime.ToString(timeFormat));
                result += TimeZone != null ? " " + TimeZone.Id : "";
                //System.Diagnostics.Debug.WriteLine("GTD: " + result);

                break;

            case 2:
                //result =  OrderTime.AddSeconds(Seconds).ToString(DateTimeFormat);
                // assume using current timezone setting
                result = DateTime.Now.AddSeconds(Seconds).ToString(DateTimeFormat);
                break;

            case 3:
                int div = (int)Math.Ceiling((float)(OrderTime.Minute / (int)BarInterval));
                // in case of the beginning of bar
                if (OrderTime.Minute % (int)BarInterval == 0)
                {
                    div++;
                }
                result = DateTime.Now.AddMinutes((int)BarInterval * div).ToString(DateTimeFormat);
                break;
            }
            return(result);
        }
Exemple #2
0
 /// <summary>
 /// Writes meta data values.
 /// </summary>
 /// <param name="writer">Instance of the <see cref="DataWriter"/> type.</param>
 public override void WriteMetaData(DataWriter writer)
 {
     base.WriteMetaData(writer);
     writer.WriteValue(CronExpressionPropertyName, CronExpression?.ToString(), null);
     writer.WriteValue(ExpressionTypePropertyName, typeof(StartTimerEventExpresionType), ExpressionType,
                       StartTimerEventExpresionType.Empty);
     writer.WriteValue(UseStartDateTimePropertyName, UseStartDateTime, false);
     writer.WriteValue(StartDateTimePropertyName, StartDateTime.ToString(DateTimeFormat), DefaultDateTimeValue);
     writer.WriteValue(UseEndDateTimePropertyName, UseEndDateTime, false);
     writer.WriteValue(EndDateTimePropertyName, EndDateTime.ToString(DateTimeFormat), DefaultDateTimeValue);
     writer.WriteValue(PeriodStartTimePropertyName, PeriodStartTime.ToString(DateTimeFormat),
                       DefaultDateTimeValue);
     writer.WriteValue(PeriodEndTimePropertyName, PeriodEndTime.ToString(DateTimeFormat), DefaultDateTimeValue);
     writer.WriteValue(UseExactTimePropertyName, UseExactTime, false);
     writer.WriteValue(ExactTimePropertyName, ExactTime.ToString(DateTimeFormat), DefaultDateTimeValue);
     writer.WriteValue(TimeZoneOffsetPropertyName, TimeZoneOffset?.Id, null);
     writer.WriteValue(UseCustomTimeZonePropertyName, UseCustomTimeZone, false);
 }