From c913bf64f57dda39a99018d725d9087c5b4a843b Mon Sep 17 00:00:00 2001 From: Decoder07 Date: Tue, 7 Nov 2023 17:26:45 +0530 Subject: [PATCH] Fixed datetime bug --- .../ios/Classes/Models/HMSPeerExtension.swift | 4 ++-- .../lib/src/model/hls_player/hms_hls_cue.dart | 4 ++-- .../src/model/hms_browser_recording_state.dart | 2 +- .../lib/src/model/hms_date_extension.dart | 15 +++++++++------ .../lib/src/model/hms_hls_recording_state.dart | 2 +- .../lib/src/model/hms_hls_variant.dart | 2 +- .../lib/src/model/hms_local_peer.dart | 4 ++-- .../hmssdk_flutter/lib/src/model/hms_message.dart | 2 +- .../lib/src/model/hms_remote_peer.dart | 5 ++--- .../lib/src/model/hms_rtmp_streaming_state.dart | 2 +- .../lib/src/model/hms_server_recording_state.dart | 2 +- 11 files changed, 23 insertions(+), 21 deletions(-) diff --git a/packages/hmssdk_flutter/ios/Classes/Models/HMSPeerExtension.swift b/packages/hmssdk_flutter/ios/Classes/Models/HMSPeerExtension.swift index dffeb3be8..8e84988de 100644 --- a/packages/hmssdk_flutter/ios/Classes/Models/HMSPeerExtension.swift +++ b/packages/hmssdk_flutter/ios/Classes/Models/HMSPeerExtension.swift @@ -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 { diff --git a/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_cue.dart b/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_cue.dart index c007ef9b9..1ffd1408f 100644 --- a/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_cue.dart +++ b/packages/hmssdk_flutter/lib/src/model/hls_player/hms_hls_cue.dart @@ -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"]); } diff --git a/packages/hmssdk_flutter/lib/src/model/hms_browser_recording_state.dart b/packages/hmssdk_flutter/lib/src/model/hms_browser_recording_state.dart index b67463262..eab39848f 100644 --- a/packages/hmssdk_flutter/lib/src/model/hms_browser_recording_state.dart +++ b/packages/hmssdk_flutter/lib/src/model/hms_browser_recording_state.dart @@ -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']); } diff --git a/packages/hmssdk_flutter/lib/src/model/hms_date_extension.dart b/packages/hmssdk_flutter/lib/src/model/hms_date_extension.dart index b8877d75f..cd1e7c331 100644 --- a/packages/hmssdk_flutter/lib/src/model/hms_date_extension.dart +++ b/packages/hmssdk_flutter/lib/src/model/hms_date_extension.dart @@ -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; } diff --git a/packages/hmssdk_flutter/lib/src/model/hms_hls_recording_state.dart b/packages/hmssdk_flutter/lib/src/model/hms_hls_recording_state.dart index a82e01fe5..840647dca 100644 --- a/packages/hmssdk_flutter/lib/src/model/hms_hls_recording_state.dart +++ b/packages/hmssdk_flutter/lib/src/model/hms_hls_recording_state.dart @@ -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); } } diff --git a/packages/hmssdk_flutter/lib/src/model/hms_hls_variant.dart b/packages/hmssdk_flutter/lib/src/model/hms_hls_variant.dart index 44a0bd4ae..d875b9f06 100644 --- a/packages/hmssdk_flutter/lib/src/model/hms_hls_variant.dart +++ b/packages/hmssdk_flutter/lib/src/model/hms_hls_variant.dart @@ -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, ); } diff --git a/packages/hmssdk_flutter/lib/src/model/hms_local_peer.dart b/packages/hmssdk_flutter/lib/src/model/hms_local_peer.dart index 2d78ddc45..59957cf29 100644 --- a/packages/hmssdk_flutter/lib/src/model/hms_local_peer.dart +++ b/packages/hmssdk_flutter/lib/src/model/hms_local_peer.dart @@ -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, ); } diff --git a/packages/hmssdk_flutter/lib/src/model/hms_message.dart b/packages/hmssdk_flutter/lib/src/model/hms_message.dart index 4cb69fb37..a7093063b 100644 --- a/packages/hmssdk_flutter/lib/src/model/hms_message.dart +++ b/packages/hmssdk_flutter/lib/src/model/hms_message.dart @@ -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); } diff --git a/packages/hmssdk_flutter/lib/src/model/hms_remote_peer.dart b/packages/hmssdk_flutter/lib/src/model/hms_remote_peer.dart index 8f22b400b..b820c6f0b 100644 --- a/packages/hmssdk_flutter/lib/src/model/hms_remote_peer.dart +++ b/packages/hmssdk_flutter/lib/src/model/hms_remote_peer.dart @@ -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'], @@ -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, ); diff --git a/packages/hmssdk_flutter/lib/src/model/hms_rtmp_streaming_state.dart b/packages/hmssdk_flutter/lib/src/model/hms_rtmp_streaming_state.dart index 6b3d72baf..65b46dc8e 100644 --- a/packages/hmssdk_flutter/lib/src/model/hms_rtmp_streaming_state.dart +++ b/packages/hmssdk_flutter/lib/src/model/hms_rtmp_streaming_state.dart @@ -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); } } diff --git a/packages/hmssdk_flutter/lib/src/model/hms_server_recording_state.dart b/packages/hmssdk_flutter/lib/src/model/hms_server_recording_state.dart index fe051c427..127bd0c24 100644 --- a/packages/hmssdk_flutter/lib/src/model/hms_server_recording_state.dart +++ b/packages/hmssdk_flutter/lib/src/model/hms_server_recording_state.dart @@ -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); } }