public static IPostgresTuple NullableTimestampToTuple(DateTime?value) { if (value.HasValue) { return(TimestampConverter.ToTuple(value.Value)); } return(null); }
private static void ToDbTimestamp(StringBuilder queryBuilder, ConstantExpression ce) { var dt = (DateTime)ce.Value; queryBuilder.Append("'"); queryBuilder.Append(TimestampConverter.ToDatabase(dt)); queryBuilder.Append("'::timestamptz"); }
public static DateTime ToDateTime(this string value) { if (!string.IsNullOrWhiteSpace(value)) { return(TimestampConverter.FromDatabase(value)); } return(DateTime.Now); }
public static DateTime?ToNullableDateTime(this string value) { if (!string.IsNullOrWhiteSpace(value)) { return(TimestampConverter.FromDatabase(value)); } return(null); }
public void ConvertNanoTime() { mockClock.Setup(clock => clock.Now).Returns(timestamp); mockClock.Setup(clock => clock.NowNanos).Returns(1234L); ITimestampConverter timeConverter = TimestampConverter.Now(mockClock.Object); Assert.Equal(Timestamp.Create(1234, 10678), timeConverter.ConvertNanoTime(6234)); Assert.Equal(Timestamp.Create(1234, 5444), timeConverter.ConvertNanoTime(1000)); Assert.Equal(Timestamp.Create(1235, 0), timeConverter.ConvertNanoTime(999995556)); }
public void TestDateTimeConverterTo() { // ARRANGE long time = 1525914401; DateTime dt = ServiceUtilities.ConvertFromUnixTimestamp(time); TimestampConverter converter = new TimestampConverter(); // ACT DynamoDBEntry data = converter.ToEntry(time); // ASSERT Assert.Equal(dt, DateTime.Parse(data.AsString()).ToUniversalTime()); }
private static void CurrentUtcTimestamp(MemberExpression memberCall, StringBuilder queryBuilder, Action <Expression> visitExpression, QueryContext context) { if (context.CanUseParams) { queryBuilder.Append("'"); queryBuilder.Append(TimestampConverter.ToDatabase(context.Time.Value.UtcNow)); queryBuilder.Append("'::timestamptz"); } else { queryBuilder.Append("CURRENT_TIMESTAMP"); } }
public static int TimestampToURI(char[] buf, int pos, DateTime value) { if (value.Kind == DateTimeKind.Utc) { value = value.ToLocalTime(); } var offset = CurrentZone.GetUtcOffset(value); if (offset.Minutes != 0) { return(TimestampConverter.Serialize(value.AddMinutes(offset.Minutes), buf, pos, offset.Hours)); } return(TimestampConverter.Serialize(value, buf, pos, offset.Hours)); }
private async Task <Tweet> ParseTweetAsync(string line) { var json = await Task.Run(() => (JObject)JsonConvert.DeserializeObject(line)); var id = long.Parse(json["id"].ToString()); var text = json["text"].ToString(); var source = json["source"].ToString(); var userId = long.Parse(json["user"].SelectToken("id").ToString()); var followers = int.Parse(json["user"].SelectToken("followers_count").ToString()); var timestamp = TimestampConverter.TimestampToDateTime(long.Parse(json["timestamp_ms"].ToString())); var tweet = new Tweet(id, text, source, userId, followers, timestamp); return(tweet); }
//@Rule public readonly ExpectedException exception = ExpectedException.none(); public SpanTest() { spanContext = SpanContext.Create(TraceId.GenerateRandomId(random), SpanId.GenerateRandomId(random), TraceOptions.DEFAULT); parentSpanId = SpanId.GenerateRandomId(random); testClock = TestClock.Create(timestamp); timestampConverter = TimestampConverter.Now(testClock); attributes.Add( "MyStringAttributeKey", AttributeValue.StringAttributeValue("MyStringAttributeValue")); attributes.Add("MyLongAttributeKey", AttributeValue.LongAttributeValue(123L)); attributes.Add("MyBooleanAttributeKey", AttributeValue.BooleanAttributeValue(false)); expectedAttributes = new Dictionary <String, IAttributeValue>(attributes); expectedAttributes.Add( "MySingleStringAttributeKey", AttributeValue.StringAttributeValue("MySingleStringAttributeValue")); }
public static int NullableTimestampToURI(char[] buf, int pos, DateTime?value) { if (value == null) { return(pos); } var v = value.Value; if (v.Kind == DateTimeKind.Utc) { v = v.ToLocalTime(); } var offset = CurrentZone.GetUtcOffset(v); if (offset.Minutes != 0) { return(TimestampConverter.Serialize(v.AddMinutes(offset.Minutes), buf, pos, offset.Hours)); } return(TimestampConverter.Serialize(v, buf, pos, offset.Hours)); }
public void TestDateTimeConverterFrom() { // ARRANGE DateTime date = DateTime.UtcNow; date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Kind); TimestampConverter converter = new TimestampConverter(); DynamoDBEntry entry = new Primitive() { Value = date.ToString("o") }; // ACT object data = converter.FromEntry(entry); DateTime derived = ServiceUtilities.ConvertFromUnixTimestamp((long)data); // ASSERT Assert.Equal(date, derived); }
public void Write_Returns_Expected_Value( long timestamp, string suffix, string expected) { using var stream = new MemoryStream(); using var writer = new Utf8JsonWriter(stream); var converter = new TimestampConverter(); converter.Write( writer, new Timestamp() { Suffix = suffix, Seconds = timestamp }, _options); writer.Flush(); var actual = Encoding.UTF8.GetString(stream.ToArray()); Assert.Equal( expected, actual); }
public static List <DateTime> ParseListTimestamp(Revenj.Utility.BufferedTextReader reader, int context) { return(TimestampConverter.ParseCollection(reader, context)); }
public static DateTime ParseTimestamp(Revenj.Utility.BufferedTextReader reader, int context) { return(TimestampConverter.Parse(reader, context)); }
public static IPostgresTuple TimestampToTuple(DateTime value) { return(TimestampConverter.ToTuple(value)); }