Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
6bc7b61d
Commit
6bc7b61d
authored
Nov 02, 2023
by
Evan W. Patton
Committed by
Evan W. Patton
Nov 03, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix iOS vs Android date support mismatch in Clock
Change-Id: Ia0a251be7c7a8f105b3b5e59fe66783931e8234d
parent
397061cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
18 deletions
+35
-18
appinventor/components-ios/src/Clock.swift
appinventor/components-ios/src/Clock.swift
+35
-18
No files found.
appinventor/components-ios/src/Clock.swift
View file @
6bc7b61d
...
@@ -5,7 +5,34 @@
...
@@ -5,7 +5,34 @@
import
Foundation
import
Foundation
/**
* Creates a `DateFormatter` object for the given `str`.
*
* @param str The date format string
* @returns A new DateFormatter object configured with the given string
*/
fileprivate
func
makeFormat
(
_
str
:
String
)
->
DateFormatter
{
let
date
=
DateFormatter
()
date
.
dateFormat
=
str
return
date
}
open
class
Clock
:
NonvisibleComponent
,
LifecycleDelegate
{
open
class
Clock
:
NonvisibleComponent
,
LifecycleDelegate
{
/**
* The list of valid date formatters for processing strings into dates.
*/
private
static
let
DATE_FORMATTERS
=
[
makeFormat
(
"MM/dd/yyyy hh:mm:ss a"
),
makeFormat
(
"MM/dd/yyyy HH:mm:ss"
),
makeFormat
(
"MM/dd/yyyy hh:mm a"
),
makeFormat
(
"MM/dd/yyyy HH:mm"
),
makeFormat
(
"MM/dd/yyyy"
),
makeFormat
(
"hh:mm:ss a"
),
makeFormat
(
"HH:mm:ss"
),
makeFormat
(
"hh:mm a"
),
makeFormat
(
"HH:mm"
)
]
fileprivate
var
_timer
:
Timer
?
fileprivate
var
_timer
:
Timer
?
fileprivate
var
_interval
:
Int32
=
1000
fileprivate
var
_interval
:
Int32
=
1000
fileprivate
var
_enabled
=
false
fileprivate
var
_enabled
=
false
...
@@ -64,14 +91,14 @@ open class Clock: NonvisibleComponent, LifecycleDelegate {
...
@@ -64,14 +91,14 @@ open class Clock: NonvisibleComponent, LifecycleDelegate {
}
}
@objc
open
func
MakeInstant
(
_
from
:
String
)
throws
->
Date
{
@objc
open
func
MakeInstant
(
_
from
:
String
)
throws
->
Date
{
guard
let
components
=
dateParser
(
from
)
else
{
guard
let
date
=
dateParser
(
from
)
else
{
_form
?
.
dispatchErrorOccurredEvent
(
self
,
"MakeInstant"
,
_form
?
.
dispatchErrorOccurredEvent
(
self
,
"MakeInstant"
,
ErrorMessage
.
ERROR_ILLEGAL_DATE
.
code
,
ErrorMessage
.
ERROR_ILLEGAL_DATE
.
code
,
ErrorMessage
.
ERROR_ILLEGAL_DATE
.
message
)
ErrorMessage
.
ERROR_ILLEGAL_DATE
.
message
)
throw
YailRuntimeError
(
"Argument to MakeInstant should have form MM/DD/YYYY hh:mm:ss, or MM/DD/YYYY or hh:mm"
,
"Sorry to be so picky."
)
throw
YailRuntimeError
(
"Argument to MakeInstant should have form MM/DD/YYYY hh:mm:ss, or MM/DD/YYYY or hh:mm"
,
"Sorry to be so picky."
)
}
}
return
_calendar
.
date
(
from
:
components
)
!
return
date
}
}
@objc
public
static
func
MakeInstantFromMillis
(
_
millis
:
Int64
)
->
Date
{
@objc
public
static
func
MakeInstantFromMillis
(
_
millis
:
Int64
)
->
Date
{
...
@@ -252,23 +279,13 @@ open class Clock: NonvisibleComponent, LifecycleDelegate {
...
@@ -252,23 +279,13 @@ open class Clock: NonvisibleComponent, LifecycleDelegate {
return
dateFormatter
.
string
(
from
:
instant
)
return
dateFormatter
.
string
(
from
:
instant
)
}
}
private
func
dateParser
(
_
from
:
String
)
->
DateComponents
?
{
private
func
dateParser
(
_
from
:
String
)
->
Date
?
{
let
dayTimeFormat
=
DateFormatter
()
for
format
in
Clock
.
DATE_FORMATTERS
{
dayTimeFormat
.
dateFormat
=
"MM/dd/yyyy hh:mm:ss"
if
let
date
=
format
.
date
(
from
:
from
)
{
let
dayFormat
=
DateFormatter
()
return
date
dayFormat
.
dateFormat
=
"MM/dd/yyyy"
}
let
timeFormat
=
DateFormatter
()
timeFormat
.
dateFormat
=
"hh:mm"
if
let
date
=
dayTimeFormat
.
date
(
from
:
from
)
{
return
_calendar
.
dateComponents
([
.
month
,
.
day
,
.
year
,
.
hour
,
.
minute
,
.
second
],
from
:
date
)
}
else
if
let
date
=
dayFormat
.
date
(
from
:
from
)
{
return
_calendar
.
dateComponents
([
.
month
,
.
day
,
.
year
],
from
:
date
)
}
else
if
let
date
=
timeFormat
.
date
(
from
:
from
)
{
return
_calendar
.
dateComponents
([
.
hour
,
.
minute
],
from
:
date
)
}
else
{
return
nil
}
}
return
nil
}
}
// MARK: Clock Events
// MARK: Clock Events
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment