protected override DriverResult Editor(CommonPart part, IUpdateModel updater, dynamic shapeHelper) { var settings = part.TypePartDefinition.Settings.GetModel <DateEditorSettings>(); if (!settings.ShowDateEditor) { return(null); } return(ContentShape( "Parts_Common_Date_Edit", () => { DateEditorViewModel model = shapeHelper.Parts_Common_Date_Edit(typeof(DateEditorViewModel)); if (part.CreatedUtc != null) { // show CreatedUtc only if is has been "touched", // i.e. it has been published once, or CreatedUtc has been set var itemHasNeverBeenPublished = part.PublishedUtc == null; var thisIsTheInitialVersionRecord = part.ContentItem.Version < 2; var theDatesHaveNotBeenModified = part.CreatedUtc == part.VersionCreatedUtc; var theEditorShouldBeBlank = itemHasNeverBeenPublished && thisIsTheInitialVersionRecord && theDatesHaveNotBeenModified; if (theEditorShouldBeBlank == false) { // date and time are formatted using the same patterns as DateTimePicker is, preventing other cultures issues var createdLocal = TimeZoneInfo.ConvertTimeFromUtc(part.CreatedUtc.Value, Services.WorkContext.CurrentTimeZone); model.CreatedDate = createdLocal.ToString("d", _cultureInfo.Value); model.CreatedTime = createdLocal.ToString("t", _cultureInfo.Value); } } if (updater != null) { updater.TryUpdateModel(model, Prefix, null, null); if (!string.IsNullOrWhiteSpace(model.CreatedDate) && !string.IsNullOrWhiteSpace(model.CreatedTime)) { DateTime createdUtc; string parseDateTime = String.Concat(model.CreatedDate, " ", model.CreatedTime); // use current culture if (DateTime.TryParse(parseDateTime, _cultureInfo.Value, DateTimeStyles.None, out createdUtc)) { // the date time is entered locally for the configured timezone part.CreatedUtc = TimeZoneInfo.ConvertTimeToUtc(createdUtc, Services.WorkContext.CurrentTimeZone); } else { updater.AddModelError(Prefix, T("{0} is an invalid date and time", parseDateTime)); } } else if (!string.IsNullOrWhiteSpace(model.CreatedDate) || !string.IsNullOrWhiteSpace(model.CreatedTime)) { // only one part is specified updater.AddModelError(Prefix, T("Both the date and time need to be specified.")); } // none date/time part is specified => do nothing } return model; })); }
public static long GetRelativeSeconds(DateTime d) { return((long)TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).Subtract(d).TotalSeconds); }
/// <summary> /// Calculates the first time an <see cref="NthIncludedDayTrigger" /> with /// <c>intervalType = IntervalTypeWeekly</c> will fire /// after the specified date. See <see cref="GetNextFireTimeUtc" /> for more /// information. /// </summary> /// <param name="afterDateUtc">The time after which to find the nearest fire time. /// This argument is treated as exclusive 舒 that is, /// if afterTime is a valid fire time for the trigger, it /// will not be returned as the next fire time. /// </param> /// <returns> the first time the trigger will fire following the specified /// date /// </returns> private NullableDateTime GetWeeklyFireTimeAfter(DateTime afterDateUtc) { var currN = 0; int currWeek; var weekCount = 0; var gotOne = false; #if !NET_35 afterDateUtc = TimeZone.ToLocalTime(afterDateUtc); #else afterDateUtc = TimeZoneInfo.ConvertTimeFromUtc(afterDateUtc, TimeZone); #endif var currCal = new DateTime(afterDateUtc.Year, afterDateUtc.Month, afterDateUtc.Day); // move to the first day of the week // TODO, we are still bound to fixed local time zone as with TimeZone property while (currCal.DayOfWeek != DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek) { currCal = currCal.AddDays(-1); } currCal = new DateTime(currCal.Year, currCal.Month, currCal.Day, fireAtHour, fireAtMinute, fireAtSecond, 0); currWeek = GetWeekOfYear(currCal); while ((!gotOne) && (weekCount < nextFireCutoffInterval)) { while ((currN != n) && (weekCount < 12)) { //if we move into a new week, reset the current "n" counter if (GetWeekOfYear(currCal) != currWeek) { currN = 0; weekCount++; currWeek = GetWeekOfYear(currCal); } //treating a null calendar as an all-inclusive calendar, // increment currN if the current date being tested is included // on the calendar if ((calendar == null) || calendar.IsTimeIncluded(currCal)) { currN++; } if (currN != n) { currCal = currCal.AddDays(1); } //if we pass endTime, drop out and return null. #if !NET_35 if (EndTimeUtc.HasValue && TimeZone.ToUniversalTime(currCal) > EndTimeUtc.Value) #else if (EndTimeUtc.HasValue && TimeZoneInfo.ConvertTimeToUtc(currCal, TimeZone) > EndTimeUtc.Value) #endif { return(null); } } // We found an "n" or we've checked the requisite number of weeks. // If we've found an "n", is it the right one? -- that is, we could // be looking at an nth day PRIOR to afterDateUtc if (currN == n) { #if !NET_35 if (afterDateUtc < TimeZone.ToUniversalTime(currCal)) #else if (afterDateUtc < TimeZoneInfo.ConvertTimeToUtc(currCal, TimeZone)) #endif { gotOne = true; } else { // resume checking on the first day of the next week // move back to the beginning of the week and add 7 days // TODO, need to correlate with time zone in .NET 3.5 while (currCal.DayOfWeek != DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek) { currCal = currCal.AddDays(-1); } currCal = currCal.AddDays(7); currN = 0; } } } if (weekCount < nextFireCutoffInterval) { #if !NET_35 return(TimeZone.ToUniversalTime(currCal)); #else return(TimeZoneInfo.ConvertTimeToUtc(currCal, TimeZone)); #endif } else { return(null); } }
public StringToTimeCase(string str, int locMonth, int locDay, int locYear, TimeZoneInfo zone, string result, TimeZoneInfo[] zones) : this(str, DateTimeUtils.UtcToUnixTimeStamp(TimeZoneInfo.ConvertTimeToUtc(new DateTime(locYear, locMonth, locDay), zone)), result, zones) { }
private int GetNowSeconds() { return((int)(TimeZoneInfo.ConvertTimeToUtc(DateTime.UtcNow) - new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc)).TotalSeconds); }
/// <summary> /// Converts the date and time to Coordinated Universal Time (UTC) /// </summary> /// <param name="dt">The date and time (respesents local system time or UTC time) to convert.</param> /// <param name="sourceDateTimeKind">The source datetimekind</param> /// <returns>A DateTime value that represents the Coordinated Universal Time (UTC) that corresponds to the dateTime parameter. The DateTime value's Kind property is always set to DateTimeKind.Utc.</returns> public virtual DateTime ConvertToUtcTime(DateTime dt, DateTimeKind sourceDateTimeKind) { dt = DateTime.SpecifyKind(dt, sourceDateTimeKind); return(TimeZoneInfo.ConvertTimeToUtc(dt)); }
public static void TimeZoneDemo() { Console.WriteLine("DateTime.UtcNow.ToString(\"o\") demo"); string timeStringO = DateTime.UtcNow.ToString("o"); Console.WriteLine($"UtcNow.ToString(\"o\"): {timeStringO}"); // Note: // When we parse the time string contains TimeZoneInfo(generate from ToString("o")), // it will return the dateTime based on the local timeZone. // The ToString result of DateTime.UtcNow ends with "Z" DateTime timeParseO = DateTime.Parse(timeStringO); Console.WriteLine($"DateTime.Parse().ToString(\"o\"): {timeParseO:o}"); Console.WriteLine(); Console.WriteLine("DateTime.Now.ToString(\"o\") demo"); timeStringO = DateTime.Now.ToString("o"); // The ToString result of DateTime.Now ends with "+08:00" Console.WriteLine($"Now.ToString(\"o\"): {timeStringO}"); timeParseO = DateTime.Parse(timeStringO); Console.WriteLine($"DateTime.Parse().ToString(\"o\"): {timeParseO:o}"); Console.WriteLine(); Console.WriteLine("DateTime.UtcNo.ToString(\"s\") demo"); string timeStringS = DateTime.UtcNow.ToString("s"); Console.WriteLine($"UtcNow.ToString(\"s\"): {timeStringS}"); // DateTime.UtcNow.ToString("s") does not contains TimeZoneInfo, // so parse functio can return the same value with the source DateTime but without timeZone info // Actually it has been different from the source dateTime if we use ToUniversalTime() function to convert it to UniversalTime(By default with local TimeZone if not contains TimeZone info) DateTime timeParseS = DateTime.Parse(timeStringS); Console.WriteLine($"DateTime.Parse().ToString(\"o\"): {timeParseS:o}"); Console.WriteLine($"DateTime.Parse().ToUniversalTime().ToString(\"o\"): {timeParseS.ToUniversalTime():o}"); Console.WriteLine(); // We can use function TimeZoneInfo.ConvertTimeToUtc or ToUniversalTime() to convert the DateTime with local TimeZone info or without TimeZone info to UniversalTime() Console.WriteLine("ToUniversalTime() demo"); Console.WriteLine($"UtcNow.ToString(\"s\"): {timeStringS}"); Console.WriteLine($"DateTime.Parse().ToString(\"o\"): {timeParseS:o}"); Console.WriteLine($"DateTime.Parse().ToUniversalTime().ToString(\"o\"): {timeParseS.ToUniversalTime():o}"); Console.WriteLine($"TimeZoneInfo.ConvertTimeToUtc(DateTime.Parse()).ToString(\"o\"): {TimeZoneInfo.ConvertTimeToUtc(timeParseS):o}"); Console.WriteLine(); Console.WriteLine("DateTime.UtcNo.ToString(\"s\") append 'Z' demo"); // You can just append a letter 'Z' to set the TimeZoneInfo Zulu Time Zone for the date string without TimeZoneInfo // And this operation won't change the TimeZoneInfo for the date string with TimeZoneInfo string timeStringSEndZ = timeStringS + "Z"; DateTime timeParseSEndZ = DateTime.Parse(timeStringSEndZ).ToUniversalTime(); Console.WriteLine($"UtcNow.ToString(\"s\") + \"Z\": {timeStringSEndZ}"); Console.WriteLine($"DateTime.Parse().ToUniversalTime().ToString(\"o\"): {timeParseSEndZ:o}"); string timeStringSEndTimeZoneZ = timeStringS + "+08:00Z"; DateTime timeParseSEndTimeZoneZ = DateTime.Parse(timeStringSEndZ).ToUniversalTime(); Console.WriteLine($"UtcNow.ToString(\"s\") + \"Z\": {timeStringSEndTimeZoneZ}"); Console.WriteLine($"DateTime.Parse().ToUniversalTime().ToString(\"o\"): {timeParseSEndTimeZoneZ:o}"); Console.WriteLine(); string timeStringWithHourInfo = DateTime.UtcNow.ToString("yyyy-MM-dd") + "Z"; timeStringWithHourInfo = "2018-10-24 22:04:42Z"; DateTime timeParseWithHourInfo = DateTime.Parse(timeStringWithHourInfo).ToUniversalTime(); Console.WriteLine($"UtcNow.ToString(\"s\") + \"Z\": {timeStringWithHourInfo}"); Console.WriteLine($"DateTime.Parse().ToUniversalTime().ToString(\"o\"): {timeParseWithHourInfo:o}"); /* Note: * This kind of dateText "2018-10-24 22:04:42" cannot append time zone info. * Just this kind of dateText "2018-10-24T22:04:42" can append time zone info. * Just like this: * "2018-10-24T22:04:42Z" * "2018-10-24T22:04:42+8:00Z" */ try { Console.WriteLine(DateTime.Parse("08/18/2018 07:22:16-07:00Z").ToUniversalTime()); } catch (FormatException) { Console.WriteLine("FormatException"); Console.WriteLine(DateTime.Parse("2018-10-11T00:00:00Z").ToUniversalTime()); } Console.WriteLine(); Console.WriteLine(DateTime.Parse("2018-10-11T00:00:00Z").ToUniversalTime().ToString()); Console.WriteLine(DateTime.Parse("2018-10-11T00:00:00Z").ToString()); }
public static EventData Parse(string originEventSource, string currentFile, long eventId, TimeZoneInfo timeZone) { string bufferEventSource = String.Copy(originEventSource); FileInfo currentFileInfo = new FileInfo(currentFile); string dateFromFileAsString = currentFileInfo.Name.Replace(".log", string.Empty); int indexEndOfDate = bufferEventSource.IndexOf('-'); string periodAsString = bufferEventSource.Substring(0, indexEndOfDate); long periodMilliseconds = long.Parse(periodAsString.Substring(6, 3)); DateTime eventPeriod = new DateTime( 2000 + int.Parse(dateFromFileAsString.Substring(0, 2)), int.Parse(dateFromFileAsString.Substring(2, 2)), int.Parse(dateFromFileAsString.Substring(4, 2)), int.Parse(dateFromFileAsString.Substring(6, 2)), int.Parse(periodAsString.Substring(0, 2)), int.Parse(periodAsString.Substring(3, 2)) ).AddMilliseconds(periodMilliseconds); long periodMoment; bool isFormat83 = periodAsString.Length == 12; if (isFormat83) { periodMoment = long.Parse(periodAsString.Substring(6, 6)); } else { periodMoment = long.Parse(periodAsString.Substring(6, 4)) * 100; } int indexEndOfDuration = bufferEventSource.IndexOf(','); string durationAsString = bufferEventSource.Substring(indexEndOfDate + 1, indexEndOfDuration - indexEndOfDate - 1); long duration = long.Parse(durationAsString) * (isFormat83 ? 1 : 100); bufferEventSource = bufferEventSource.Substring(indexEndOfDuration + 1, bufferEventSource.Length - indexEndOfDuration - 1); int indexEndOfEventName = bufferEventSource.IndexOf(','); string eventName = bufferEventSource.Substring(0, indexEndOfEventName); string eventNameKey = eventName.ToUpper(); if (!_eventObjectTypes.TryGetValue(eventNameKey, out var eventObjectType)) { eventObjectType = typeof(EventData); } EventData dataRow = (EventData)Activator.CreateInstance(eventObjectType); dataRow.Id = eventId; dataRow.Period = eventPeriod; dataRow.PeriodUTC = TimeZoneInfo.ConvertTimeToUtc(dataRow.Period, timeZone ?? TimeZoneInfo.Local); dataRow.PeriodMoment = periodMoment; dataRow.Duration = duration; dataRow.EventName = eventName; bufferEventSource = bufferEventSource.Substring(indexEndOfEventName + 1, bufferEventSource.Length - indexEndOfEventName - 1); int indexEndOfLevel = bufferEventSource.IndexOf(','); dataRow.Level = int.Parse(bufferEventSource.Substring(0, indexEndOfLevel)); bufferEventSource = bufferEventSource.Substring(indexEndOfLevel + 1, bufferEventSource.Length - indexEndOfLevel - 1); int indexOfDelimiter = bufferEventSource.IndexOf("=", StringComparison.InvariantCulture); bufferEventSource = bufferEventSource.Replace("''", "¦"); bufferEventSource = bufferEventSource.Replace(@"""""", "÷"); while (indexOfDelimiter > 0) { string paramName = bufferEventSource .Substring(0, indexOfDelimiter) .ToUpper() .Trim(); string valueAsString = string.Empty; bufferEventSource = bufferEventSource.Substring(indexOfDelimiter + 1); if (!string.IsNullOrEmpty(bufferEventSource)) { if (bufferEventSource.Substring(0, 1) == "'") { bufferEventSource = bufferEventSource.Substring(1); indexOfDelimiter = bufferEventSource.IndexOf("'", StringComparison.InvariantCulture); if (indexOfDelimiter > 0) { valueAsString = bufferEventSource.Substring(0, indexOfDelimiter).Trim(); valueAsString = valueAsString.Replace("¦", "'"); } if (bufferEventSource.Length > indexOfDelimiter + 1) { bufferEventSource = bufferEventSource.Substring(indexOfDelimiter + 1 + 1); } else { bufferEventSource = string.Empty; } } else if (bufferEventSource.Substring(0, 1) == "\"") { bufferEventSource = bufferEventSource.Substring(1); indexOfDelimiter = bufferEventSource.IndexOf("\"", StringComparison.InvariantCulture); if (indexOfDelimiter > 0) { valueAsString = bufferEventSource.Substring(0, indexOfDelimiter).Trim(); valueAsString = valueAsString.Replace("÷", "\"\""); } if (bufferEventSource.Length > indexOfDelimiter + 1) { bufferEventSource = bufferEventSource.Substring(indexOfDelimiter + 1 + 1); } else { bufferEventSource = string.Empty; } } else { indexOfDelimiter = bufferEventSource.IndexOf(",", StringComparison.Ordinal); if (indexOfDelimiter > 0) { valueAsString = bufferEventSource.Substring(0, indexOfDelimiter).Trim(); } else { valueAsString = bufferEventSource; } if (bufferEventSource.Length > indexOfDelimiter) { bufferEventSource = bufferEventSource.Substring(indexOfDelimiter + 1); } else { bufferEventSource = string.Empty; } } } indexOfDelimiter = bufferEventSource.IndexOf("=", StringComparison.InvariantCulture); if (dataRow.Properties.ContainsKey(paramName)) { int countParamWithSameName = dataRow.Properties.Count(e => e.Key.StartsWith(paramName)); dataRow.Properties.Add($"{paramName}#{countParamWithSameName + 1}", valueAsString); } else { dataRow.Properties.Add(paramName, valueAsString); } } return(dataRow); }
public async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query) { TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 3, 5, DayOfWeek.Sunday); TimeZoneInfo.TransitionTime endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 4, 0, 0), 10, 5, DayOfWeek.Sunday); TimeSpan delta = new TimeSpan(1, 0, 0); TimeZoneInfo.AdjustmentRule adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1999, 10, 1), DateTime.MaxValue.Date, delta, startTransition, endTransition); TimeZoneInfo.AdjustmentRule[] adjustments = { adjustment }; TimeZoneInfo germanyTz = TimeZoneInfo.CreateCustomTimeZone("W. Europe Standard Time", new TimeSpan(1, 0, 0), "(GMT+01:00) W. Europe Standard Time", "W. Europe Standard Time", "W. Europe DST Time", adjustments); var releases = new List <ReleaseInfo>(); var searchString = query.GetQueryString(); var searchUrl = BrowseUrl; var queryCollection = new NameValueCollection(); queryCollection.Add("showsearch", "1"); queryCollection.Add("incldead", "1"); queryCollection.Add("orderby", "added"); queryCollection.Add("sort", "desc"); if (!string.IsNullOrWhiteSpace(searchString)) { queryCollection.Add("search", searchString); } foreach (var cat in MapTorznabCapsToTrackers(query)) { queryCollection.Add("c" + cat, "1"); } searchUrl += "?" + queryCollection.GetQueryString(); var response = await RequestBytesWithCookies(searchUrl); var results = Encoding.GetEncoding("iso-8859-1").GetString(response.Content); try { CQ dom = results; var rows = dom["table.tableinborder > tbody > tr:has(td.tableb)"]; foreach (var row in rows) { var release = new ReleaseInfo(); var qRow = row.Cq(); var qDetailsLink = qRow.Find("a[href^=details.php?id=]").First(); release.Title = qDetailsLink.Attr("title"); var qCatLink = qRow.Find("a[href^=browse.php?cat=]").First(); var qDLLink = qRow.Find("a[href^=download.php?torrent=]").First(); var qSeeders = qRow.Find("span:contains(Seeder) > b:eq(0)"); var qLeechers = qRow.Find("span:contains(Seeder) > b:eq(1)"); var qDateStr = qRow.Find("td > table > tbody > tr > td:eq(7)").First(); var qSize = qRow.Find("span:contains(Volumen) > b:eq(0)").First(); var qOnlyUpload = qRow.Find("img[title=OnlyUpload]"); if (qOnlyUpload.Any()) { release.MinimumRatio = 2; release.MinimumSeedTime = 144 * 60 * 60; } else { release.MinimumRatio = 1; release.MinimumSeedTime = 72 * 60 * 60; } var catStr = qCatLink.Attr("href").Split('=')[1]; release.Category = MapTrackerCatToNewznab(catStr); release.Link = new Uri(SiteLink + qDLLink.Attr("href")); release.Comments = new Uri(SiteLink + qDetailsLink.Attr("href")); release.Guid = release.Link; var sizeStr = qSize.Text(); release.Size = ReleaseInfo.GetBytes(sizeStr); release.Seeders = ParseUtil.CoerceInt(qSeeders.Text()); release.Peers = ParseUtil.CoerceInt(qLeechers.Text()) + release.Seeders; var dateStr = qDateStr.Text().Trim().Replace('\xA0', ' '); DateTime dateGerman = DateTime.SpecifyKind(DateTime.ParseExact(dateStr, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture), DateTimeKind.Unspecified); DateTime pubDateUtc = TimeZoneInfo.ConvertTimeToUtc(dateGerman, germanyTz); release.PublishDate = pubDateUtc.ToLocalTime(); releases.Add(release); } } catch (Exception ex) { OnParseError(results, ex); } return(releases); }
/// <summary> /// 时间戳转换为日期类型 /// 返回自1970以来的时间 /// </summary> /// <param name="timestamp">时间戳(1147763686)</param> /// <returns></returns> public static DateTime TimeStampToDate(uint timestamp) { return(TimeZoneInfo.ConvertTimeToUtc(DateTime.Now.AddSeconds(timestamp))); }
/// <summary> /// Converts the date and time to Coordinated Universal Time (UTC) /// </summary> /// <param name="dt">The date and time to convert.</param> /// <param name="sourceTimeZone">The time zone of dateTime.</param> /// <returns>A DateTime value that represents the Coordinated Universal Time (UTC) that corresponds to the dateTime parameter. The DateTime value's Kind property is always set to DateTimeKind.Utc.</returns> public static DateTime ConvertToUtcTime(DateTime dt, TimeZoneInfo sourceTimeZone) { return(TimeZoneInfo.ConvertTimeToUtc(dt, sourceTimeZone)); }
private DateTime ZoneTimeToUtc(DateTime zoneTime, string timeSpan) { var span = ParseTimeZone(timeSpan, out var tz); return(null != tz?TimeZoneInfo.ConvertTimeToUtc(zoneTime, tz) : zoneTime.AddTicks(-1 * span.Ticks)); }
public static void AdjustTimer(string userName) { string con = System.Configuration.ConfigurationManager.ConnectionStrings["emDatabaseNewLook"].ConnectionString; SqlConnection conn = new System.Data.SqlClient.SqlConnection(con); SqlCommand updateCmd = new SqlCommand("UPDATE Users " + "SET LastActivityDate = @LastActivityDate " + "WHERE UserName = @UserName", conn); // TimeZoneInfo.ConvertTimeToUtc(DateTime.Now) DateTime.UtcNow.AddMinutes(-10); updateCmd.Parameters.Add("@LastActivityDate", SqlDbType.DateTime).Value = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).AddMinutes(-10); updateCmd.Parameters.Add("@UserName", SqlDbType.VarChar, 255).Value = userName; //updateCmd.Parameters.Add("@ApplicationName", SqlDbType.VarChar, 255).Value = m_ApplicationName; conn.Open(); updateCmd.ExecuteNonQuery(); conn.Close(); }
/* * Method Name: OnCreate * Purpose: It is used for when the app is loading */ protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); _db = new Database.Database(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "ShareMyDay.db3"); _db.Create(); _db.Setup(); //scheduling time logic adapted from https://forums.xamarin.com/discussion/121773/scheduling-repeating-alarms var year = DateTime.Now.Year; var month = DateTime.Now.Month; var day = DateTime.Now.Day; DateTime deleteStoriesTime = new DateTime(year, month, day, 08, 01, 30); if (DateTime.Now > deleteStoriesTime) { deleteStoriesTime = deleteStoriesTime.AddDays(1); } DateTime deleteStoriesUtcTime = TimeZoneInfo.ConvertTimeToUtc(deleteStoriesTime); double epochDate = (new DateTime(1970, 1, 1) - DateTime.MinValue).TotalSeconds; long deleteTime = deleteStoriesUtcTime.AddSeconds(-epochDate).Ticks / 10000; var deleteIntent = new Intent(this, typeof(DeleteStoriesReceiver)); var deletePendingIntent = PendingIntent.GetBroadcast(this, 0, deleteIntent, PendingIntentFlags.UpdateCurrent); var deleteAlertManager = (AlarmManager)GetSystemService(AlarmService); deleteAlertManager.SetInexactRepeating(AlarmType.RtcWakeup, deleteTime, AlarmManager.IntervalDay, deletePendingIntent); DateTime generateStoriesTime = new DateTime(year, month, day, 15, 01, 30); if (DateTime.Now > generateStoriesTime) { generateStoriesTime = generateStoriesTime.AddDays(1); } DateTime generateStoriesUtcTime = TimeZoneInfo.ConvertTimeToUtc(generateStoriesTime); long notifyTimeInInMilliseconds = generateStoriesUtcTime.AddSeconds(-epochDate).Ticks / 10000; var generateIntent = new Intent(this, typeof(StoryGenerationReceiver)); var generatePendingIntent = PendingIntent.GetBroadcast(this, 0, generateIntent, PendingIntentFlags.UpdateCurrent); var generateAlertManager = (AlarmManager)GetSystemService(AlarmService); generateAlertManager.SetInexactRepeating(AlarmType.RtcWakeup, notifyTimeInInMilliseconds, AlarmManager.IntervalDay, generatePendingIntent); _nfc = new NFC.NFC(this); Button todayStory = FindViewById <Button>(Resource.Id.latestStoryButton); Button favouriteStory = FindViewById <Button>(Resource.Id.favouriteStoryButton); todayStory.SetBackgroundResource(Resource.Drawable.TodayStoryButton); todayStory.Click += delegate { todayStory.SetBackgroundResource(Resource.Drawable.TodayStoryButtonPressed); Intent storyIntent = new Intent(this, typeof(TodayStoryActivity)); StartActivity(storyIntent); }; favouriteStory.Click += delegate { favouriteStory.SetBackgroundResource(Resource.Drawable.FaveButtonPressed); Intent storyIntent = new Intent(this, typeof(StoryActivity)); storyIntent.PutExtra("Story", "Favourite"); StartActivity(storyIntent); }; }
/// <summary> /// Uses the TimeZoneInfo for conversion, which will throw on historically invalid DateTimes. /// </summary> /// <param name="dateTime"></param> /// <returns></returns> // ReSharper disable once InconsistentNaming public static DateTime RobustToUTC(this DateTime dateTime) { // See: https://stackoverflow.com/questions/1704780/what-is-the-difference-between-datetime-touniversaltime-and-timezoneinfo-convert return(TimeZoneInfo.ConvertTimeToUtc(dateTime)); }
/// <summary> /// Converter data em padrao timestamp (modo Fluent) /// </summary> public static double toUnixTimestamp(this DateTime dateTime) { return((TimeZoneInfo.ConvertTimeToUtc(dateTime) - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds); }
/// <summary> /// Initializes a new instance of the <see cref="QuantConnect.Time.DateTimeWithZone"/> struct. /// </summary> /// <param name="dateTime">Date time.</param> /// <param name="timeZone">Time zone.</param> public DateTimeWithZone(DateTime dateTime, TimeZoneInfo timeZone) { utcDateTime = TimeZoneInfo.ConvertTimeToUtc(dateTime, timeZone); this.timeZone = timeZone; }
public static DateTime ToUTCDateTime(this DateTime localDateTime, string timeZone) { TimeZoneInfo SiteLocalTime = TimeZoneInfo.FindSystemTimeZoneById(timeZone); return(TimeZoneInfo.ConvertTimeToUtc(localDateTime, SiteLocalTime)); }
protected async Task DigestCalendarLuisResult(DialogContext dc, Calendar luisResult, bool isBeginDialog) { try { var state = await Accessor.GetAsync(dc.Context); var entity = luisResult.Entities; if (entity.ordinal != null) { try { var eventList = state.SummaryEvents; var value = entity.ordinal[0]; var num = int.Parse(value.ToString()); if (eventList != null && num > 0) { var currentList = eventList.GetRange(0, Math.Min(CalendarSkillState.PageSize, eventList.Count)); if (num <= currentList.Count) { state.ReadOutEvents.Clear(); state.ReadOutEvents.Add(currentList[num - 1]); } } } catch { // ignored } } if (entity.number != null && entity.ordinal != null && entity.ordinal.Length == 0) { try { var eventList = state.SummaryEvents; var value = entity.ordinal[0]; var num = int.Parse(value.ToString()); if (eventList != null && num > 0) { var currentList = eventList.GetRange(0, Math.Min(CalendarSkillState.PageSize, eventList.Count)); if (num <= currentList.Count) { state.ReadOutEvents.Clear(); state.ReadOutEvents.Add(currentList[num - 1]); } } } catch { // ignored } } if (!isBeginDialog) { return; } if (entity.Subject != null) { state.Title = entity.Subject[0]; } if (entity.ContactName != null) { foreach (var name in entity.ContactName) { if (!state.AttendeesNameList.Contains(name)) { state.AttendeesNameList.Add(name); } } } if (entity.Duration != null) { foreach (var datetimeItem in entity.datetime) { if (datetimeItem.Type == "duration") { var culture = dc.Context.Activity.Locale ?? English; List <DateTimeResolution> result = RecognizeDateTime(entity.Duration[0], culture); if (result != null) { if (result[0].Value != null) { state.Duration = int.Parse(result[0].Value); } } break; } } } if (entity.MeetingRoom != null) { state.Location = entity.MeetingRoom[0]; } if (entity.Location != null) { state.Location = entity.Location[0]; } if (entity.StartDate != null) { var culture = dc.Context.Activity.Locale ?? English; List <DateTimeResolution> results = RecognizeDateTime(entity.StartDate[0], culture); if (results != null) { var result = results[results.Count - 1]; if (result.Value != null) { var dateTime = DateTime.Parse(result.Value); var dateTimeConvertType = result.Timex; if (dateTime != null) { bool isRelativeTime = IsRelativeTime(entity.StartDate[0], result.Value, result.Timex); state.StartDate = isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTime; } } } } if (entity.StartTime != null) { var culture = dc.Context.Activity.Locale ?? English; List <DateTimeResolution> result = RecognizeDateTime(entity.StartTime[0], culture); if (result != null) { if (result[0].Value != null) { var dateTime = DateTime.Parse(result[0].Value); var dateTimeConvertType = result[0].Timex; if (dateTime != null) { bool isRelativeTime = IsRelativeTime(entity.StartTime[0], result[0].Value, result[0].Timex); state.StartTime = isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTime; } } else { var startTime = DateTime.Parse(result[0].Start); var endTime = DateTime.Parse(result[0].End); state.StartTime = startTime; state.EndTime = endTime; } } } if (entity.EndDate != null) { var culture = dc.Context.Activity.Locale ?? English; List <DateTimeResolution> results = RecognizeDateTime(entity.EndDate[0], culture); if (results != null) { var result = results[results.Count - 1]; if (result.Value != null) { var dateTime = DateTime.Parse(result.Value); var dateTimeConvertType = result.Timex; if (dateTime != null) { bool isRelativeTime = IsRelativeTime(entity.EndDate[0], result.Value, result.Timex); state.EndDate = isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTime; } } } } if (entity.EndTime != null) { var culture = dc.Context.Activity.Locale ?? English; List <DateTimeResolution> result = RecognizeDateTime(entity.EndTime[0], culture); if (result != null && result[0].Value != null) { var dateTime = DateTime.Parse(result[0].Value); var dateTimeConvertType = result[0].Timex; if (dateTime != null) { bool isRelativeTime = IsRelativeTime(entity.EndTime[0], result[0].Value, result[0].Timex); state.EndTime = isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTime; } } } if (entity.OriginalStartDate != null) { var culture = dc.Context.Activity.Locale ?? English; List <DateTimeResolution> results = RecognizeDateTime(entity.OriginalStartDate[0], culture); if (results != null) { var result = results[results.Count - 1]; if (result.Value != null) { var dateTime = DateTime.Parse(result.Value); var dateTimeConvertType = result.Timex; if (dateTime != null) { bool isRelativeTime = IsRelativeTime(entity.OriginalStartDate[0], result.Value, result.Timex); state.OriginalStartDate = isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTime; } } } } if (entity.OriginalStartTime != null) { var culture = dc.Context.Activity.Locale ?? English; List <DateTimeResolution> result = RecognizeDateTime(entity.OriginalStartTime[0], culture); if (result != null) { if (result[0].Value != null) { var dateTime = DateTime.Parse(result[0].Value); var dateTimeConvertType = result[0].Timex; if (dateTime != null) { bool isRelativeTime = IsRelativeTime(entity.OriginalStartTime[0], result[0].Value, result[0].Timex); state.OriginalStartTime = isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTime; } } else { var startTime = DateTime.Parse(result[0].Start); var endTime = DateTime.Parse(result[0].End); state.OriginalStartTime = startTime; state.OriginalEndTime = endTime; } } } if (entity.OriginalEndDate != null) { var culture = dc.Context.Activity.Locale ?? English; List <DateTimeResolution> results = RecognizeDateTime(entity.OriginalEndDate[0], culture); if (results != null) { var result = results[results.Count - 1]; if (result.Value != null) { var dateTime = DateTime.Parse(result.Value); var dateTimeConvertType = result.Timex; if (dateTime != null) { bool isRelativeTime = IsRelativeTime(entity.OriginalEndDate[0], result.Value, result.Timex); state.OriginalEndDate = isRelativeTime ? TimeZoneInfo.ConvertTime(dateTime, TimeZoneInfo.Local, state.GetUserTimeZone()) : dateTime; } } } } if (entity.OriginalEndTime != null) { var culture = dc.Context.Activity.Locale ?? English; List <DateTimeResolution> result = RecognizeDateTime(entity.OriginalEndTime[0], culture); if (result != null && result[0].Value != null) { var dateTime = DateTime.Parse(result[0].Value); var dateTimeConvertType = result[0].Timex; if (dateTime != null) { bool isRelativeTime = IsRelativeTime(entity.OriginalEndTime[0], result[0].Value, result[0].Timex); state.OriginalEndTime = isRelativeTime ? TimeZoneInfo.ConvertTimeToUtc(dateTime, TimeZoneInfo.Local) : TimeConverter.ConvertLuisLocalToUtc(dateTime, state.GetUserTimeZone()); } } } } catch { // put log here } }
protected override async Task <IEnumerable <ReleaseInfo> > PerformQuery(TorznabQuery query) { TimeZoneInfo.TransitionTime startTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 3, 0, 0), 3, 5, DayOfWeek.Sunday); TimeZoneInfo.TransitionTime endTransition = TimeZoneInfo.TransitionTime.CreateFloatingDateRule(new DateTime(1, 1, 1, 4, 0, 0), 10, 5, DayOfWeek.Sunday); TimeSpan delta = new TimeSpan(1, 0, 0); TimeZoneInfo.AdjustmentRule adjustment = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(new DateTime(1999, 10, 1), DateTime.MaxValue.Date, delta, startTransition, endTransition); TimeZoneInfo.AdjustmentRule[] adjustments = { adjustment }; TimeZoneInfo Tz = TimeZoneInfo.CreateCustomTimeZone("custom", new TimeSpan(1, 0, 0), "custom", "custom", "custom", adjustments); var releases = new List <ReleaseInfo>(); NameValueCollection qParams = new NameValueCollection(); qParams.Add("api", ""); if (query.ImdbIDShort != null) { qParams.Add("imdb", query.ImdbIDShort); } else { qParams.Add("search", query.SearchTerm); } foreach (var cat in MapTorznabCapsToTrackers(query)) { qParams.Add("categories[" + cat + "]", "1"); } string urlSearch = SearchUrl; urlSearch += "?" + qParams.GetQueryString(); var response = await RequestStringWithCookiesAndRetry(urlSearch); if (response.IsRedirect) { throw new Exception("not logged in"); } try { var jsonContent = JArray.Parse(response.Content); var sitelink = new Uri(SiteLink); foreach (var item in jsonContent) { var release = new ReleaseInfo(); var id = item.Value <long>("id"); release.Title = item.Value <string>("name"); var imdbid = item.Value <string>("imdbid"); if (!string.IsNullOrEmpty(imdbid)) { release.Imdb = long.Parse(imdbid); } var category = item.Value <string>("category"); release.Category = MapTrackerCatToNewznab(category); release.Link = new Uri(sitelink, "/download.php?id=" + id); release.Comments = new Uri(sitelink, "/details.php?id=" + id); release.Guid = release.Comments; var dateStr = item.Value <string>("added"); var dateTime = DateTime.SpecifyKind(DateTime.ParseExact(dateStr, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture), DateTimeKind.Unspecified); var pubDateUtc = TimeZoneInfo.ConvertTimeToUtc(dateTime, Tz); release.PublishDate = pubDateUtc; release.Grabs = item.Value <long>("times_completed"); release.Files = item.Value <long>("numfiles"); release.Seeders = item.Value <int>("seeders"); release.Peers = item.Value <int>("leechers") + release.Seeders; var size = item.Value <string>("size"); release.Size = ReleaseInfo.GetBytes(size); var is_freeleech = item.Value <int>("is_freeleech"); if (is_freeleech == 1) { release.DownloadVolumeFactor = 0; } else { release.DownloadVolumeFactor = 1; } release.UploadVolumeFactor = 1; releases.Add(release); } } catch (Exception ex) { OnParseError(response.Content, ex); } return(releases); }
/// <summary> /// Returns the Unix Timestamp of the given DateTime /// </summary> /// <param name="dateTime">The DateTime to convert</param> /// <returns>The Unix Timestamp</returns> public static long DateTimeToUnixTimestamp(DateTime dateTime) { return((long)(TimeZoneInfo.ConvertTimeToUtc(dateTime) - new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc)).TotalSeconds); }
private void ConvertToUtc() { // <Snippet1> DateTime datNowLocal = DateTime.Now; Console.WriteLine("Converting {0}, Kind {1}:", datNowLocal, datNowLocal.Kind); Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNowLocal), TimeZoneInfo.ConvertTimeToUtc(datNowLocal).Kind); Console.WriteLine(); DateTime datNowUtc = DateTime.UtcNow; Console.WriteLine("Converting {0}, Kind {1}", datNowUtc, datNowUtc.Kind); Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNowUtc), TimeZoneInfo.ConvertTimeToUtc(datNowUtc).Kind); Console.WriteLine(); DateTime datNow = new DateTime(2007, 10, 26, 13, 32, 00); Console.WriteLine("Converting {0}, Kind {1}", datNow, datNow.Kind); Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNow), TimeZoneInfo.ConvertTimeToUtc(datNow).Kind); Console.WriteLine(); DateTime datAmbiguous = new DateTime(2007, 11, 4, 1, 30, 00); Console.WriteLine("Converting {0}, Kind {1}, Ambiguous {2}", datAmbiguous, datAmbiguous.Kind, TimeZoneInfo.Local.IsAmbiguousTime(datAmbiguous)); Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datAmbiguous), TimeZoneInfo.ConvertTimeToUtc(datAmbiguous).Kind); Console.WriteLine(); DateTime datInvalid = new DateTime(2007, 3, 11, 02, 30, 00); Console.WriteLine("Converting {0}, Kind {1}, Invalid {2}", datInvalid, datInvalid.Kind, TimeZoneInfo.Local.IsInvalidTime(datInvalid)); try { Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datInvalid), TimeZoneInfo.ConvertTimeToUtc(datInvalid).Kind); } catch (ArgumentException e) { Console.WriteLine(" {0}: Cannot convert {1} to UTC.", e.GetType().Name, datInvalid); } Console.WriteLine(); DateTime datNearMax = new DateTime(9999, 12, 31, 22, 00, 00); Console.WriteLine("Converting {0}, Kind {1}", datNearMax, datNearMax.Kind); Console.WriteLine(" ConvertTimeToUtc: {0}, Kind {1}", TimeZoneInfo.ConvertTimeToUtc(datNearMax), TimeZoneInfo.ConvertTimeToUtc(datNearMax).Kind); Console.WriteLine(); // // This example produces the following output if the local time zone // is Pacific Standard Time: // // Converting 8/31/2007 2:26:28 PM, Kind Local: // ConvertTimeToUtc: 8/31/2007 9:26:28 PM, Kind Utc // // Converting 8/31/2007 9:26:28 PM, Kind Utc // ConvertTimeToUtc: 8/31/2007 9:26:28 PM, Kind Utc // // Converting 10/26/2007 1:32:00 PM, Kind Unspecified // ConvertTimeToUtc: 10/26/2007 8:32:00 PM, Kind Utc // // Converting 11/4/2007 1:30:00 AM, Kind Unspecified, Ambiguous True // ConvertTimeToUtc: 11/4/2007 9:30:00 AM, Kind Utc // // Converting 3/11/2007 2:30:00 AM, Kind Unspecified, Invalid True // ArgumentException: Cannot convert 3/11/2007 2:30:00 AM to UTC. // // Converting 12/31/9999 10:00:00 PM, Kind Unspecified // ConvertTimeToUtc: 12/31/9999 11:59:59 PM, Kind Utc // // </Snippet1> }
public StringToTimeCase(string str, DateTime local, TimeZoneInfo zone, string result, TimeZoneInfo[] zones) : this(str, DateTimeUtils.UtcToUnixTimeStamp(TimeZoneInfo.ConvertTimeToUtc(local, zone)), result, zones) { }
} // ChangeMD5 method private double DateTimeToUnixTimestamp(DateTime dateTime) { return((TimeZoneInfo.ConvertTimeToUtc(dateTime) - new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc)).TotalMilliseconds); }
public void ConvertLocalToUtc() { TimeZoneInfo.ConvertTimeToUtc(SummerUnspecified, PacificZone); }
public static uint ToEpoch(this DateTime d) { return(Convert.ToUInt32(((DateTimeOffset)TimeZoneInfo.ConvertTimeToUtc(d)).ToUnixTimeSeconds())); }
public static DateTime ToUtcTime(DateTime local) { return(TimeZoneInfo.ConvertTimeToUtc(local, tzi)); }
/// <summary> /// Converts the time in a specified time zone to Coordinated Universal Time (UTC). /// </summary> /// <param name="dateTime">The date and time to convert.</param> /// <param name="sourceTimeZone">The time zone of .</param> /// <returns> /// The Coordinated Universal Time (UTC) that corresponds to the parameter. The object's property is /// always set to . /// </returns> public static DateTime ConvertTimeToUtc(this DateTime dateTime, TimeZoneInfo sourceTimeZone) { return(TimeZoneInfo.ConvertTimeToUtc(dateTime, sourceTimeZone)); }
/// <summary> /// Calculates the first time an <see cref="NthIncludedDayTrigger" /> with /// intervalType = <see cref="IntervalTypeYearly" /> will fire /// after the specified date. See <see cref="GetNextFireTimeUtc" /> for more /// information. /// </summary> /// <param name="afterDateUtc"> /// The UTC time after which to find the nearest fire time. /// This argument is treated as exclusive 舒 that is, /// if afterTime is a valid fire time for the trigger, it /// will not be returned as the next fire time. /// </param> /// <returns> the first time the trigger will fire following the specified /// date /// </returns> private NullableDateTime GetYearlyFireTimeAfter(DateTime afterDateUtc) { var currN = 0; #if !NET_35 DateTime currCal = TimeZone.ToLocalTime(afterDateUtc); #else var currCal = TimeZoneInfo.ConvertTimeFromUtc(afterDateUtc, TimeZone); #endif currCal = new DateTime(currCal.Year, 1, 1, fireAtHour, fireAtMinute, fireAtSecond, 0); int currYear; var yearCount = 0; var gotOne = false; currYear = currCal.Year; while ((!gotOne) && (yearCount < nextFireCutoffInterval)) { while ((currN != n) && (yearCount < 5)) { //if we move into a new year, reset the current "n" counter if (currCal.Year != currYear) { currN = 0; yearCount++; currYear = currCal.Year; } //treating a null calendar as an all-inclusive calendar, // increment currN if the current date being tested is included // on the calendar if (calendar == null || calendar.IsTimeIncluded(currCal)) { currN++; } if (currN != n) { currCal = currCal.AddDays(1); } //if we pass endTime, drop out and return null. #if !NET_35 if (EndTimeUtc.HasValue && TimeZone.ToUniversalTime(currCal) > EndTimeUtc.Value) #else if (EndTimeUtc.HasValue && TimeZoneInfo.ConvertTimeToUtc(currCal, TimeZone) > EndTimeUtc.Value) #endif { return(null); } } //We found an "n" or we've checked the requisite number of years. // If we've found an "n", is it the right one? -- that is, we // could be looking at an nth day PRIOR to afterDateUtc if (currN == n) { #if !NET_35 if (afterDateUtc < TimeZone.ToUniversalTime(currCal)) #else if (afterDateUtc < TimeZoneInfo.ConvertTimeToUtc(currCal, TimeZone)) #endif { gotOne = true; } else { //resume checking on the first day of the next year currCal = new DateTime(currCal.Year + 1, 1, 1, currCal.Hour, currCal.Minute, currCal.Second); currN = 0; } } } if (yearCount < nextFireCutoffInterval) { #if !NET_35 return(TimeZone.ToUniversalTime(currCal)); #else return(TimeZoneInfo.ConvertTimeToUtc(currCal, TimeZone)); #endif } else { return(null); } }
private static void processPrograms(XmlWriter xmlWriter) { int programNumber = 1; foreach (TVStation station in TVStation.StationCollection) { if (!station.Excluded) { foreach (EPGEntry epgEntry in station.EPGCollection) { xmlWriter.WriteStartElement("Program"); xmlWriter.WriteAttributeString("id", "prg" + programNumber); xmlWriter.WriteAttributeString("uid", "!Program!" + (epgEntry.OriginalNetworkID + ":" + epgEntry.TransportStreamID + ":" + epgEntry.ServiceID + TimeZoneInfo.ConvertTimeToUtc(epgEntry.StartTime).ToString()).Replace(" ", "").Replace(":", "").Replace("/", "").Replace(".", "")); xmlWriter.WriteAttributeString("title", epgEntry.EventName); xmlWriter.WriteAttributeString("description", epgEntry.ShortDescription); if (epgEntry.EventSubTitle != null) { xmlWriter.WriteAttributeString("episodeTitle", epgEntry.EventSubTitle); } if (epgEntry.HasAdult) { xmlWriter.WriteAttributeString("hasAdult", "1"); } if (epgEntry.HasGraphicLanguage) { xmlWriter.WriteAttributeString("hasGraphicLanguage", "1"); } if (epgEntry.HasGraphicViolence) { xmlWriter.WriteAttributeString("hasGraphicViolence", "1"); } if (epgEntry.HasNudity) { xmlWriter.WriteAttributeString("hasNudity", "1"); } if (epgEntry.HasStrongSexualContent) { xmlWriter.WriteAttributeString("hasStrongSexualContent", "1"); } if (epgEntry.MpaaParentalRating != null) { switch (epgEntry.MpaaParentalRating) { case "G": xmlWriter.WriteAttributeString("mpaaRating", "1"); break; case "PG": xmlWriter.WriteAttributeString("mpaaRating", "2"); break; case "PG13": xmlWriter.WriteAttributeString("mpaaRating", "3"); break; case "R": xmlWriter.WriteAttributeString("mpaaRating", "4"); break; case "NC17": xmlWriter.WriteAttributeString("mpaaRating", "5"); break; case "X": xmlWriter.WriteAttributeString("mpaaRating", "6"); break; case "NR": xmlWriter.WriteAttributeString("mpaaRating", "7"); break; case "AO": xmlWriter.WriteAttributeString("mpaaRating", "8"); break; default: break; } } if (epgEntry.EventCategory != null) { processCategoryKeywords(xmlWriter, epgEntry.EventCategory); } if (epgEntry.Date != null) { xmlWriter.WriteAttributeString("year", epgEntry.Date); } if (epgEntry.SeasonNumber != -1) { xmlWriter.WriteAttributeString("seasonNumber", epgEntry.SeasonNumber.ToString()); } if (epgEntry.EpisodeNumber != -1) { xmlWriter.WriteAttributeString("episodeNumber", epgEntry.EpisodeNumber.ToString()); } if (epgEntry.PreviousPlayDate != DateTime.MinValue) { xmlWriter.WriteAttributeString("originalAirdate", convertDateTimeToString(epgEntry.PreviousPlayDate)); } if (RunParameters.Instance.Options.Contains("ALLSERIES")) { xmlWriter.WriteAttributeString("isSeries", "1"); } else { processSeries(xmlWriter, epgEntry); } if (epgEntry.StarRating != null) { switch (epgEntry.StarRating) { case "*": xmlWriter.WriteAttributeString("halfStars", "2"); break; case "*+": xmlWriter.WriteAttributeString("halfStars", "3"); break; case "**": xmlWriter.WriteAttributeString("halfStars", "4"); break; case "**+": xmlWriter.WriteAttributeString("halfStars", "5"); break; case "***": xmlWriter.WriteAttributeString("halfStars", "6"); break; case "***+": xmlWriter.WriteAttributeString("halfStars", "7"); break; case "****": xmlWriter.WriteAttributeString("halfStars", "8"); break; default: break; } } if (epgEntry.Cast != null && epgEntry.Cast.Count != 0) { processCast(xmlWriter, epgEntry.Cast); } if (epgEntry.Directors != null && epgEntry.Directors.Count != 0) { processDirectors(xmlWriter, epgEntry.Directors); } xmlWriter.WriteEndElement(); programNumber++; } } } }