Exemplo n.º 1
0
        /// <summary>
        /// Converts the instance into a local date time
        /// </summary>
        /// <param name="dateTime">The current instance of the date time</param>
        /// <param name="timeZone">The time zone to convert to</param>
        /// <returns>The same date time but expressed in local time</returns>
        public static DateTime?ToLocal(this DateTime?dateTime, string timeZone = null)
        {
            if (dateTime == null)
            {
                return(null);
            }

            IDateTimeConverter converter = new LocalDateTimeConverter(timeZone);

            return(converter.Convert((DateTime)dateTime));
        }
Exemplo n.º 2
0
        public void LocalDateTimeConverter_ConvertToLocalTime_DateTime_UseCustomTimezone_Success()
        {
            const string inputValue  = "2016-12-31 15:00";
            string       outputValue = "";
            const string timeZone    = "Europe/Brussels";

            IDateTimeConverter converter = new LocalDateTimeConverter(timeZone);

            const string exactFormat = "yyyy-MM-dd HH:mm";

            if (DateTime.TryParseExact(inputValue, exactFormat, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime output))
            {
                DateTime convertedDate = converter.Convert(DateTime.SpecifyKind(output, DateTimeKind.Utc));
                outputValue = convertedDate.ToString(exactFormat);
            }

            Assert.True(outputValue == "2016-12-31 16:00");
        }
        private void PART_ScCompactView_IsLoaded(object sender, RoutedEventArgs e)
        {
            PART_ScCompactView.Children.Clear();
            PART_ScCompactView.ColumnDefinitions.Clear();

            // Prepare Grid 40x40 & add data
            double actualWidth = PART_ScCompactView.ActualWidth;
            int    nbGrid      = (int)actualWidth / 52;

#if DEBUG
            logger.Debug($"SuccessStory - SuccessStoryAchievementsCompact - actualWidth: {actualWidth} - nbGrid: {nbGrid} - AchievementsList: {AchievementsList.Count}");
#endif

            if (nbGrid > 0)
            {
                for (int i = 0; i < nbGrid; i++)
                {
                    ColumnDefinition gridCol = new ColumnDefinition();
                    gridCol.Width = new GridLength(1, GridUnitType.Star);
                    PART_ScCompactView.ColumnDefinitions.Add(gridCol);

                    if (i < AchievementsList.Count)
                    {
                        if (i < nbGrid - 1)
                        {
                            Image gridImage = new Image();
                            gridImage.Stretch = Stretch.UniformToFill;
                            gridImage.Width   = 48;
                            gridImage.Height  = 48;
                            gridImage.ToolTip = AchievementsList[i].Name;
                            gridImage.SetValue(Grid.ColumnProperty, i);

                            if (_withUnlocked)
                            {
                                var converter = new LocalDateTimeConverter();
                                converter.Convert(AchievementsList[i].DateUnlock, null, null, null);
                                gridImage.ToolTip += " (" + converter.Convert(AchievementsList[i].DateUnlock, null, null, null) + ")";
                            }

                            if (AchievementsList[i].IsGray)
                            {
                                var tmpImg = new BitmapImage(new Uri(AchievementsList[i].Icon, UriKind.Absolute));
                                gridImage.Source = ImageTools.ConvertBitmapImage(tmpImg, ImageColor.Gray);

                                ImageBrush imgB = new ImageBrush
                                {
                                    ImageSource = new BitmapImage(new Uri(AchievementsList[i].IconImage, UriKind.Absolute))
                                };
                                gridImage.OpacityMask = imgB;
                            }
                            else
                            {
                                gridImage.Source = new BitmapImage(new Uri(AchievementsList[i].Icon, UriKind.Absolute));
                            }

                            DropShadowEffect myDropShadowEffect = new DropShadowEffect();
                            myDropShadowEffect.ShadowDepth = 0;
                            myDropShadowEffect.BlurRadius  = 30;

                            SetColorConverter setColorConverter = new SetColorConverter();
                            var color = setColorConverter.Convert(AchievementsList[i].Percent, null, null, CultureInfo.CurrentCulture);

                            if (color != null)
                            {
                                myDropShadowEffect.Color = (Color)color;
                            }

                            if (_EnableRaretyIndicator)
                            {
                                gridImage.Effect = myDropShadowEffect;
                            }

                            PART_ScCompactView.Children.Add(gridImage);
                        }
                        else
                        {
                            Label lb = new Label();
                            lb.FontSize            = 16;
                            lb.Content             = $"+{AchievementsList.Count - i}";
                            lb.VerticalAlignment   = VerticalAlignment.Center;
                            lb.HorizontalAlignment = HorizontalAlignment.Center;
                            lb.SetValue(Grid.ColumnProperty, i);

                            PART_ScCompactView.Children.Add(lb);

#if DEBUG
                            logger.Debug($"SuccessStory - SuccessStoryAchievementsCompact - AchievementsList.Count: {AchievementsList.Count} - nbGrid: {nbGrid} - i: {i}");
#endif
                        }
                    }
                }
            }
            else
            {
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Converts the instance into a local date time
        /// </summary>
        /// <param name="dateTime">The current instance of the date time</param>
        /// <param name="timeZone">The time zone to convert to</param>
        /// <returns>The same date time but expressed in local time</returns>
        public static DateTime ToLocal(this DateTime dateTime, string timeZone = null)
        {
            IDateTimeConverter converter = new LocalDateTimeConverter(timeZone);

            return(converter.Convert(dateTime));
        }