Skip to content

Commit 74df7ca

Browse files
committed
Fixing a locale issue of DateTime
1 parent ddb9c01 commit 74df7ca

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Jobs/AzureBackupJobHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public enum JobOperationType
6060

6161
public static class AzureBackupJobHelper
6262
{
63+
public static DateTime MinimumAllowedDate = new DateTime(DateTime.MinValue.Year, DateTime.MinValue.Month, DateTime.MinValue.Day, DateTime.MinValue.Hour, DateTime.MinValue.Minute, DateTime.MinValue.Second, DateTimeKind.Utc);
64+
6365
public static bool IsValidStatus(string inputStatus)
6466
{
6567
JobStatus status;

src/ResourceManager/AzureBackup/Commands.AzureBackup/Cmdlets/Jobs/GetAzureBackupJob.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class GetAzureBackupJob : AzureBackupCmdletBase
5555
public string Status { get; set; }
5656

5757
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.JobFilterTypeHelpMessage, ParameterSetName = "FiltersSet")]
58-
[ValidateSet("VM")]
58+
[ValidateSet("IaasVM")]
5959
public string Type { get; set; }
6060

6161
[Parameter(Mandatory = false, HelpMessage = AzureBackupCmdletHelpMessage.JobFilterOperationHelpMessage, ParameterSetName = "FiltersSet")]
@@ -81,18 +81,22 @@ public override void ExecuteCmdlet()
8181
// validations
8282
if (!From.HasValue)
8383
{
84+
if (To.HasValue)
85+
{
86+
throw new Exception("Please specify both From and To.");
87+
}
8488
WriteDebug("Setting StartTime to min value.");
8589
From = new DateTime();
86-
From = DateTime.MinValue;
90+
From = AzureBackupJobHelper.MinimumAllowedDate;
8791
}
8892

8993
if (To.HasValue && To.Value <= From.Value)
9094
{
91-
throw new Exception("StartTime should be greater than EndTime.");
95+
throw new Exception("From should be lesser than To.");
9296
}
9397
else
9498
{
95-
if (From != DateTime.MinValue)
99+
if (From != AzureBackupJobHelper.MinimumAllowedDate)
96100
{
97101
WriteDebug("End time not set. Setting it to current time.");
98102
To = DateTime.Now;
@@ -101,7 +105,7 @@ public override void ExecuteCmdlet()
101105
{
102106
WriteDebug("Setting EndTime to min value.");
103107
To = new DateTime();
104-
To = DateTime.MinValue;
108+
To = AzureBackupJobHelper.MinimumAllowedDate;
105109
}
106110
}
107111

@@ -110,7 +114,7 @@ public override void ExecuteCmdlet()
110114

111115
// if user hasn't specified any filters, then default filter fetches
112116
// all jobs that were created in last 24 hours.
113-
if (From == DateTime.MinValue && To == DateTime.MinValue &&
117+
if (From == AzureBackupJobHelper.MinimumAllowedDate && To == AzureBackupJobHelper.MinimumAllowedDate &&
114118
string.IsNullOrEmpty(Operation) && string.IsNullOrEmpty(Status) &&
115119
string.IsNullOrEmpty(Type) && string.IsNullOrEmpty(JobId))
116120
{

0 commit comments

Comments
 (0)