Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V4] DateTime handling adjustments for inconsistencies between local and UTC times. #3572

Open
wants to merge 7 commits into
base: v4-development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions buildtools/CustomTasks/TimingTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public override bool Execute()
if (ShouldInit)
{
ShouldInit = false;
StartTime = DateTime.Now;
StartTime = DateTime.UtcNow;
MainThread = new Thread(() =>
{
try
{
while (true)
{
var elapsed = DateTime.Now - StartTime;
var elapsed = DateTime.UtcNow - StartTime;
Console.WriteLine(">>>>> ELAPSED TIME = " + elapsed.ToString("h'h 'm'm 's's'"));
Thread.Sleep(SleepTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,11 @@ public void AutoScalingPutScheduledUpdateGroupAction()
{
AutoScalingGroupName = "my-auto-scaling-group",
DesiredCapacity = 4,
EndTimeUtc = new DateTime(2014, 5, 12, 8, 0, 0, DateTimeKind.Utc),
EndTime = new DateTime(2014, 5, 12, 8, 0, 0, DateTimeKind.Utc),
MaxSize = 6,
MinSize = 2,
ScheduledActionName = "my-scheduled-action",
StartTimeUtc = new DateTime(2014, 5, 12, 8, 0, 0, DateTimeKind.Utc)
StartTime = new DateTime(2014, 5, 12, 8, 0, 0, DateTimeKind.Utc)
});


Expand Down
6 changes: 3 additions & 3 deletions docgenerator/AWSSDKDocSamples/EC2/EC2.GeneratedSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ public void EC2DescribeSpotFleetRequestHistory()
var response = client.DescribeSpotFleetRequestHistory(new DescribeSpotFleetRequestHistoryRequest
{
SpotFleetRequestId = "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE",
StartTimeUtc = new DateTime(2015, 5, 26, 12, 0, 0, DateTimeKind.Utc)
StartTime = new DateTime(2015, 5, 26, 12, 0, 0, DateTimeKind.Utc)
});

List<HistoryRecord> historyRecords = response.HistoryRecords;
Expand Down Expand Up @@ -1879,14 +1879,14 @@ public void EC2DescribeSpotPriceHistory()
var client = new AmazonEC2Client();
var response = client.DescribeSpotPriceHistory(new DescribeSpotPriceHistoryRequest
{
EndTimeUtc = new DateTime(2014, 1, 6, 8, 9, 10, DateTimeKind.Utc),
EndTime = new DateTime(2014, 1, 6, 8, 9, 10, DateTimeKind.Utc),
InstanceTypes = new List<string> {
"m1.xlarge"
},
ProductDescriptions = new List<string> {
"Linux/UNIX (Amazon VPC)"
},
StartTimeUtc = new DateTime(2014, 1, 6, 7, 8, 9, DateTimeKind.Utc)
StartTime = new DateTime(2014, 1, 6, 7, 8, 9, DateTimeKind.Utc)
});

List<SpotPrice> spotPriceHistory = response.SpotPriceHistory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ public void ElastiCacheDescribeEvents()
var client = new AmazonElastiCacheClient();
var response = client.DescribeEvents(new DescribeEventsRequest
{
StartTimeUtc = new DateTime(2016, 12, 22, 3, 0, 0, DateTimeKind.Utc)
StartTime = new DateTime(2016, 12, 22, 3, 0, 0, DateTimeKind.Utc)
});

List<Event> events = response.Events;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static CookiesForCannedPolicy GetCookiesForCannedPolicy(string resourceUr
{
var cookies = new CookiesForCannedPolicy();

string epochSeconds = AWSSDKUtils.ConvertToUnixEpochSecondsString(expiresOn.ToUniversalTime());
string epochSeconds = AWSSDKUtils.ConvertToUnixEpochSecondsString(expiresOn);
cookies.Expires = new KeyValuePair<string, string>(
ExpiresKey, epochSeconds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public static String SignUrlCanned(string resourceUrlOrPath,
TextReader privateKey,
DateTime expiresOn)
{
string epochSeconds = AWSSDKUtils.ConvertToUnixEpochSecondsString(expiresOn.ToUniversalTime());
string epochSeconds = AWSSDKUtils.ConvertToUnixEpochSecondsString(expiresOn);
RSAParameters rsaParameters = ConvertPEMToRSAParameters(privateKey);
string cannedPolicy = "{\"Statement\":[{\"Resource\":\"" + resourceUrlOrPath
+ "\",\"Condition\":{\"DateLessThan\":{\"AWS:EpochTime\":" + epochSeconds
Expand Down Expand Up @@ -408,15 +408,15 @@ public static string BuildPolicyForSignedUrl(string resourcePath,
+ "\""
+ ",\"Condition\":{"
+ "\"DateLessThan\":{\"AWS:EpochTime\":"
+ AWSSDKUtils.ConvertToUnixEpochSecondsString(expiresOn.ToUniversalTime())
+ AWSSDKUtils.ConvertToUnixEpochSecondsString(expiresOn)
+ "}"
// omitting IpAddress parameter indicates any ip address access
+ (string.IsNullOrEmpty(limitToIpAddressCIDR)
? ""
: ",\"IpAddress\":{\"AWS:SourceIp\":\"" + limitToIpAddressCIDR + "\"}")
// Ignore epochDateGreaterThan if its value is DateTime.MinValue, the default value of DateTime.
+ (activeFrom > DateTime.MinValue ? ",\"DateGreaterThan\":{\"AWS:EpochTime\":"
+ AWSSDKUtils.ConvertToUnixEpochSecondsString(activeFrom.ToUniversalTime()) + "}"
+ AWSSDKUtils.ConvertToUnixEpochSecondsString(activeFrom) + "}"
: string.Empty)
+ "}}]}";
return policy;
Expand Down
2 changes: 1 addition & 1 deletion extensions/test/CloudFront.SignersTests/URLSignerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void TestGetCannedSignedUrlWithOpenSSL3()
-----END PRIVATE KEY-----
");

Assert.NotNull(AmazonCloudFrontUrlSigner.GetCannedSignedURL("http://example.com", reader, "keyPairId", DateTime.Now));
Assert.NotNull(AmazonCloudFrontUrlSigner.GetCannedSignedURL("http://example.com", reader, "keyPairId", DateTime.UtcNow));

}
}
Expand Down
22 changes: 22 additions & 0 deletions generator/.DevConfigs/460d1afb-6912-4244-82e2-cfb811a84743.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"core": {
"changeLogMessages": [
"Updated DateTime handling to use UTC instead of local times.",
"DateTime handling (Breaking Change): Removed obsolete properties such EndTime then changed EndTimeUtc to EndTime. This could lead to offset times for developers still using the marked obsolete original EndTime for example. A compile time error will occur for anyone using any of the removed *Utc properties such as EndTimeUtc.",
"DateTime handling (Breaking Change): Response unmarshallers for TimeStamps and list TimeStamps for formats TimestampFormat.ISO8601 || TimestampFormat.RFC822 datetimes were being parsed into local times. Adjusted DateTime parsing to return UTC times.",
"DateTime handling (Breaking Change): Fixed the DateTimeUnmarshaller which was parsing datetime strings into and returning them as local time which in some cases were still getting converted back to UTC on a prior bug fix but not always. DateTime strings unmarshalled are assumed to be UTC time and will be specified and unmarshalled as UTC.",
"DateTime handling (Breaking Change): ConvertFromUnixEpochSeconds/ConvertFromUnixEpochMilliseconds incorrectly returning the Unix Epoch time as local time instead of a UTC time by definition. This changes the behavior where these methods were used.",
"DateTime handling (Breaking Change): DynamoDB RetrieveDateTimeInUtc has been switched to true as the default.",
"DateTime handling (Bug fix): Fixed internal Epoch dates to UTC per definition where the epoch date was created in local time. ",
"DateTime handling (Bug fix): Stopped using expiry times in credentials internally as local time. Changed to UTC.",
"DateTime handling (Bug fix): Ensured DateTime.Max and DateTime.Min are marked with a DateTime.Kind DateTimeKind.Utc for proper calculations.",
"DateTime handling (Bug fix): Instead of assuming SAML credentials are local time then converting to UTC and assume that the time given is UTC to work properly with credential expiration being in UTC time for other credential providers.",
"DateTime handling (Bug fix): Console logger outputs timestamps as a UTC date incase output is sent off the local machine and for easier comparison with other UTC dates.",
"DateTime handling (Bug fix): RetryPolicies return UTC server time instead of a UTC time converted to local time.",
"DateTime handling (Bug fix): AWSPublicIpAddressRanges mixing UTC and local time.",
"DateTime handling (Bug fix): GetFormattedTimestampISO8601 incorrectly creating a DateTime object as local time even though it is passed in as UTC. Then formatting it as a UTC string."
],
"type": "patch",
"updateMinimum": true
}
}
41 changes: 0 additions & 41 deletions generator/ServiceClientGeneratorLib/Customizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,8 @@ public class ShapeModifier
public const string InjectKey = "inject";
public const string CustomMarshallKey = "customMarshall";
public const string DeprecatedMessageKey = "deprecatedMessage";
public const string BackwardsCompatibleDateTimeKey = "backwardsCompatibleDateTimeProperties";

private readonly HashSet<string> _excludedProperties;
private readonly HashSet<string> _backwardsCompatibleDateTimeProperties;
private readonly Dictionary<string, JsonData> _modifiedProperties;
private readonly Dictionary<string, JsonData> _injectedProperties;

Expand All @@ -871,7 +869,6 @@ public ShapeModifier(JsonData data)
DeprecationMessage = data[DeprecatedMessageKey].CastToString();

_excludedProperties = ParseExclusions(data);
_backwardsCompatibleDateTimeProperties = ParseBackwardsCompatibleDateTimeProperties(data);
_modifiedProperties = ParseModifiers(data);
// Process additions after rename to allow for models where we
// add a 'convenience' member (for backwards compatibility) using
Expand Down Expand Up @@ -931,25 +928,6 @@ public bool IsExcludedProperty(string propertyName)

#endregion

#region Backwards Compatible DateTime Properties

// Backwards Compatible DateTime Properties modifier is a simple array of property names.
// "backwardsCompatibleDateTimeProperties": [ "propName1", "propName2" ]
private static HashSet<string> ParseBackwardsCompatibleDateTimeProperties(JsonData data)
{
var exclusions = data[ShapeModifier.BackwardsCompatibleDateTimeKey]
?.Cast<object>()
.Select(exclusion => exclusion.ToString());
return new HashSet<string>(exclusions ?? new string[0]);
}

public bool IsBackwardsCompatibleDateTimeProperty(string propertyName)
{
return _backwardsCompatibleDateTimeProperties.Contains(propertyName);
}

#endregion

#region Property Modifiers

// A modifier is an array of objects, each object being the original
Expand Down Expand Up @@ -1237,25 +1215,6 @@ public bool IsExcludedProperty(string propertyName, string shapeName = null)
return false;
}

/// <summary>
/// Returns true if the specified property name is marked as requiring backwards compatible handling
/// of DateTime values at global or per-shape scope.
/// </summary>
/// <param name="propertyName"></param>
/// <param name="shapeName"></param>
/// <returns></returns>
public bool IsBackwardsCompatibleDateTimeProperty(string propertyName, string shapeName = null)
{
if (shapeName != null)
{
var shapeModifier = GetShapeModifier(shapeName);
if (shapeModifier != null)
return shapeModifier.IsBackwardsCompatibleDateTimeProperty(propertyName);
}

return false;
}

public OperationModifiers GetOperationModifiers(string operationName)
{
var data = _documentRoot[OperationModifiers.OperationModifiersKey];
Expand Down
4 changes: 2 additions & 2 deletions generator/ServiceClientGeneratorLib/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void GetSampleLiteral(Shape shape, JsonData data, CodeBuilder cb)
cb.AppendFormat("new {0}({1})", ShapeType(shape), data.ToString());
}

else if (shape.IsDateTime)
else if (shape.IsTimeStamp)
{
string exampleValue = null;

Expand Down Expand Up @@ -363,7 +363,7 @@ private string ShapeType(Shape shape)
return "float";
if (shape.IsDouble)
return "double";
if (shape.IsDateTime)
if (shape.IsTimeStamp)
return "DateTime";
if (shape.IsMemoryStream)
return "MemoryStream";
Expand Down
Loading
Loading