public static string GetCurrentTimeStamp(TimestampFormat tsf) { string str = ""; string str1 = ""; switch (tsf) { case TimestampFormat.European: { str = "dd/MM/yyyy"; str1 = "HH:mm:ss"; break; } case TimestampFormat.American: { str = "MM-dd-yyyy"; str1 = "h:mm:ss tt"; break; } default: { str = "yyyyMMdd"; str1 = "HHmmss"; break; } } string str2 = DateTime.Today.ToString(str); DateTime now = DateTime.Now; string str3 = string.Concat(str2, " ", now.ToString(str1)); return(str3); }
public void FormatMessageParts_FormatTimestamp_TimestampIsFormattedCorrectly(TimestampFormat format, string pattern) { var formatter = CreateFormatter(x => x.TimestampFormat = format); var messages = formatter.FormatMessageParts(Bot.Build <LogMessageEntry>()); messages.First().Text.Should().MatchRegex(pattern); }
/// <summary> /// Populates the values in the current instance by parsing /// its field data in a specified version. /// </summary> /// <param name="data"> /// A <see cref="ByteVector" /> object containing the /// extracted field data. /// </param> /// <param name="version"> /// A <see cref="byte" /> indicating the ID3v2 version the /// field data is encoded in. /// </param> protected override void ParseFields(ByteVector data, byte version) { if (data.Count < 6) { throw new CorruptFileException( "Not enough bytes in field."); } encoding = (StringType)data [0]; language = data.ToString(StringType.Latin1, 1, 3); timestamp_format = (TimestampFormat)data [4]; lyrics_type = (SynchedTextType)data [5]; ByteVector delim = ByteVector.TextDelimiter( encoding); int delim_index = data.Find(delim, 6, delim.Count); if (delim_index < 0) { throw new CorruptFileException( "Text delimiter expected."); } description = data.ToString(encoding, 6, delim_index - 6); int offset = delim_index + delim.Count; List <SynchedText> l = new List <SynchedText> (); while (offset + delim.Count + 4 < data.Count) { delim_index = data.Find(delim, offset, delim.Count); if (delim_index < offset) { throw new CorruptFileException( "Text delimiter expected."); } string text = data.ToString(encoding, offset, delim_index - offset); offset = delim_index + delim.Count; if (offset + 4 > data.Count) { break; } l.Add(new SynchedText(data.Mid(offset, 4) .ToUInt(), text)); offset += 4; } this.text = l.ToArray(); }
public static string DateTimeToTimeStamp(this DateTime?dt, TimestampFormat tf = TimestampFormat.RelativeTime, string def = "NA") { if (dt != null) { return(DateTimeToTimeStamp((DateTime)dt, tf)); } else { return(def); } }
/// <summary> /// Initializes <see cref="AzureEventHubOutputAdapter"/>. /// </summary> public override void Initialize() { base.Initialize(); new ConnectionStringParser().ParseConnectionString(ConnectionString, this); if (string.IsNullOrWhiteSpace(TimestampFormat)) { TimestampFormat = DefaultTimestampFormat; } m_useEpochMilliseconds = TimestampFormat.Trim().Equals(DefaultTimestampFormat, StringComparison.OrdinalIgnoreCase); }
private static string GetDateTimeFormat(TimestampFormat format) { switch (format) { case TimestampFormat.DateTimeMs: return("yyyy-MM-dd HH:mm:ss.fff"); case TimestampFormat.TimeMs: return("HH:mm:ss.fff"); case TimestampFormat.Time: return("HH:mm:ss"); } return(""); }
public static string GetTestDate(TimestampFormat timestampFormat) { switch (timestampFormat) { case TimestampFormat.ISO8601: return(Constants.DEFAULT_DATE.ToString(AWSSDKUtils.ISO8601DateFormat, CultureInfo.InvariantCulture)); case TimestampFormat.RFC822: return(Constants.DEFAULT_DATE.ToString(AWSSDKUtils.RFC822DateFormat, CultureInfo.InvariantCulture)); case TimestampFormat.UnixTimestamp: return(GetTestEpochTime().TotalSeconds.ToString(CultureInfo.InvariantCulture)); default: throw new InvalidOperationException("Encountered unsupported TimestampFormat: " + timestampFormat); } }
public async ValueTask <MessariResponse <TimeSeriesMarketResponse> > GetMarketTimeSeriesAsync( string marketKey, string metricId, DateTime start, DateTime end, Interval interval = Interval._1d, string columns = "open,close", Order order = Order.Asc, Format format = Format.Json, TimestampFormat timestampFormat = TimestampFormat.Rfc3339 ) { var urlPattern = $"v1/markets/{marketKey}/metrics/{metricId}/time-series"; var qsb = new QueryStringBuilder(); qsb.Add("start", start.ToString("yyyy-MM-dd")); qsb.Add("end", end.ToString("yyyy-MM-dd")); qsb.Add("interval", interval.GetDescription()); qsb.Add("columns", columns); qsb.Add("order", order.GetDescription()); qsb.Add("format", format.GetDescription()); qsb.Add("timestamp-format", timestampFormat.GetDescription()); return(await _executor.ExecuteAsync <TimeSeriesMarketResponse>(urlPattern, qsb).ConfigureAwait(false)); }
/// <summary> /// Populates the values in the current instance by parsing /// its field data in a specified version. /// </summary> /// <param name="data"> /// A <see cref="ByteVector" /> object containing the /// extracted field data. /// </param> /// <param name="version"> /// A <see cref="byte" /> indicating the ID3v2 version the /// field data is encoded in. /// </param> protected override void ParseFields(ByteVector data, byte version) { events = new List <EventTimeCode>(); timestampFormat = (TimestampFormat)data.Data[0]; var incomingEventsData = data.Mid(1); for (var i = 0; i < incomingEventsData.Count - 1; i++) { var eventType = (EventType)incomingEventsData.Data[i]; i++; var timestampData = new ByteVector(incomingEventsData.Data[i], incomingEventsData.Data[i + 1], incomingEventsData.Data[i + 2], incomingEventsData.Data[i + 3]); i += 3; var timestamp = timestampData.ToInt(); events.Add(new EventTimeCode(eventType, timestamp)); } }
public static string DateTimeToTimeStamp(this DateTime dt, TimestampFormat tf = TimestampFormat.RelativeTime) { return(Formatter.Timestamp(dt, tf)); }
public static string Timestamp(long unixTimestamp, TimestampFormat format) => new StringBuilder().Append("<t:").Append(unixTimestamp).Append(':').Append((char)format).Append('>').ToString();
/// <summary> /// Creates a rendered timestamp. /// </summary> /// <param name="time">The time from now.</param> /// <param name="format">The format to render the timestamp in. Defaults to relative.</param> /// <returns>A formatted timestamp relative to now.</returns> public static string Timestamp(DateTime time, TimestampFormat format = TimestampFormat.RelativeTime) => Timestamp(time.ToUniversalTime() - DateTime.UtcNow, format);
/// <summary> /// Creates a rendered timestamp. /// </summary> /// <param name="time">The time from now.</param> /// <param name="format">The format to render the timestamp in. Defaults to relative.</param> /// <returns>A formatted timestamp relative to now.</returns> public static string Timestamp(TimeSpan time, TimestampFormat format = TimestampFormat.RelativeTime) => $"<t:{(DateTimeOffset.UtcNow + time).ToUnixTimeSeconds()}:{(char)format}>";
/// <summary> /// Creates a rendered timestamp. /// </summary> /// <param name="time">Timestamp to format.</param> /// <param name="format">The format to render the timestamp in. Defaults to relative.</param> /// <returns>A formatted timestamp.</returns> public static string Timestamp(DateTimeOffset time, TimestampFormat format = TimestampFormat.RelativeTime) => $"<t:{time.ToUnixTimeSeconds()}:{(char)format}>";
/// <summary> /// Creates a rendered timestamp. /// </summary> /// <param name="time">The time from now.</param> /// <param name="format">The format to render the timestamp in. Defaults to relative.</param> /// <returns>A formatted timestamp.</returns> public static string Timestamp(DateTime time, TimestampFormat format = TimestampFormat.RelativeTime) => Timestamp(new DateTimeOffset(time.ToUniversalTime()), format);
protected override void ParseFields(ByteVector data, byte version) { if (data.Count < 6) { throw new CorruptFileException("Not enough bytes in field."); } this.encoding = (StringType) data[0]; this.language = data.ToString(StringType.Latin1, 1, 3); this.timestamp_format = (TimestampFormat) data[4]; this.lyrics_type = (SynchedTextType) data[5]; ByteVector pattern = ByteVector.TextDelimiter(this.encoding); int num = data.Find(pattern, 6, pattern.Count); if (num < 0) { throw new CorruptFileException("Text delimiter expected."); } this.description = data.ToString(this.encoding, 6, num - 6); int offset = num + pattern.Count; List<SynchedText> list = new List<SynchedText>(); while (((offset + pattern.Count) + 4) < data.Count) { num = data.Find(pattern, offset, pattern.Count); if (num < offset) { throw new CorruptFileException("Text delimiter expected."); } string text = data.ToString(this.encoding, offset, num - offset); offset = num + pattern.Count; if ((offset + 4) > data.Count) { break; } list.Add(new SynchedText((long) data.Mid(offset, 4).ToUInt(), text)); offset += 4; } this.text = list.ToArray(); }
public PositionSynchronization() { m_TimestampFormat = TimestampFormat.Milliseconds; }
public override void Read(TagReadingInfo tagReadingInfo, Stream stream) { Items.Clear(); _frameHeader.Read(tagReadingInfo, ref stream); int bytesLeft = _frameHeader.FrameSizeExcludingAdditions; if (bytesLeft >= 1) { TextEncoding = (EncodingType)stream.Read1(ref bytesLeft); if (bytesLeft >= 3) { LanguageCode = ID3v2Utils.ReadString(EncodingType.ISO88591, stream, 3); bytesLeft -= 3; if (bytesLeft >= 2) { TimestampFormat = (TimestampFormat)stream.Read1(ref bytesLeft); ContentType = (TextContentType)stream.Read1(ref bytesLeft); if (bytesLeft > 0) { ContentDescriptor = ID3v2Utils.ReadString(TextEncoding, stream, ref bytesLeft); while (bytesLeft > 0) { string lyrics = ID3v2Utils.ReadString(TextEncoding, stream, ref bytesLeft); if (bytesLeft >= 4) { SynchronizedTextItem textItem = new SynchronizedTextItem(); textItem.Text = lyrics; textItem.Timestamp = stream.ReadInt32(); bytesLeft -= 4; Items.Add(textItem); } } } else { // Incomplete frame ContentDescriptor = ""; } } else { // Incomplete frame TimestampFormat = TimestampFormat.Milliseconds; ContentType = TextContentType.Other; ContentDescriptor = ""; } } else { // Incomplete frame LanguageCode = "eng"; TimestampFormat = TimestampFormat.Milliseconds; ContentType = TextContentType.Other; ContentDescriptor = ""; } } else { // Incomplete frame TextEncoding = EncodingType.ISO88591; LanguageCode = "eng"; TimestampFormat = TimestampFormat.Milliseconds; ContentType = TextContentType.Other; ContentDescriptor = ""; } if (bytesLeft > 0) { stream.Seek(bytesLeft, SeekOrigin.Current); } }
public static string ToDiscordFormatStringValue(this TimestampFormat format) => new string(new[] { (char)format });
// https://www.reddit.com/r/discordapp/comments/ob2h2l/discord_added_new_timestamp_formatting/ /* * Use <t:TIMESTAMP:FLAG> to send it * Available flags: * t: Short time (e.g 9:41 PM) * T: Long Time (e.g. 9:41:30 PM) * d: Short Date (e.g. 30/06/2021) * D: Long Date (e.g. 30 June 2021) * f (default): Short Date/Time (e.g. 30 June 2021 9:41 PM) * F: Long Date/Time (e.g. Wednesday, June, 30, 2021 9:41 PM) * R: Relative Time (e.g. 2 months ago, in an hour) */ public static string ToDiscordMessageTs(this DateTimeOffset when, TimestampFormat format = TimestampFormat.ShortDateTime) => $"<t:{when.ToUnixTimeSeconds()}:{format.ToDiscordFormatStringValue()}>";
public static string Timestamp(DateTimeOffset dateTimeOffset, TimestampFormat format) => Timestamp(dateTimeOffset.ToUnixTimeSeconds(), format);
/// <summary> /// Creates a rendered timestamp. /// </summary> /// <param name="time">The time from now.</param> /// <param name="format">The format to render the timestamp in. Defaults to relative.</param> /// <returns>A formatted timestamp.</returns> public static string Timestamp(TimeSpan time, TimestampFormat format = TimestampFormat.RelativeTime) => Timestamp(DateTimeOffset.UtcNow + time, format);
/// <summary> /// Populates the values in the current instance by parsing /// its field data in a specified version. /// </summary> /// <param name="data"> /// A <see cref="ByteVector" /> object containing the /// extracted field data. /// </param> /// <param name="version"> /// A <see cref="byte" /> indicating the ID3v2 version the /// field data is encoded in. /// </param> protected override void ParseFields(ByteVector data, byte version) { if (data.Count < 6) throw new CorruptFileException ( "Not enough bytes in field."); encoding = (StringType) data [0]; language = data.ToString (StringType.Latin1, 1, 3); timestamp_format = (TimestampFormat) data [4]; lyrics_type = (SynchedTextType) data [5]; ByteVector delim = ByteVector.TextDelimiter ( encoding); int delim_index = data.Find (delim, 6, delim.Count); if (delim_index < 0) throw new CorruptFileException ( "Text delimiter expected."); description = data.ToString (encoding, 6, delim_index - 6); int offset = delim_index + delim.Count; List<SynchedText> l = new List<SynchedText> (); while (offset + delim.Count + 4 < data.Count) { delim_index = data.Find (delim, offset, delim.Count); if (delim_index < offset) throw new CorruptFileException ( "Text delimiter expected."); string text = data.ToString (encoding, offset, delim_index - offset); offset = delim_index + delim.Count; if (offset + 4 > data.Count) break; l.Add (new SynchedText (data.Mid (offset, 4) .ToUInt (), text)); offset += 4; } this.text = l.ToArray (); }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="EventTimeCodesFrame" /> by reading its raw data /// in a specified ID3v2 version. /// </summary> /// <param name="timestampFormat"> /// A <see cref="TimestampFormat" /> Specifies the time unit to use in this frame. /// </param> public EventTimeCodesFrame(TimestampFormat timestampFormat) : base(FrameType.ETCO, 4) { TimestampFormat = timestampFormat; Flags = FrameFlags.FileAlterPreservation; }