Skip to content

Commit 4abd7c4

Browse files
authored
fix: fixed time for createdWhen and updated tests (#193)
1 parent 407d7de commit 4abd7c4

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

src/CommonLib/Helpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public static long ConvertFileTimeToUnixEpoch(string ldapTime) {
207207
/// <returns></returns>
208208
public static long ConvertTimestampToUnixEpoch(string ldapTime) {
209209
try {
210-
var dt = DateTime.ParseExact(ldapTime, "yyyyMMddHHmmss.0K", CultureInfo.CurrentCulture);
210+
var dt = DateTime.ParseExact(ldapTime, "yyyyMMddHHmmss.0K", CultureInfo.CurrentCulture).ToUniversalTime();
211211
return (long)dt.Subtract(EpochDiff).TotalSeconds;
212212
} catch {
213213
return 0;

test/unit/CommonLibHelperTests.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public void ConvertFileTimeToUnixEpoch_BadInput_CastExceptionReturnsNegativeOne(
197197
}
198198

199199
[Fact]
200-
public void ConvertTimestampToUnixEpoch_ValidTimestamp_ValidUnixEpoch() {
200+
public void ConvertFileTimeToUnixEpoch_ValidTimestamp_ValidUnixEpoch() {
201201
var d = DateTime.Parse("2021-06-21T00:00:00");
202202
var result =
203203
Helpers.ConvertFileTimeToUnixEpoch(d.ToFileTimeUtc().ToString()); // get the epoch
@@ -208,7 +208,7 @@ public void ConvertTimestampToUnixEpoch_ValidTimestamp_ValidUnixEpoch() {
208208
}
209209

210210
[Fact]
211-
public void ConvertTimestampToUnixEpoch_InvalidTimestamp_FormatException() {
211+
public void ConvertFileTimeToUnixEpoch_InvalidTimestamp_FormatException() {
212212
Exception ex = Assert.Throws<FormatException>(() =>
213213
Helpers.ConvertFileTimeToUnixEpoch("-201adsfasf12180244"));
214214
Assert.Equal("The input string '-201adsfasf12180244' was not in a correct format.", ex.Message);
@@ -230,5 +230,23 @@ public void DistinguishedNameToDomain_DeletedObjects_CorrectDomain() {
230230
@"DC=..Deleted-_msdcs.testlab.local\0ADEL:af1f072f-28d7-4b86-9b87-a408bfc9cb0d,CN=Deleted Objects,DC=testlab,DC=local");
231231
Assert.Equal("TESTLAB.LOCAL", result);
232232
}
233+
234+
[Fact]
235+
public void ConvertTimestampToUnixEpoch_ValidTimestamp() {
236+
var d = DateTime.Parse("2025-04-07T00:00:00.0000000-07:00");
237+
var result =
238+
Helpers.ConvertTimestampToUnixEpoch(d.ToString("yyyyMMddHHmmss.0K"));
239+
var dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(result);
240+
241+
Assert.Equal(d.ToUniversalTime(), dateTimeOffset.DateTime);
242+
}
243+
244+
[Fact]
245+
public void ConvertTimestampToUnixEpoch_InvalidTimestamp() {
246+
var result =
247+
Helpers.ConvertTimestampToUnixEpoch("-201adsfasf12180244");
248+
249+
Assert.Equal(result, 0);
250+
}
233251
}
234252
}

0 commit comments

Comments
 (0)