/// <summary>
        /// Converts timestamp to date and time with timezone.
        /// Timezone depends on converter parameter.
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>Cardinal direction.</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is ulong timestamp && parameter is BindableString offsetString &&
                long.TryParse(offsetString.Value, out long offset))
            {
                return(TimeStamp.Convert(timestamp).AddSeconds(offset).ToShortTimeString());
            }

            return(string.Empty);
        }
        /// <summary>
        /// Converts time stamp to date object.
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>Date and hour in local format.</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var date = string.Empty;

            if (value is ulong time)
            {
                date = TimeStamp.Convert(time).ToLocalTime().ToString("g");
            }

            return(date);
        }
示例#3
0
        /// <summary>
        /// Converts timestamp to date and time with timezone.
        /// Timezone depends on converter parameter.
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>Cardinal direction.</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is ulong timestamp && parameter is BindableString offsetString &&
                long.TryParse(offsetString.Value, out long offset))
            {
                var time = TimeStamp.Convert(timestamp).AddSeconds(offset).ToString("g");
                return($"{time} (KST{offset / 60 / 60:+#;-#;+0})");
            }

            return(string.Empty);
        }
        /// <summary>
        /// Converts timestamp to time of the day.
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>Time of the day.</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var date = string.Empty;

            if (value is ulong time)
            {
                if (parameter is Models.Location.TimeZone timeZone)
                {
                    date = TimeStamp.Convert(time).AddSeconds(timeZone.Offset)
                           .ToString(culture.DateTimeFormat.ShortTimePattern);
                }
                else
                {
                    date = TimeStamp.Convert((ulong)value).ToString(culture.DateTimeFormat.ShortTimePattern);
                }
            }

            return(date);
        }