mirror of
https://github.com/bitwarden/directory-connector
synced 2025-12-15 07:43:27 +00:00
parse date extension
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.DirectoryServices;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -20,5 +21,17 @@ namespace Bit.Core.Utilities
|
|||||||
{
|
{
|
||||||
return date.ToString("yyyyMMddHHmmss.f'Z'");
|
return date.ToString("yyyyMMddHHmmss.f'Z'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static DateTime? ParseDateTime(this ResultPropertyCollection collection, string dateKey)
|
||||||
|
{
|
||||||
|
DateTime date;
|
||||||
|
if(collection.Contains(dateKey) && collection[dateKey].Count > 0 &&
|
||||||
|
DateTime.TryParse(collection[dateKey][0].ToString(), out date))
|
||||||
|
{
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -266,8 +266,8 @@ namespace Bit.Core.Utilities
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dates
|
// Dates
|
||||||
user.CreationDate = ParseDate(item.Properties, SettingsService.Instance.Sync.CreationDateAttribute);
|
user.CreationDate = item.Properties.ParseDateTime(SettingsService.Instance.Sync.CreationDateAttribute);
|
||||||
user.RevisionDate = ParseDate(item.Properties, SettingsService.Instance.Sync.RevisionDateAttribute);
|
user.RevisionDate = item.Properties.ParseDateTime(SettingsService.Instance.Sync.RevisionDateAttribute);
|
||||||
|
|
||||||
users.Add(user);
|
users.Add(user);
|
||||||
}
|
}
|
||||||
@@ -308,17 +308,5 @@ namespace Bit.Core.Utilities
|
|||||||
FlattenGroupsToUsers(groupsInThisGroup, usersInThisGroup, allGroups, allUsers);
|
FlattenGroupsToUsers(groupsInThisGroup, usersInThisGroup, allGroups, allUsers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DateTime? ParseDate(ResultPropertyCollection collection, string dateKey)
|
|
||||||
{
|
|
||||||
DateTime date;
|
|
||||||
if(collection.Contains(dateKey) && collection[dateKey].Count > 0 &&
|
|
||||||
DateTime.TryParse(collection[dateKey][0].ToString(), out date))
|
|
||||||
{
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user