Skip to content

Commit

Permalink
Fixed datetime bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Decoder07 committed Nov 7, 2023
1 parent b520205 commit c913bf6
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class HMSPeerExtension {
"is_hand_raised": peer.isHandRaised,
"customer_description": peer.metadata ?? "",
"customer_user_id": peer.customerUserID ?? "",
"joined_at": peer.joinedAt.timeIntervalSince1970,
"updated_at": peer.updatedAt.timeIntervalSince1970
"joined_at": Int(peer.joinedAt.timeIntervalSince1970)*1000,
"updated_at": Int(peer.updatedAt.timeIntervalSince1970)*1000
] as [String: Any]

if let metadata = peer.metadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class HMSHLSCue {

factory HMSHLSCue.fromMap(Map map) {
return HMSHLSCue(
startDate: HMSDateExtension.convertDate(map["start_date"]),
startDate: HMSDateExtension.convertDateFromString(map["start_date"]),
endDate: map["end_date"] == null
? null
: HMSDateExtension.convertDate(map["end_date"]),
: HMSDateExtension.convertDateFromString(map["end_date"]),
id: map["id"],
payload: map["payload"]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HMSBrowserRecordingState {
error: map["error"] != null ? HMSException.fromMap(map) : null,
running: map['running'],
startedAt: map['started_at'] != null
? HMSDateExtension.convertDate(map['started_at'])
? HMSDateExtension.convertDateFromString(map['started_at'])
: null,
initialising: map['initialising']);
}
Expand Down
15 changes: 9 additions & 6 deletions packages/hmssdk_flutter/lib/src/model/hms_date_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import 'dart:developer';
///[HMSDateExtension] is used to convert android and ios native time format to DateTime type
///in local time zone format.
class HMSDateExtension {
static DateTime convertDate(int date) {
DateTime _dateTime = DateTime.fromMillisecondsSinceEpoch(date);

///Returns DateTime object from String
static DateTime convertDateFromString(String date) {
DateTime _dateTime = DateTime.parse(date).toLocal();
return _dateTime;
}

static optionalConvertDate(int date) {
///Returns optional DateTime object from epoch in milliseconds
static DateTime? convertDateFromEpoch(int date) {
try {
DateTime _dateTime = DateTime.fromMillisecondsSinceEpoch(date);
// DateTime _dateTime = DateTime.parse(date).toLocal();
DateTime _dateTime =
DateTime.fromMillisecondsSinceEpoch(date, isUtc: false);
return _dateTime;
} catch (e) {
print(e);
log(e.toString());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HMSHLSRecordingState {
: null,
running: map['running'],
startedAt: map['started_at'] != null
? HMSDateExtension.convertDate(map['started_at'])
? HMSDateExtension.convertDateFromString(map['started_at'])
: null);
}
}
2 changes: 1 addition & 1 deletion packages/hmssdk_flutter/lib/src/model/hms_hls_variant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class HMSHLSVariant {
meetingUrl: map['meeting_url'] as String?,
metadata: map['metadata'] as String?,
startedAt: map['started_at'] != null
? HMSDateExtension.convertDate(map['started_at'])
? HMSDateExtension.convertDateFromString(map['started_at'])
: null,
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/hmssdk_flutter/lib/src/model/hms_local_peer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class HMSLocalPeer extends HMSPeer {
? HMSNetworkQuality.fromMap(map["network_quality"])
: null,
joinedAt: map.containsKey("joined_at")
? HMSDateExtension.optionalConvertDate(map["joined_at"].toInt())
? HMSDateExtension.convertDateFromEpoch(map["joined_at"])
: null,
updatedAt: map.containsKey("updated_at")
? HMSDateExtension.optionalConvertDate(map["updated_at"])
? HMSDateExtension.convertDateFromEpoch(map["updated_at"])
: null,
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hmssdk_flutter/lib/src/model/hms_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class HMSMessage {
sender: sender,
message: messageMap['message'] as String,
type: messageMap['type'] as String,
time: HMSDateExtension.convertDate(messageMap['time']),
time: HMSDateExtension.convertDateFromString(messageMap['time']),
hmsMessageRecipient: recipient);
}

Expand Down
5 changes: 2 additions & 3 deletions packages/hmssdk_flutter/lib/src/model/hms_remote_peer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class HMSRemotePeer extends HMSPeer {

factory HMSRemotePeer.fromMap(Map map) {
HMSRole role = HMSRole.fromMap(map['role']);
// TODO: add auxiliary tracks
HMSRemotePeer peer = HMSRemotePeer(
peerId: map['peer_id'],
name: map['name'],
Expand All @@ -76,10 +75,10 @@ class HMSRemotePeer extends HMSPeer {
? HMSNetworkQuality.fromMap(map["network_quality"])
: null,
joinedAt: map.containsKey("joined_at")
? HMSDateExtension.convertDate(map["joined_at"])
? HMSDateExtension.convertDateFromEpoch(map["joined_at"])
: null,
updatedAt: map.containsKey("updated_at")
? HMSDateExtension.convertDate(map["updated_at"])
? HMSDateExtension.convertDateFromEpoch(map["updated_at"])
: null,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class HMSRtmpStreamingState {
error: map["error"] != null ? HMSException.fromMap(map) : null,
running: map['running'],
startedAt: map['started_at'] != null
? HMSDateExtension.convertDate(map['started_at'])
? HMSDateExtension.convertDateFromString(map['started_at'])
: null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HMSServerRecordingState {
error: map["error"] != null ? HMSException.fromMap(map) : null,
running: map['running'],
startedAt: map['started_at'] != null
? HMSDateExtension.convertDate(map['started_at'])
? HMSDateExtension.convertDateFromString(map['started_at'])
: null);
}
}

0 comments on commit c913bf6

Please sign in to comment.