Skip to content

Commit f85fe5c

Browse files
committed
use extension member for DateTime.UnixEpoch
1 parent 0770be4 commit f85fe5c

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#nullable enable
2+
namespace System
3+
{
4+
internal static class DateTimeExtensions
5+
{
6+
extension(DateTime)
7+
{
8+
#if !NET
9+
public static DateTime UnixEpoch
10+
{
11+
get
12+
{
13+
return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
14+
}
15+
}
16+
#endif
17+
}
18+
}
19+
}

src/Renci.SshNet/ScpClient.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,7 @@ private string ReadString(Stream stream)
675675
/// <param name="fileOrDirectory">The file or directory to upload.</param>
676676
private void UploadTimes(IChannelSession channel, Stream input, FileSystemInfo fileOrDirectory)
677677
{
678-
#if NET
679678
var zeroTime = DateTime.UnixEpoch;
680-
#else
681-
var zeroTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
682-
#endif
683679
var modificationSeconds = (long)(fileOrDirectory.LastWriteTimeUtc - zeroTime).TotalSeconds;
684680
var accessSeconds = (long)(fileOrDirectory.LastAccessTimeUtc - zeroTime).TotalSeconds;
685681
SendData(channel, string.Format(CultureInfo.InvariantCulture, "T{0} 0 {1} 0\n", modificationSeconds, accessSeconds));
@@ -856,11 +852,7 @@ private void InternalDownload(IChannelSession channel, Stream input, FileSystemI
856852
var mtime = long.Parse(match.Result("${mtime}"), CultureInfo.InvariantCulture);
857853
var atime = long.Parse(match.Result("${atime}"), CultureInfo.InvariantCulture);
858854

859-
#if NET
860855
var zeroTime = DateTime.UnixEpoch;
861-
#else
862-
var zeroTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
863-
#endif
864856
modifiedTime = zeroTime.AddSeconds(mtime);
865857
accessedTime = zeroTime.AddSeconds(atime);
866858
continue;

0 commit comments

Comments
 (0)