public static DateTime GetAdjustedDateTimeFromServerSetAttributes(this SQSEvent.SQSMessage message, TimeSpan clockOffset) { var result = UnixEpoch.AddMilliseconds(long.Parse(message.Attributes["SentTimestamp"], NumberFormatInfo.InvariantInfo)); // Adjust for clock skew between this endpoint and aws. // https://aws.amazon.com/blogs/developer/clock-skew-correction/ return(result + clockOffset); }
public override String ConvertFromNumber(Double value) { var dt = UnixEpoch.AddMilliseconds(value); return(ConvertFromDate(dt)); }
/// <summary> /// 지정된 밀리초 수를 더한 새로운 (UTC) System.DateTime을 반환합니다. /// </summary> /// <param name="milliSeconds"></param> /// <returns></returns> public static DateTime ConvertToUtcTimeMilli(Int64 milliSeconds) { return(UnixEpoch.AddMilliseconds(milliSeconds).ToUniversalTime()); }
void LoadInternal(BEncodedDictionary torrentInformation, InfoHash infoHash) { Check.TorrentInformation(torrentInformation); AnnounceUrls = new List <IList <string> > ().AsReadOnly(); foreach (KeyValuePair <BEncodedString, BEncodedValue> keypair in torrentInformation) { switch (keypair.Key.Text) { case ("announce"): // Ignore this if we have an announce-list if (torrentInformation.ContainsKey("announce-list")) { break; } AnnounceUrls = new List <IList <string> > { new List <string> { keypair.Value.ToString() }.AsReadOnly() }.AsReadOnly(); break; case ("creation date"): try { try { CreationDate = UnixEpoch.AddSeconds(long.Parse(keypair.Value.ToString())); } catch (Exception e) { if (e is ArgumentOutOfRangeException) { CreationDate = UnixEpoch.AddMilliseconds(long.Parse(keypair.Value.ToString())); } else { throw; } } } catch (Exception e) { if (e is ArgumentOutOfRangeException) { throw new BEncodingException("Argument out of range exception when adding seconds to creation date.", e); } else if (e is FormatException) { throw new BEncodingException($"Could not parse {keypair.Value} into a number", e); } else { throw; } } break; case ("nodes"): if (keypair.Value is BEncodedList list) { Nodes = list; } break; case ("comment.utf-8"): if (keypair.Value.ToString().Length != 0) { Comment = keypair.Value.ToString(); // Always take the UTF-8 version } break; // even if there's an existing value case ("comment"): if (string.IsNullOrEmpty(Comment)) { Comment = keypair.Value.ToString(); } break; case ("publisher-url.utf-8"): // Always take the UTF-8 version PublisherUrl = keypair.Value.ToString(); // even if there's an existing value break; case ("publisher-url"): if (string.IsNullOrEmpty(PublisherUrl)) { PublisherUrl = keypair.Value.ToString(); } break; case ("created by"): CreatedBy = keypair.Value.ToString(); break; case ("encoding"): Encoding = keypair.Value.ToString(); break; case ("info"): InfoHash = infoHash; ProcessInfo(((BEncodedDictionary)keypair.Value)); break; case ("name"): // Handled elsewhere break; case ("announce-list"): if (keypair.Value is BEncodedString) { break; } var result = new List <IList <string> > (); var announces = (BEncodedList)keypair.Value; for (int j = 0; j < announces.Count; j++) { if (announces[j] is BEncodedList bencodedTier) { var tier = new List <string> (bencodedTier.Count); for (int k = 0; k < bencodedTier.Count; k++) { tier.Add(bencodedTier[k].ToString()); } Toolbox.Randomize(tier); var resultTier = new List <string> (); for (int k = 0; k < tier.Count; k++) { resultTier.Add(tier[k]); } if (resultTier.Count != 0) { result.Add(tier.AsReadOnly()); } } else { throw new BEncodingException( $"Non-BEncodedList found in announce-list (found {announces[j].GetType ()})"); } } if (result.Count > 0) { AnnounceUrls = result.AsReadOnly(); } break; case ("httpseeds"): // This form of web-seeding is not supported. break; case ("url-list"): if (keypair.Value is BEncodedString httpSeedString) { HttpSeeds.Add(httpSeedString.Text); } else if (keypair.Value is BEncodedList httpSeedList) { foreach (BEncodedString str in httpSeedList) { HttpSeeds.Add(str.Text); } } break; default: break; } } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { return(UnixEpoch.AddMilliseconds((long)reader.Value)); }
public static DateTimeOffset FromUnixTimeMilliseconds(long milliseconds) { return(UnixEpoch.AddMilliseconds(milliseconds)); }