@@ -19,6 +19,13 @@ function isPrerelease(version: string): boolean {
1919 return version . includes ( '-' )
2020}
2121
22+ // NuGet stamps unlisted versions with 1900-01-01T00:00:00Z as a sentinel — treat as absent.
23+ function parsePublishedDate ( published : string | undefined ) : Date | null {
24+ if ( ! published ) return null
25+ const date = new Date ( published )
26+ return ! isNaN ( date . getTime ( ) ) && date . getUTCFullYear ( ) > 1900 ? date : null
27+ }
28+
2229const SCM_HOSTS = [ 'github.com' , 'gitlab.com' , 'bitbucket.org' ]
2330
2431function normalizeRepoUrl ( url : string | undefined ) : string | null {
@@ -105,25 +112,15 @@ export function normalizeNuGetPackage(
105112 status = 'active'
106113 }
107114
108- // NuGet stamps unlisted versions with 1900-01-01T00:00:00Z as a sentinel — exclude them.
109115 const publishedDates = allEntries
110- . filter ( ( e ) => e . published )
111- . map ( ( e ) => new Date ( e . published as string ) )
112- . filter ( ( d ) => ! isNaN ( d . getTime ( ) ) && d . getUTCFullYear ( ) > 1900 )
116+ . map ( ( e ) => parsePublishedDate ( e . published ) )
117+ . filter ( ( d ) : d is Date => d !== null )
113118 . sort ( ( a , b ) => a . getTime ( ) - b . getTime ( ) )
114119
115120 const firstReleaseAt = publishedDates . length > 0 ? publishedDates [ 0 ] : null
116121
117122 const latestEntry4Date = latestListedEntry ?? latestEntry
118- const latestReleaseAtRaw = latestEntry4Date ?. published
119- ? new Date ( latestEntry4Date . published )
120- : null
121- const latestReleaseAt =
122- latestReleaseAtRaw &&
123- ! isNaN ( latestReleaseAtRaw . getTime ( ) ) &&
124- latestReleaseAtRaw . getUTCFullYear ( ) > 1900
125- ? latestReleaseAtRaw
126- : null
123+ const latestReleaseAt = parsePublishedDate ( latestEntry4Date ?. published )
127124
128125 const totalDownloads = searchResult ?. totalDownloads ?? 0
129126
@@ -144,7 +141,7 @@ export function normalizeNuGetPackage(
144141 const { licenses : vLicenses } = parseLicense ( entry . licenseExpression , entry . licenseUrl )
145142 return {
146143 number : ver ,
147- publishedAt : entry . published ? new Date ( entry . published ) : null ,
144+ publishedAt : parsePublishedDate ( entry . published ) ,
148145 isLatest : ver === latestVersion ,
149146 isPrerelease : isPrerelease ( ver ) ,
150147 isYanked : entry . listed === false ,
0 commit comments