Example #1
0
        public bool CanRun()
        {
            var now           = DateTime.UtcNow;
            var referenceTime = ReferenceTime;

            if (TimeZone != null)
            {
                now           = _clock.ConvertToTimeZone(DateTime.UtcNow, TimeZone).DateTime;
                referenceTime = _clock.ConvertToTimeZone(ReferenceTime, TimeZone).DateTime;
            }

            var nextStartTime = CrontabSchedule.Parse(Settings.Schedule).GetNextOccurrence(referenceTime);

            if (now >= nextStartTime)
            {
                if (Settings.Enable && !Released && Updated)
                {
                    return(true);
                }

                ReferenceTime = DateTime.UtcNow;
            }

            return(false);
        }
        public ToLocalTimeTransform(
            IContext context       = null,
            IClock clock           = null,
            ILocalClock localClock = null
            ) : base(context, "datetime")
        {
            if (IsMissingContext())
            {
                return;
            }

            if (IsNotReceiving("date"))
            {
                return;
            }

            _input = SingleInput();

            _clock = clock;

            var localTimeZone = localClock.GetLocalTimeZoneAsync().Result;

            _transform = (dt) => {
                if (dt.Kind != DateTimeKind.Utc)
                {
                    dt = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
                }
                return(_clock.ConvertToTimeZone(dt, localTimeZone).DateTime);
            };
        }
Example #3
0
        /// <summary>
        /// Converts a <see cref="DateTime" /> to the specified <see cref="ITimeZone" /> instance.
        /// </summary>
        public static DateTimeOffset ConvertToTimeZone(this IClock clock, DateTime dateTime, ITimeZone timeZone)
        {
            DateTime dateTimeUtc;

            switch (dateTime.Kind)
            {
            case DateTimeKind.Utc:
                dateTimeUtc = dateTime;
                break;

            case DateTimeKind.Local:
                dateTimeUtc = dateTime.ToUniversalTime();
                break;

            default:     //DateTimeKind.Unspecified
                dateTimeUtc = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
                break;
            }

            return(clock.ConvertToTimeZone(new DateTimeOffset(dateTimeUtc), timeZone));
        }
Example #4
0
 private async Task <DateTimeOffset> GetLocalNowAsync()
 {
     return(_clock.ConvertToTimeZone(_clock.UtcNow, await GetLocalTimeZoneAsync()));
 }