diff --git a/src/X.Web.RSS/Extensions/DateTimeExtensions.cs b/src/X.Web.RSS/Extensions/DateTimeExtensions.cs
index f8accf1..b4d5b5f 100644
--- a/src/X.Web.RSS/Extensions/DateTimeExtensions.cs
+++ b/src/X.Web.RSS/Extensions/DateTimeExtensions.cs
@@ -1,4 +1,5 @@
using System;
+using System.Globalization;
namespace X.Web.RSS.Extensions
{
@@ -9,6 +10,14 @@ public static class DateTimeExtensions
///
///The specified date formatted as a RFC822 date string.
public static string ToRFC822Date(this DateTime date)
+ {
+ var timeZone = GetTimeZone();
+
+ var result = date.ToString("ddd, dd MMM yyyy HH:mm:ss " + timeZone.PadRight(5, '0'));
+ return result;
+ }
+
+ private static string GetTimeZone()
{
var utcOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.Now);
var offset = utcOffset.Hours;
@@ -19,9 +28,12 @@ public static string ToRFC822Date(this DateTime date)
int i = offset * -1;
timeZone = "-" + i.ToString().PadLeft(2, '0');
}
+ return timeZone;
+ }
- var result = date.ToString("ddd, dd MMM yyyy HH:mm:ss " + timeZone.PadRight(5, '0'));
- return result;
+ public static DateTime FromRFC822Date(this string date)
+ {
+ return DateTime.Parse(date);
}
}
}
\ No newline at end of file
diff --git a/src/X.Web.RSS/Structure/RssChannel.cs b/src/X.Web.RSS/Structure/RssChannel.cs
index fcb2bf2..f04bad7 100644
--- a/src/X.Web.RSS/Structure/RssChannel.cs
+++ b/src/X.Web.RSS/Structure/RssChannel.cs
@@ -95,14 +95,14 @@ public RssChannel()
public string InternalLastBuildDate
{
get => LastBuildDate?.ToRFC822Date();
- set => throw new System.NotSupportedException("Setting this property is not supported");
+ set => LastBuildDate = value?.FromRFC822Date();
}
[XmlElement("pubDate")]
public string InternalPubDate
{
get => PubDate?.ToRFC822Date();
- set => throw new System.NotSupportedException("Setting this property is not supported");
+ set => PubDate = value?.FromRFC822Date();
}
[XmlElement("ttl")]
diff --git a/src/X.Web.RSS/Structure/RssItem.cs b/src/X.Web.RSS/Structure/RssItem.cs
index 6bce117..21b1315 100644
--- a/src/X.Web.RSS/Structure/RssItem.cs
+++ b/src/X.Web.RSS/Structure/RssItem.cs
@@ -94,11 +94,9 @@ public class RssItem
public string InternalPubDate
{
get => PubDate?.ToRFC822Date();
- set => throw new System.NotSupportedException("Setting this property is not supported");
+ set => PubDate = value?.FromRFC822Date();
}
-
-
#endregion
}
}
\ No newline at end of file
diff --git a/src/X.Web.RSS/Structure/RssPerson.cs b/src/X.Web.RSS/Structure/RssPerson.cs
index 98af1f5..8f55a9a 100644
--- a/src/X.Web.RSS/Structure/RssPerson.cs
+++ b/src/X.Web.RSS/Structure/RssPerson.cs
@@ -1,6 +1,4 @@
using System.Xml.Serialization;
-using X.Web.RSS.Enumerators;
-using X.Web.RSS.Structure.Validators;
namespace X.Web.RSS.Structure
{
@@ -12,21 +10,10 @@ public RssPerson()
public RssPerson(string name, string email)
{
- Name = name;
- Email = email;
+ Value = $"{email} ({name})";
}
- [XmlIgnore]
- public string Email { get; set; }
-
- [XmlIgnore]
- public string Name { get; set; }
-
[XmlText]
- public string Value
- {
- get => $"{Email} ({Name})";
- set => throw new System.NotSupportedException("Setting this property is not supported");
- }
+ public string Value { get; set; }
}
}
\ No newline at end of file
diff --git a/src/X.Web.RSS/X.Web.RSS.csproj b/src/X.Web.RSS/X.Web.RSS.csproj
index 02b75d3..3daf6b8 100644
--- a/src/X.Web.RSS/X.Web.RSS.csproj
+++ b/src/X.Web.RSS/X.Web.RSS.csproj
@@ -2,12 +2,10 @@
netstandard1.4
- 2.1.0
+ 2.2.0
beta
-
- X.Web.Rss is a part of X-Framework library.
- This library allows you quickly and easily generate a RSS feeds.
-
+ X.Web.Rss is a part of X-Framework library.
+This library allows you quickly and easily generate a RSS feeds.
Andrew Gubskiy
https://github.com/ernado-x/X.Web.RSS
git
@@ -15,7 +13,7 @@
https://ru.gravatar.com/userimage/8071071/f2dc08ee7e4016451f64a7ae9cffd110.png?size=200
True
xwebrss
- Andrew Gubskiu
+ Andrew Gubskiy
.NET Core Ukrainian User Group
diff --git a/tests/X.Web.RSS.Tests/RSSHelperTest.cs b/tests/X.Web.RSS.Tests/RSSHelperTest.cs
index a9359d4..a8ca339 100644
--- a/tests/X.Web.RSS.Tests/RSSHelperTest.cs
+++ b/tests/X.Web.RSS.Tests/RSSHelperTest.cs
@@ -4,7 +4,6 @@
using System.IO;
using System.Net;
using System.Text;
-using X.Web.RSS;
using X.Web.RSS.Enumerators;
using X.Web.RSS.Structure;
using X.Web.RSS.Structure.Validators;
@@ -61,7 +60,7 @@ public void Test()
var rss = RssDocument.Load(stream);
- Assert.Equal("News Center", rss.Channel.Title);
+ Assert.Equal("Stories", rss.Channel.Title);
Assert.Equal("Microsoft news, features, events, and press materials", rss.Channel.Description);
}
diff --git a/tests/X.Web.RSS.Tests/Validators/RssDateTest.cs b/tests/X.Web.RSS.Tests/Validators/RssDateTest.cs
index 76e9f0c..32d2512 100644
--- a/tests/X.Web.RSS.Tests/Validators/RssDateTest.cs
+++ b/tests/X.Web.RSS.Tests/Validators/RssDateTest.cs
@@ -2,6 +2,7 @@
using System;
using System.Globalization;
using X.Web.RSS.Exceptions;
+using X.Web.RSS.Extensions;
using X.Web.RSS.Structure.Validators;
namespace X.Web.RSS.Tests.Validators
@@ -242,5 +243,17 @@ public void Ctor_InvalidDateFormat_Error()
// Assert
Assert.NotNull(e);
}
+
+ [Fact]
+ public void DateExtensionTest()
+ {
+ var date = DateTime.Now;
+
+ var rfcDateInString = date.ToRFC822Date();
+ var parsedDate = rfcDateInString.FromRFC822Date();
+
+ Assert.Equal(date.ToLongDateString(), parsedDate.ToLongDateString());
+ Assert.Equal(date.ToLongTimeString(), parsedDate.ToLongTimeString());
+ }
}
}
\ No newline at end of file