Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cordova-plugin-local-notifications
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nabil Sadki
cordova-plugin-local-notifications
Commits
404db4f3
Commit
404db4f3
authored
Sep 30, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accurate way to calculate the next trigger date for fixed triggers
parent
dbb83bbe
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
65 deletions
+48
-65
Trigger.cs
...Proxy/LocalNotificationProxy/LocalNotification/Trigger.cs
+48
-65
LocalNotificationProxy.winmd
src/windows/lib.UW/ARM/LocalNotificationProxy.winmd
+0
-0
LocalNotificationProxy.winmd
src/windows/lib.UW/x64/LocalNotificationProxy.winmd
+0
-0
LocalNotificationProxy.winmd
src/windows/lib.UW/x86/LocalNotificationProxy.winmd
+0
-0
No files found.
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/Trigger.cs
View file @
404db4f3
...
@@ -27,7 +27,6 @@ namespace LocalNotificationProxy.LocalNotification
...
@@ -27,7 +27,6 @@ namespace LocalNotificationProxy.LocalNotification
public
sealed
class
Trigger
public
sealed
class
Trigger
{
{
private
DateTime
?
triggerDate
;
private
DateTime
?
triggerDate
;
private
TimeSpan
?
triggerInterval
;
/// <summary>
/// <summary>
/// Gets trigger type.
/// Gets trigger type.
...
@@ -66,81 +65,19 @@ namespace LocalNotificationProxy.LocalNotification
...
@@ -66,81 +65,19 @@ namespace LocalNotificationProxy.LocalNotification
{
{
get
get
{
{
var
minDate
=
DateTime
.
Now
.
AddSeconds
(
0.1
);
if
(!
this
.
triggerDate
.
HasValue
)
if
(!
this
.
triggerDate
.
HasValue
)
{
{
this
.
triggerDate
=
this
.
Every
is
Every
?
this
.
GetRelDate
()
:
this
.
GetFixDate
();
this
.
triggerDate
=
this
.
Every
is
Every
?
this
.
GetRelDate
()
:
this
.
GetFixDate
();
}
}
var
ticks
=
this
.
Interval
.
Ticks
*
(
this
.
Occurrence
-
1
);
var
date
=
this
.
GetNextTriggerDate
(
);
var
date
=
this
.
triggerDate
.
Value
.
AddTicks
(
ticks
);
var
minDate
=
DateTime
.
Now
.
AddSeconds
(
0.1
);
return
(
date
<
minDate
)
?
minDate
:
date
;
return
(
date
<
minDate
)
?
minDate
:
date
;
}
}
}
}
/// <summary>
/// <summary>
/// Gets the parsed repeat interval.
/// </summary>
internal
TimeSpan
Interval
{
get
{
if
(
this
.
triggerInterval
.
HasValue
)
{
return
this
.
triggerInterval
.
Value
;
}
var
every
=
this
.
Every
is
Every
?
(
this
.
Every
as
Every
).
Interval
:
this
.
Every
;
try
{
switch
(
every
)
{
case
null
:
case
""
:
this
.
triggerInterval
=
TimeSpan
.
Zero
;
break
;
case
"second"
:
this
.
triggerInterval
=
new
TimeSpan
(
TimeSpan
.
TicksPerSecond
);
break
;
case
"minute"
:
this
.
triggerInterval
=
new
TimeSpan
(
TimeSpan
.
TicksPerMinute
);
break
;
case
"hour"
:
this
.
triggerInterval
=
new
TimeSpan
(
TimeSpan
.
TicksPerHour
);
break
;
case
"day"
:
this
.
triggerInterval
=
new
TimeSpan
(
TimeSpan
.
TicksPerDay
);
break
;
case
"week"
:
this
.
triggerInterval
=
new
TimeSpan
(
TimeSpan
.
TicksPerDay
*
7
);
break
;
case
"month"
:
this
.
triggerInterval
=
new
TimeSpan
(
TimeSpan
.
TicksPerDay
*
31
);
break
;
case
"quarter"
:
this
.
triggerInterval
=
new
TimeSpan
(
TimeSpan
.
TicksPerHour
*
2190
);
break
;
case
"year"
:
this
.
triggerInterval
=
new
TimeSpan
(
TimeSpan
.
TicksPerDay
*
365
);
break
;
default
:
this
.
triggerInterval
=
TimeSpan
.
FromSeconds
(
60
*
int
.
Parse
(
every
as
string
));
break
;
}
}
catch
{
this
.
triggerInterval
=
TimeSpan
.
Zero
;
}
return
this
.
triggerInterval
.
Value
;
}
}
/// <summary>
/// Deserializes the XML string into an instance of Trigger.
/// Deserializes the XML string into an instance of Trigger.
/// </summary>
/// </summary>
/// <param name="xml">The serialized instance of Options as an xml string.</param>
/// <param name="xml">The serialized instance of Options as an xml string.</param>
...
@@ -305,5 +242,51 @@ namespace LocalNotificationProxy.LocalNotification
...
@@ -305,5 +242,51 @@ namespace LocalNotificationProxy.LocalNotification
return
date
;
return
date
;
}
}
/// <summary>
/// Calculates the next trigger date by adding (interval * occurence)
/// </summary>
/// <returns>The next valid trigger date</returns>
private
DateTime
GetNextTriggerDate
()
{
var
every
=
this
.
Every
is
Every
?
(
this
.
Every
as
Every
).
Interval
:
this
.
Every
;
var
date
=
this
.
triggerDate
.
Value
;
var
multiple
=
this
.
Occurrence
-
1
;
if
(
multiple
==
0
)
{
return
date
;
}
switch
(
every
)
{
case
null
:
case
""
:
return
date
;
case
"minute"
:
return
date
.
AddMinutes
(
multiple
*
1
);
case
"hour"
:
return
date
.
AddHours
(
multiple
*
1
);
case
"day"
:
return
date
.
AddDays
(
multiple
*
1
);
case
"week"
:
return
date
.
AddDays
(
multiple
*
7
);
case
"month"
:
return
date
.
AddMonths
(
multiple
*
1
);
case
"quarter"
:
return
date
.
AddMonths
(
multiple
*
3
);
case
"year"
:
return
date
.
AddYears
(
multiple
*
1
);
}
try
{
return
date
.
AddSeconds
(
multiple
*
(
60
*
int
.
Parse
(
every
as
string
)));
}
catch
{
return
date
;
}
}
}
}
}
}
src/windows/lib.UW/ARM/LocalNotificationProxy.winmd
View file @
404db4f3
No preview for this file type
src/windows/lib.UW/x64/LocalNotificationProxy.winmd
View file @
404db4f3
No preview for this file type
src/windows/lib.UW/x86/LocalNotificationProxy.winmd
View file @
404db4f3
No preview for this file type
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