/// <summary>
        /// Applies the tag helper.
        /// </summary>
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            var modelExplorer = For.ModelExplorer;
            var fieldType     = modelExplorer.Metadata.UnderlyingOrModelType;

            if (fieldType == typeof(DateTime) || fieldType == typeof(DateTime?))
            {
                var localTime = _timeZoneProvider.ToUserLocalTime((DateTime)For.Model);
                output.Attributes.SetAttribute
                (
                    "value",
                    localTime.Second > 0
                                                ? localTime.ToString("s")
                                                : localTime.ToString("yyyy-MM-ddTHH\\:mm")
                );

                if (string.IsNullOrEmpty(modelExplorer.Metadata.TemplateHint) &&
                    string.IsNullOrEmpty(modelExplorer.Metadata.DataTypeName) &&
                    (output.Attributes["type"] == null ||
                     (string)output.Attributes["type"].Value == "datetime"))
                {
                    output.Attributes.SetAttribute("type", "datetime-local");
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Formats the given date, in the correct timezone.
        /// </summary>
        public static string FormatShortDate(
            this DateTime dateTime,
            ITimeZoneProvider timeZoneProvider)
        {
            var userTime = timeZoneProvider.ToUserLocalTime(dateTime);

            return(userTime.ToString("M/d"));
        }
Exemple #3
0
        /// <summary>
        /// Formats the given date time, in the correct timezone.
        /// </summary>
        public static string FormatLongDateTime(
            this DateTime dateTime,
            ITimeZoneProvider timeZoneProvider)
        {
            var userTime = timeZoneProvider.ToUserLocalTime(dateTime);

            return($"{userTime.ToString("M/d/yyyy")} at {userTime.ToString("h:mm tt")}");
        }
        /// <summary>
        /// Formats the given date time, in the correct timezone.
        /// </summary>
        public static string FormatShortDateTime(
            this DateTime dateTime,
            ITimeZoneProvider timeZoneProvider)
        {
            var userTime = timeZoneProvider.ToUserLocalTime(dateTime);

            return userTime.ToString("M/d/yyyy h:mm tt");
        }
        /// <summary>
        /// Formats the given date time, in the correct timezone.
        /// </summary>
        public static string FormatLongDateTime(
            this DateTime dateTime,
            ITimeZoneProvider timeZoneProvider)
        {
            var userTime = timeZoneProvider.ToUserLocalTime(dateTime);

            return $"{userTime.ToString("M/d/yyyy")} at {userTime.ToString("h:mm tt")}";
        }
        /// <summary>
        /// Returns a JSON property containing the value of a model property, for a given model object.
        /// </summary>
        private IEnumerable <JProperty> GetProperties(ModelMetadata modelMetadata, object obj)
        {
            object value = modelMetadata.PropertyGetter(obj);

            if (modelMetadata.ModelType == typeof(DateTime))
            {
                value = _timeZoneProvider.ToUserLocalTime((DateTime)value);
            }

            yield return(new JProperty(modelMetadata.PropertyName, value));
        }
        /// <summary>
        /// Returns an array of booleans, indicating whether each index
        /// is the first index corresponding to the given value's day.
        /// </summary>
        private bool[] GetDayBoundaries()
        {
            bool[] days = new bool[AllBuildTestCounts.Count];

            DateTime prevValue = DateTime.MinValue;

            for (int index = 0; index < AllBuildTestCounts.Count; index++)
            {
                var value = _timeZoneProvider.ToUserLocalTime(AllBuildTestCounts[index].PushDate).Date;
                if (value != prevValue)
                {
                    days[index] = true;
                    prevValue   = value;
                }
            }

            return(days);
        }