Exemplo n.º 1
0
        public TimeService(IScheduler scheduler)
        {
            this.scheduler = scheduler;

            CurrentDateTimeObservable =
                Observable
                .Interval(TimeSpan.FromSeconds(1), scheduler)
                .Select(_ => CurrentDateTime)
                .Publish().RefCount();

            var localTimeObservable = CurrentDateTimeObservable
                                      .Select(t => t.ToLocalTime());

            MidnightObservable = localTimeObservable
                                 .Zip(localTimeObservable.Skip(1), (previous, now) => (previous: previous, now: now))
                                 .Where(t => t.previous.Date != t.now.Date)
                                 .Select(t => t.now);
        }
Exemplo n.º 2
0
        public TimeService(IScheduler scheduler)
        {
            this.scheduler = scheduler;

            previousSecondLocalDateTime = CurrentDateTime.ToLocalTime();
            midnightSubject             = new Subject <DateTimeOffset>();

            CurrentDateTimeObservable =
                Observable
                .Interval(TimeSpan.FromSeconds(1), scheduler)
                .Select(_ => CurrentDateTime)
                .Do(tickOnMidnight)
                .Publish();

            MidnightObservable = midnightSubject.AsObservable().Publish();

            disposable.Add(CurrentDateTimeObservable.Connect());
            disposable.Add(MidnightObservable.Connect());
        }