public DateTime Base(DateTime timestamp) { switch (PeriodType) { case PeriodType.Millisecond: case PeriodType.Second: case PeriodType.Minute: case PeriodType.Hour: case PeriodType.Day: case PeriodType.Week: { return(new DateTime(timestamp.Ticks - timestamp.Ticks % periodInTicks)); } case PeriodType.Month: { int months = 12 * (timestamp.Year - 1) + timestamp.Month - 1; months = months - months % Duration; int year = 1 + months / 12; int month = 1 + months % 12; return(new DateTime(year, month, 1)); } case PeriodType.Year: { int year = timestamp.Year; return(new DateTime(year - year % Duration, 1, 1)); } default: throw new NotSupportedException(PeriodType.ToString()); } }
/// <summary> /// Statistics of issued and received invoices for given period of time. /// </summary> /// <param name="periodType">Type of time period.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns><see cref="ApiResult{TData}"/> instance containing <see cref="InvoicingForPeriodGetModel"/>.</returns> public Task <ApiResult <InvoicingForPeriodGetModel> > InvoicingForPeriodAsync(PeriodType periodType, CancellationToken cancellationToken = default) { var queryParams = new Dictionary <string, string> { { nameof(PeriodType), periodType.ToString() } }; return(GetAsync <InvoicingForPeriodGetModel>($"{ResourceUrl}/InvoicingForPeriod", queryParams, cancellationToken)); }
/// <summary> /// Statistics of issued and received invoices for given period of time. /// </summary> /// <param name="periodType">Type of time period.</param> /// <returns><see cref="ApiResult{TData}"/> instance containing <see cref="InvoicingForPeriodGetModel"/>.</returns> public ApiResult <InvoicingForPeriodGetModel> InvoicingForPeriod(PeriodType periodType) { var queryParams = new Dictionary <string, string> { { nameof(PeriodType), periodType.ToString() } }; return(Get <InvoicingForPeriodGetModel>($"{ResourceUrl}/InvoicingForPeriod", queryParams)); }
private static string MakeGetVideosUrl( string url, DateTimeOffset startedAt, DateTimeOffset endedAt, string after, string before, PeriodType period, SortType sort, VideoType type, int first) { bool isStartedAtNull = startedAt == null; bool isEndedAtNull = endedAt == null; if (!isStartedAtNull && !isEndedAtNull && startedAt < endedAt) { url += string.Format( "&started_at={0}&ended_at={1}", startedAt.ToRfc3339(), endedAt.ToRfc3339() ); } bool isAfterNull = after == null; bool isBeforeNull = before == null; if (isAfterNull != isBeforeNull) { if (!isAfterNull) { url += string.Format("&after={0}", after); } if (!isBeforeNull) { url += string.Format("&before={0}", before); } } url += string.Format("&period={0}", period.ToString().ToLower()); url += string.Format("&sort={0}", sort.ToString().ToLower()); url += string.Format("&type={0}", type.ToString().ToLower()); url += string.Format("&first={0}", first); return(url); }
public override string ToString() => PeriodCount.ToString() + PeriodType.ToString();
public static string GetData(string stock, string exchange, Interval interval, PeriodType periodType, int period, DateTime?startTime = null) { if (startTime == null) { startTime = DateTime.Today; } var client = new WebClient(); return(client.DownloadString(String.Format("http://www.google.com/finance/getprices?q={0}&x={1}&i={2}&p={3}{4}&f=d,c,v,k,o,h,l&df=cpct&auto=0&ts={5}&ei=Ef6XUYDfCqSTiAKEMg", stock, exchange, (int)interval, period, periodType.ToString(), startTime.Value.ToUnix()))); }