{"id":17182356,"url":"https://github.com/simoncropp/timestamp","last_synced_at":"2025-04-13T16:21:54.974Z","repository":{"id":11678208,"uuid":"14188408","full_name":"SimonCropp/Timestamp","owner":"SimonCropp","description":"Adds a build timestamp to an assembly.","archived":false,"fork":false,"pushed_at":"2025-04-09T00:41:41.000Z","size":650,"stargazers_count":18,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-12T00:26:26.390Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SimonCropp.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"license.txt","code_of_conduct":"code_of_conduct.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"SimonCropp"}},"created_at":"2013-11-06T23:08:47.000Z","updated_at":"2025-04-09T00:41:45.000Z","dependencies_parsed_at":"2023-12-18T17:12:45.379Z","dependency_job_id":"200be822-1ab3-46aa-8660-1b153e4ab180","html_url":"https://github.com/SimonCropp/Timestamp","commit_stats":{"total_commits":338,"total_committers":7,"mean_commits":"48.285714285714285","dds":0.4349112426035503,"last_synced_commit":"aeb36f21992f08afbf283237b1b69fa8de956cb8"},"previous_names":["particular/timestamp"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonCropp%2FTimestamp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonCropp%2FTimestamp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonCropp%2FTimestamp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimonCropp%2FTimestamp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimonCropp","download_url":"https://codeload.github.com/SimonCropp/Timestamp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248741849,"owners_count":21154388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T00:36:51.698Z","updated_at":"2025-04-13T16:21:54.953Z","avatar_url":"https://github.com/SimonCropp.png","language":"C#","funding_links":["https://github.com/sponsors/SimonCropp"],"categories":[],"sub_categories":[],"readme":"Timestamp\n=========\n\nAdds a build timestamp to an assembly.\n\n**See [Milestones](../../milestones?state=closed) for release notes.**\n\n\n## The NuGet package [![NuGet Status](http://img.shields.io/nuget/v/Timestamp.svg?style=flat)](https://www.nuget.org/packages/Timestamp/)\n\nhttps://nuget.org/packages/Timestamp/\n\n    PM\u003e Install-Package Timestamp\n\n\n## What's wrong with using Modified or Created date\n\nFile timestamps are not reliable since they can be changed by various mechanisms, for example when being transferred over the wire.\n\n\n## What it actually does\n\nNote that this is done at compile time and you will not see the code in your project.\n\n\n### Adds the following class to your assembly\n\n```csharp\nnamespace Timestamp\n{\n    [System.AttributeUsage(System.AttributeTargets.Assembly)]\n    class TimestampAttribute : System.Attribute\n    {\n        public string Timestamp { get; private set; }\n\n        public TimestampAttribute(string timestamp)\n        {\n            Timestamp = timestamp;\n        }\n    }\n}\n```\n\n\n### Adds the following attribute to your assembly\n\n```csharp\n[assembly: Timestamp(\"yyyy-MM-ddTHH:mm:ss.fffZ\")]\n```\n\nSo for example, if you compile your assembly on the 10th of September 2018 the timestamp will be\n\n```csharp\n[assembly: Timestamp(\"2018-09-10T16:24:59.417Z\")]\n```\n\n\n### It is UTC\n\nNote that the code that generates the timestamp uses UTC. \n\n```csharp\nDateTime.UtcNow.ToString(\"yyyy-MM-ddTHH:mm:ss.fffZ\")\n```\n\n## How do I access the value\n\nIn standard .net you can use the following\n\n```csharp\npublic static string RetrieveTimestamp()\n{\n    var attribute = Assembly.GetExecutingAssembly()\n        .GetCustomAttributes(false)\n        .First(x =\u003e x.GetType().Name == \"TimestampAttribute\");\n\n    return (string) attribute.GetType()\n        .GetProperty(\"Timestamp\")\n        .GetValue(attribute);\n}\n```\n\nIf you are on .net 4.5 you can make use of the [AttributeType](http://msdn.microsoft.com/en-us/library/system.reflection.customattributedata.attributetype.aspx) property use the below code. It will be a little faster due to less reflection.\n\n\n```csharp\npublic static string RetrieveTimestamp()\n{\n    var attribute = Assembly.GetExecutingAssembly()\n        .GetCustomAttributesData()\n        .First(x =\u003e x.AttributeType.Name == \"TimestampAttribute\");\n\n    return (string)attribute.ConstructorArguments.First().Value;\n}\n```\n\n\n### What if I need a `DateTime` \n\n```csharp\npublic static DateTime RetrieveTimestampAsDateTime()\n{\n    var timestamp = RetrieveTimestamp();\n    return DateTime.ParseExact(timestamp, \"yyyy-MM-ddTHH:mm:ss.fffZ\", null, DateTimeStyles.AssumeUniversal)\n        .ToUniversalTime();\n}\n```\n\n\n## How do I test that it has worked\n\nSince all this happens at compile time, with no code seen by you, it is advisable to add a unit test to verify that the injection has happened.\n\n```csharp\n[Test]\npublic void EnsureTimestampHasBeenAdded()\n{\n    var timestamp = RetrieveTimestamp();\n    Assert.AreEqual(DateTime.UtcNow.ToString(\"yyyy-MM-ddTHH:mm:ss.fffZ\"), timestamp);\n}\n```\n\nNote that this test makes the assumption that the test is being run on the same day as the compilation of the target assembly. Feel free to change the tolerance of that assumption.\n\n\n## Nuget\n\nNuget package http://nuget.org/packages/Timestamp\n\nTo Install from the NuGet Package Manager Console\n\n```powershell\nPM\u003e Install-Package Timestamp\n```\n\n\n## Icon\n\n\u003ca href=\"http://thenounproject.com/noun/mayan-calendar/#icon-No10219\" target=\"_blank\"\u003eMayan Calendar\u003c/a\u003e designed by \u003ca href=\"http://thenounproject.com/Aleks1416\" target=\"_blank\"\u003eArturo Alejandro Romo Escartin\u003c/a\u003e from The Noun Project","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimoncropp%2Ftimestamp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimoncropp%2Ftimestamp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimoncropp%2Ftimestamp/lists"}