public void TestGetObjectDateTimeValue() { DateTime dateTime = new DateTime(); Date date = new Date(); date.year = 2012; date.month = 12; date.day = 2; dateTime.date = date; dateTime.hour = 12; dateTime.minute = 45; dateTime.second = 0; dateTime.timeZoneID = "Asia/Shanghai"; DateTimeValue dateTimeValue = new DateTimeValue(); dateTimeValue.value = dateTime; Assert.AreEqual(dateTime, PqlUtilities.GetValue(dateTimeValue)); }
/// <summary> /// Gets the text value of an object. /// </summary> /// <param name="value">The value.</param> /// <returns>A formatted text representation of the value.</returns> /// <remarks>DateValue is formatted in yyyy-mm-dd format. DateTimeValue is /// formatted in yyyy-mm-dd HH:mm:ss Z format.</remarks> private static string getTextValue(Object value) { if (value == null) { return(""); } if (value is DateValue) { Google.Api.Ads.Dfp.v201505.DateValue dateValue = (Google.Api.Ads.Dfp.v201505.DateValue)value; return(string.Format("{0:0000}-{1:00}-{2:00}", dateValue.value.year, dateValue.value.month, dateValue.value.day)); } else if (value is DateTimeValue) { Google.Api.Ads.Dfp.v201505.DateTimeValue dateTimeValue = (Google.Api.Ads.Dfp.v201505.DateTimeValue)value; return(string.Format("{0:0000}-{1:00}-{2:00}T{3:00}:{4:00}:{5:00} {6}", dateTimeValue.value.date.year, dateTimeValue.value.date.month, dateTimeValue.value.date.day, dateTimeValue.value.hour, dateTimeValue.value.minute, dateTimeValue.value.second, dateTimeValue.value.timeZoneID)); } else if (value is List <object> ) { List <string> textValues = (value as List <object>) .ConvertAll(new Converter <object, string>(getTextValue)) .ConvertAll(new Converter <string, string>(EscapeCsv)); return(String.Join <string>(",", textValues)); } else { // NumberValue, BooleanValue, TextValue return(value.ToString()); } }
/// <summary> /// Adds a new DateTime value to the list of query parameters. /// </summary> /// <param name="key">The parameter name.</param> /// <param name="value">The parameter value.</param> /// <returns>The statement builder, for chaining method calls.</returns> public StatementBuilder AddValue(string key, DateTime value) { DateTimeValue queryValue = new DateTimeValue(); queryValue.value = value; return AddValue(key, queryValue); }
public void TestGetObjectDateTimeSetValue() { DateTime dateTime = new DateTime(); Date date = new Date(); date.year = 2012; date.month = 12; date.day = 2; dateTime.date = date; dateTime.hour = 12; dateTime.minute = 45; dateTime.second = 0; dateTime.timeZoneID = "Asia/Shanghai"; DateTimeValue dateTimeValue = new DateTimeValue(); dateTimeValue.value = dateTime; SetValue setValue = new SetValue(); setValue.values = new Value[] { dateTimeValue }; List<object> value = PqlUtilities.GetValue(setValue) as List<object>; Assert.AreEqual(1, value.Count); Assert.True(value.Contains(dateTime)); }