public IActionResult Topic(int id)
        {
            var section = _sectionService.GetByID(id);

            var posts = section.Posts;

            TimeDifference td = new TimeDifference();

            var postListing = posts.Select(post => new PostListingModel
            {
                Id = post.Id,
                Title = post.Title,
                DatePosted = post.Created.ToString(CultureInfo.InvariantCulture),
                Ago = td.PostTimeDifference(post.Created),
                AuthorName = post.User.FirstName + " " + post.User.LastName,
                Section = BuildSectionListing(post)
            }).OrderByDescending(post => post.DatePosted);

            var model = new SectionTopicModel
            {
                Posts = postListing,
                Section = BuildSectionListing(section)
            };

            return View(model);
        }
Beispiel #2
0
        // Methode, die aufgerufen wird, wenn Timer-Event auftritt
        private void MyTimer_Tick(object sender, EventArgs e)
        {
            TimeSpan TimeDifference;
            DateTime CurrentTime = DateTime.Now;
            string   t           = CurrentTime.ToString("H:mm:ss");

            lblCurrentTime.Content = t;

            if (MainController.getAlarms().Count() > 0)
            {
                DateTime NextAlarm = MainController.getAlarms()[0];

                //Remove old Alarms
                if (NextAlarm < CurrentTime)
                {
                    removeAlarm(NextAlarm);
                }

                //Calculate remaining time till next Alarm
                if (NextAlarm > CurrentTime)
                {
                    lblNextAlarm.Content = NextAlarm.ToString("H:mm");

                    TimeDifference           = NextAlarm - CurrentTime;
                    lblRemainingTime.Content = TimeDifference.ToString("hh\\:mm\\:ss");
                    setAlarmClocksVisibility(true);
                }
                else
                {
                    setAlarmClocksVisibility(false);
                }
            }
        }
        private HomeIndexModel BuildHomeIndexModel()
        {
            var            latestPost = _postService.GetLatestPost(10);
            TimeDifference td         = new TimeDifference();

            var posts = latestPost.Select(post => new PostListingModel
            {
                Id         = post.Id,
                Title      = post.Title,
                AuthorName = post.User.FirstName + " " + post.User.LastName,
                DatePosted = td.PostTimeDifference(post.Created),
                Section    = GetSectionListingForPost(post)
            });

            return(new HomeIndexModel
            {
                LatestPosts = posts
            });
        }
    public static TimeDifference GetDateTimeDifference(DateTime dateA, DateTime dateB)
    {
        int days;
        int months;
        int years;

        int fird = dateA.Day;
        int lasd = dateB.Day;

        int firm = dateA.Month;
        int lasm = dateB.Month;

        if (fird >= lasd)
        {
            days = fird - lasd;
            if (firm >= lasm)
            {
                months = firm - lasm;
                years  = dateA.Year - dateB.Year;
            }
            else
            {
                months = (firm + 12) - lasm;
                years  = dateA.AddYears(-1).Year - dateB.Year;
            }
        }
        else
        {
            days = (fird + 30) - lasd;
            if ((firm - 1) >= lasm)
            {
                months = (firm - 1) - lasm;
                years  = dateA.Year - dateB.Year;
            }
            else
            {
                months = (firm - 1 + 12) - lasm;
                years  = dateA.AddYears(-1).Year - dateB.Year;
            }
        }

        if (days < 0)
        {
            days = 0 - days;
        }

        if (months < 0)
        {
            months = 0 - months;
        }

        TimeSpan ts = dateA.Subtract(dateB);

        TimeDifference td = new TimeDifference
        {
            years   = years,
            months  = months,
            days    = days,
            hours   = ts.Hours,
            minutes = ts.Minutes,
            seconds = ts.Seconds
        };

        // Debug.Log($"Years: {years}, Months: {months}, Days: {days}, Hours: {ts.Hours}, Minutes: {ts.Minutes}, Seconds: {ts.Seconds}");

        return(td);
    }
Beispiel #5
0
 public static TimeDifferenceDto FromTimeDifference(TimeDifference timeDifference) => new TimeDifferenceDto
 (
     timeDifference.TimeData.Time,
     timeDifference.TimeData.Sensor?.SensorNumber ?? 0,
     timeDifference.DifferenceToLeader.TotalMilliseconds
 );