Click here to Skip to main content
15,892,517 members
Articles / Web Development / HTML

Using DayPilot (Outlook-Like Calendar/Scheduling Control for ASP.NET)

Rate me:
Please Sign up or sign in to vote.
4.83/5 (64 votes)
30 Mar 2015Apache7 min read 367.9K   4.2K   286  
Showing the features of a flexible ASP.NET event calendar/scheduling control.
/*
Copyright � 2005 - 2015 Annpoint, s.r.o.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-------------------------------------------------------------------------

NOTE: Reuse requires the following acknowledgement (see also NOTICE):
This product includes DayPilot (http://www.daypilot.org) developed by Annpoint, s.r.o.
*/

using System;
using DayPilot.Web.Ui;
using DayPilot.Web.Ui.Enums;

namespace DayPilot.Utils
{
    /// <summary>
    /// Helper class for hour formatting.
    /// </summary>
    public class TimeFormatter
    {
        /// <summary>
        /// Extracts hour from DateTime class and formats it for 12/24 hours clock.
        /// </summary>
        /// <param name="time"></param>
        /// <param name="clock"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public static string GetHour(DateTime time, TimeFormat clock, string format)
        {
            return GetHour(time.Hour, clock, format);
        }

        /// <summary>
        /// Formats an hour number for 12/24 hours clock.
        /// </summary>
        /// <param name="hour"></param>
        /// <param name="clock"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public static string GetHour(int hour, TimeFormat clock, string format)
        {
            bool am = (hour / 12) == 0;
            if (clock == TimeFormat.Clock12Hours)
            {
                hour = hour % 12;
                if (hour == 0)
                    hour = 12;
            }

            string suffix = String.Empty;
            if (clock == TimeFormat.Clock12Hours)
            {
                if (am)
                {
                    suffix = "AM";
                }
                else
                {
                    suffix = "PM";
                }
            }

            if (String.IsNullOrEmpty(format))
            {
                format = "{0} {1}";
            }

            return String.Format(format, hour, suffix);

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Czech Republic Czech Republic
My open-source event calendar/scheduling web UI components:

DayPilot for JavaScript, Angular, React and Vue

Comments and Discussions