Beispiel #1
0
        /// <summary>
        /// Set a datetime value, truncating it to the metric's resolution.
        /// </summary>
        /// <param name="value"> The [Date] value to set. If not provided, will record the current time.
        public void Set(DateTimeOffset value = new DateTimeOffset())
        {
            if (disabled)
            {
                return;
            }
            // The current time of datetime offset.
            var currentTime = value.DateTime;
            // InvariantCulture calendar still preserves timezones and locality information,
            // it just formats them in a way to ease persistence.
            var calendar = CultureInfo.InvariantCulture.Calendar;

            Dispatchers.LaunchAPI(() => {
                LibGleanFFI.glean_datetime_set(
                    handle,
                    year: calendar.GetYear(currentTime),
                    month: calendar.GetMonth(currentTime),
                    day: calendar.GetDayOfMonth(currentTime),
                    hour: calendar.GetHour(currentTime),
                    minute: calendar.GetMinute(currentTime),
                    second: calendar.GetSecond(currentTime),
                    nano: Convert.ToInt64(1000000 * calendar.GetMilliseconds(currentTime)),
                    offset_seconds: Convert.ToInt32((currentTime - value.UtcDateTime).TotalSeconds)
                    );;
            });
        }