question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sitemap LastMod property serialized in an incorrect format

See original GitHub issue

Google’s webmasters tools is throwing several errors on the LastMod property, “An invalid date was found. Please fix the date or formatting before resubmitting”. Upon inspection, as per sitemaps.org, the date must be in a W3C format.

I believe a minor update in SitemapNode.cs such as the following should do the trick (PS: not tested):

        /// <summary>
        /// Shows the date the URL was last modified, value is optional.
        /// </summary>
        [XmlElement("lastmod", Order = 2)]
        public string LastModificationDateW3C
        {
            get
            {
                if (this.LastModificationDate != null)
                {
                    return XmlConvert.ToString((DateTime)this.LastModificationDate);
                }
                return null;
            }
        }
        /// <summary>
        /// The date the URL was last modified
        /// </summary>
        public DateTime? LastModificationDate { get; set; }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
geogaucicommented, Jan 20, 2017

The first method (converting to UTC) does not work, however the second method works perfectly! 😃

Just a recap, after retrieving the datetime required, I created a new DateTime, as per your second suggestion, like so:

        DateTime lta = <get some date, _in local time zone_ >
        DateTime w3cDateTime = new DateTime(lta.Year, lta.Month, lta.Day, lta.Hour, lta.Minute, lta.Second, DateTimeKind.Local);
        sitemapNode.LastModificationDate = w3cDateTime;

Thanks for your support and for your awesome tool! 😃

0reactions
uhaciogullaricommented, Jan 20, 2017

You’re welcome.

It seems like there is a ToLocalTime method as well and it looks cleaner.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is the sitemap validator returning an error for ...
According to the spec for lastmod , specifying the seconds isn't required for datetimes. The lastmod element uses the "W3C Datetime format", ...
Read more >
How to serialize google sitemap in c# using XmlSerializer
You need to use the right namespace: [XmlRoot("urlset", Namespace = "http://www.sitemaps.org/schemas/sitemap/0.9")].
Read more >
The Importance of Setting the "lastmod" Tag in Your Sitemap
The most prevalent issue with incorrectly set "lastmod" values in XML sitemaps is that they are identical, as in the example provided.
Read more >
@astrojs/sitemap Astro Documentation
The serialize function should return SitemapItem , touched or not. The example below shows the ability to add sitemap specific properties individually.
Read more >
Sitemap update error with date format
Hi! I'm trying to update my site's sitemap.xml and constantly receiving an error message about date format. I had the same date format ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found