Add properties Now and Today (dotnet/corefx#30682)
authorEdwinEngelen <edwin@engelen.name>
Sat, 28 Jul 2018 05:31:29 +0000 (07:31 +0200)
committerDan Moseley <danmose@microsoft.com>
Sat, 28 Jul 2018 05:31:29 +0000 (22:31 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/dfa1338034a24eacda7a89d63363ab267a603449

src/libraries/Microsoft.VisualBasic/ref/Microsoft.VisualBasic.cs
src/libraries/Microsoft.VisualBasic/src/Microsoft.VisualBasic.vbproj
src/libraries/Microsoft.VisualBasic/src/Microsoft/VisualBasic/DateAndTime.vb [new file with mode: 0644]
src/libraries/Microsoft.VisualBasic/tests/DateAndTimeTests.cs [new file with mode: 0644]
src/libraries/Microsoft.VisualBasic/tests/Microsoft.VisualBasic.Tests.csproj

index f5598ea..8fbe3fa 100644 (file)
@@ -5,6 +5,8 @@
 // Changes to this file must follow the http://aka.ms/api-review process.
 // ------------------------------------------------------------------------------
 
+using System;
+
 namespace Microsoft.VisualBasic
 {
     public enum CallType
@@ -63,6 +65,13 @@ namespace Microsoft.VisualBasic
         public const char VerticalTab = '\v';
         public ControlChars() { }
     }
+    [Microsoft.VisualBasic.CompilerServices.StandardModuleAttribute]
+    public sealed partial class DateAndTime
+    {
+        internal DateAndTime() { }
+        public static DateTime Now { get; }
+        public static DateTime Today { get; }
+    }
     [System.AttributeUsageAttribute((System.AttributeTargets)(4), AllowMultiple=false, Inherited=false)]
     [System.ComponentModel.EditorBrowsableAttribute((System.ComponentModel.EditorBrowsableState)(1))]
     public sealed partial class HideModuleNameAttribute : System.Attribute
index 02284a3..c4c94fa 100644 (file)
@@ -47,6 +47,7 @@
     <Compile Include="Microsoft\VisualBasic\Constants.vb" />
     <Compile Include="Microsoft\VisualBasic\ControlChars.vb" />
     <Compile Include="Microsoft\VisualBasic\CompilerServices\DoubleType.vb" />
+    <Compile Include="Microsoft\VisualBasic\DateAndTime.vb" />
     <Compile Include="Microsoft\VisualBasic\HideModuleNameAttribute.vb" />
     <Compile Include="Microsoft\VisualBasic\Information.vb" />
     <Compile Include="Microsoft\VisualBasic\Interaction.vb" />
diff --git a/src/libraries/Microsoft.VisualBasic/src/Microsoft/VisualBasic/DateAndTime.vb b/src/libraries/Microsoft.VisualBasic/src/Microsoft/VisualBasic/DateAndTime.vb
new file mode 100644 (file)
index 0000000..afff190
--- /dev/null
@@ -0,0 +1,21 @@
+' Licensed to the .NET Foundation under one or more agreements.
+' The .NET Foundation licenses this file to you under the MIT license.
+' See the LICENSE file in the project root for more information.
+
+Imports System
+
+Namespace Microsoft.VisualBasic
+    Public Module DateAndTime
+        Public ReadOnly Property Now As DateTime
+            Get
+                Return DateTime.Now
+            End Get
+        End Property
+
+        Public ReadOnly Property Today As DateTime
+            Get
+                Return DateTime.Today
+            End Get
+        End Property
+    End Module
+End Namespace
diff --git a/src/libraries/Microsoft.VisualBasic/tests/DateAndTimeTests.cs b/src/libraries/Microsoft.VisualBasic/tests/DateAndTimeTests.cs
new file mode 100644 (file)
index 0000000..6c75dbc
--- /dev/null
@@ -0,0 +1,33 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using Xunit;
+
+namespace Microsoft.VisualBasic.Tests
+{
+    public class DateAndTimeTests
+    {
+        [Fact]
+        public void Now_ReturnsDateTimeNow()
+        {
+            var dateTimeNowBefore = DateTime.Now;
+            var now = DateAndTime.Now;
+            var dateTimeNowAfter = DateTime.Now;
+
+            Assert.InRange(now, dateTimeNowBefore, dateTimeNowAfter);
+        }
+
+        [Fact]
+        public void Today_ReturnsDateTimeToday()
+        {
+            var dateTimeTodayBefore = DateTime.Today;
+            var today = DateAndTime.Today;
+            var dateTimeTodayAfter = DateTime.Today;
+
+            Assert.InRange(today, dateTimeTodayBefore, dateTimeTodayAfter);
+            Assert.Equal(TimeSpan.Zero, today.TimeOfDay);
+        }
+    }
+}
index f2e1a8f..b179a0f 100644 (file)
@@ -22,6 +22,7 @@
     <Compile Include="Microsoft/VisualBasic/Devices/NetworkAvailableEventArgsTests.cs" />
     <Compile Include="ConversionsTests.cs" />
     <Compile Include="OperatorsTests.cs" />
+    <Compile Include="DateAndTimeTests.cs" />
     <Compile Include="InformationTests.cs" />
     <Compile Include="UtilsTests.cs" />
     <Compile Include="StringsTests.cs" />