Beispiel #1
0
        /// <summary>
        /// Parses the Unix timestamp at <paramref name="path"/>.
        ///
        /// In some cases, the Graph APi may return <c>0</c> indicating no value - if this is the case, this method will return <c>null</c> instead of <see cref="EssentialsTime.Zero"/>.
        /// </summary>
        /// <param name="obj">The parent object.</param>
        /// <param name="path">A <see cref="string"/> that contains a JPath expression.</param>
        /// <returns></returns>
        protected EssentialsTime ParseUnixTimestamp(JObject obj, string path)
        {
            if (obj.HasValue(path) == false)
            {
                return(null);
            }
            int value = obj.GetInt32(path);

            return(value > 0 ? EssentialsTime.FromUnixTimestamp(value) : null);
        }
Beispiel #2
0
        public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
        {
            if (!(inter is string str) || str.Length <= 0 || !int.TryParse(str, out int seconds))
            {
                return(null);
            }

            // Find the selected time zone
            TimeZoneInfo timeZone = GetTimeZoneInfo(propertyType.DataType.Configuration as UnixTimestampConfiguration);

            // Convert to UNIX time from the specified seconds
            EssentialsTime timestamp = EssentialsTime.FromUnixTimestamp(seconds).ToTimeZone(timeZone);

            return(timestamp);
        }
 /// <summary>
 /// Parses the specified millisecond UNIX timestamp into an instance of <see cref="EssentialsTime"/>.
 /// </summary>
 /// <param name="timestamp">The timestamp to be parsed.</param>
 /// <returns>An instance of <see cref="EssentialsTime"/>.</returns>
 protected EssentialsTime ParseUnixTimestamp(long timestamp)
 {
     return(EssentialsTime.FromUnixTimestamp(timestamp / 1000));
 }