Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2025-07-23 12:17:14 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c576dea3522e16f74651164886d80a1ac4a3e5d3
c576dea3
1 parent
8c0fc0a9
CampaignItemModel parse fixes
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
22 deletions
SwiftWarplyFramework/SwiftWarplyFramework/models/Campaign.swift
SwiftWarplyFramework/SwiftWarplyFramework/models/Campaign.swift
View file @
c576dea
...
...
@@ -128,27 +128,9 @@ public class CampaignItemModel {
self
.
description
=
dictionary
[
"description"
]
as?
String
?
??
""
self
.
workflow_settings
=
dictionary
[
"workflow_settings"
]
as?
[
String
:
Any
]
let
startDateString
=
dictionary
[
"start_date"
]
as?
String
?
??
""
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"yyyy-MM-dd HH:mm:ss"
if
let
date
=
dateFormatter
.
date
(
from
:
startDateString
??
""
)
{
dateFormatter
.
dateFormat
=
"dd/MM/yyyy"
let
resultString
=
dateFormatter
.
string
(
from
:
date
)
self
.
start_date
=
resultString
}
else
{
self
.
start_date
=
""
}
let
endDateString
=
dictionary
[
"end_date"
]
as?
String
?
??
""
let
dateFormatter2
=
DateFormatter
()
dateFormatter2
.
dateFormat
=
"yyyy-MM-dd HH:mm:ss"
if
let
date
=
dateFormatter2
.
date
(
from
:
endDateString
??
""
)
{
dateFormatter2
.
dateFormat
=
"dd/MM/yyyy"
let
resultString
=
dateFormatter2
.
string
(
from
:
date
)
self
.
end_date
=
resultString
}
else
{
self
.
end_date
=
""
}
// Store raw date strings as received from server for better flexibility
self
.
start_date
=
dictionary
[
"start_date"
]
as?
String
?
??
""
self
.
end_date
=
dictionary
[
"end_date"
]
as?
String
?
??
""
if
let
extra_fields
=
dictionary
[
"extra_fields"
]
as?
[
String
:
Any
]
{
self
.
subcategory
=
extra_fields
[
"subcategory"
]
as?
String
?
??
""
...
...
@@ -159,7 +141,7 @@ public class CampaignItemModel {
self
.
type
=
extra_fields
[
"type"
]
as?
String
?
??
""
self
.
carousel
=
extra_fields
[
"carousel"
]
as?
String
?
??
"false"
self
.
category_title
=
extra_fields
[
"category_title"
]
as?
String
??
""
self
.
banner_img
=
CampaignItemModel
.
cleanEscapedUrl
(
extra_fields
[
"
B
anner_img"
]
as?
String
??
""
)
self
.
banner_img
=
CampaignItemModel
.
cleanEscapedUrl
(
extra_fields
[
"
b
anner_img"
]
as?
String
??
""
)
self
.
banner_title
=
extra_fields
[
"Banner_title"
]
as?
String
??
""
self
.
category_id
=
extra_fields
[
"category_id"
]
as?
String
??
""
self
.
filter
=
extra_fields
[
"filter"
]
as?
String
??
""
...
...
@@ -354,6 +336,75 @@ public class CampaignItemModel {
set
(
newValue
)
{
self
.
banner_img_mobile
=
newValue
}
}
// MARK: - Date Formatting Functions
/// Format start date for UI display
/// - Parameter format: Desired output format (default: "dd/MM/yyyy")
/// - Returns: Formatted date string or empty string if parsing fails
public
func
formattedStartDate
(
format
:
String
=
"dd/MM/yyyy"
)
->
String
{
return
CampaignItemModel
.
formatDate
(
self
.
start_date
,
outputFormat
:
format
)
}
/// Format end date for UI display
/// - Parameter format: Desired output format (default: "dd/MM/yyyy")
/// - Returns: Formatted date string or empty string if parsing fails
public
func
formattedEndDate
(
format
:
String
=
"dd/MM/yyyy"
)
->
String
{
return
CampaignItemModel
.
formatDate
(
self
.
end_date
,
outputFormat
:
format
)
}
/// Generic date formatter with multiple input format support
/// - Parameters:
/// - dateString: Raw date string from server
/// - outputFormat: Desired output format
/// - Returns: Formatted date string or empty string if parsing fails
private
static
func
formatDate
(
_
dateString
:
String
?,
outputFormat
:
String
)
->
String
{
guard
let
dateString
=
dateString
,
!
dateString
.
isEmpty
else
{
return
""
}
let
inputFormats
=
[
"yyyy-MM-dd HH:mm:ssZZZZZ"
,
// With timezone: "2025-07-12 11:55:00+03:00"
"yyyy-MM-dd HH:mm:ss"
// Without timezone: "2025-07-12 11:55:00"
]
let
inputFormatter
=
DateFormatter
()
let
outputFormatter
=
DateFormatter
()
outputFormatter
.
dateFormat
=
outputFormat
for
format
in
inputFormats
{
inputFormatter
.
dateFormat
=
format
if
let
date
=
inputFormatter
.
date
(
from
:
dateString
)
{
return
outputFormatter
.
string
(
from
:
date
)
}
}
// If all formats fail, return the original string
print
(
"⚠️ [CampaignItemModel] Failed to parse date:
\(
dateString
)
"
)
return
dateString
}
// MARK: - Backward Compatibility
/// Formatted start date for backward compatibility
/// Returns start date in "dd/MM/yyyy" format
public
var
_start_date_formatted
:
String
{
return
formattedStartDate
()
}
/// Formatted end date for backward compatibility
/// Returns end date in "dd/MM/yyyy" format
public
var
_end_date_formatted
:
String
{
return
formattedEndDate
()
}
/// Raw start date as received from server
public
var
_start_date_raw
:
String
?
{
return
self
.
start_date
}
/// Raw end date as received from server
public
var
_end_date_raw
:
String
?
{
return
self
.
end_date
}
// MARK: - Computed properties for UI compatibility
public
var
_valid_until
:
String
?
{
...
...
Please
register
or
login
to post a comment