@outliant/sunrise-utils 1.1.9 → 1.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,8 +4,16 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [1.1.10](https://github.com/outliant/sunrise-utils/compare/1.1.9...1.1.10)
8
+
9
+ - chore: add days to complete function [`#15`](https://github.com/outliant/sunrise-utils/pull/15)
10
+ - chore: fix test [`8202713`](https://github.com/outliant/sunrise-utils/commit/8202713cafa50ee4ad6978ffcf588e93e821b429)
11
+ - chore: add type and remove console [`8bb18ae`](https://github.com/outliant/sunrise-utils/commit/8bb18ae2ff3e37fcee5f66f8b57cf7a1d45f3dad)
12
+
7
13
  #### [1.1.9](https://github.com/outliant/sunrise-utils/compare/1.1.8...1.1.9)
8
14
 
15
+ > 3 October 2023
16
+
9
17
  - Task/task new columns #85ztbmnkf [`#14`](https://github.com/outliant/sunrise-utils/pull/14)
10
18
  - chore: add filter for days to complete [`f2fdf97`](https://github.com/outliant/sunrise-utils/commit/f2fdf977c6b5c5f22c17b3fffb7a6a2024a3c38c)
11
19
  - chore: add test [`847deb3`](https://github.com/outliant/sunrise-utils/commit/847deb3d2eebba343b865bb69cb6dc642096160d)
@@ -16,8 +16,21 @@ const commonOperatorTemplate = (conditionCallback) => {
16
16
  return false;
17
17
  }
18
18
 
19
- def readyAt = doc['ready_at'].value.toInstant().toEpochMilli();
20
- def completedAt = doc['completed_at'].value.toInstant().toEpochMilli();
19
+ def readyAt = doc['ready_at'].value
20
+ .toInstant()
21
+ .atZone(ZoneId.of('UTC'))
22
+ .toLocalDate()
23
+ .atStartOfDay(ZoneId.of('UTC'))
24
+ .toInstant()
25
+ .toEpochMilli();
26
+
27
+ def completedAt = doc['completed_at'].value
28
+ .toInstant()
29
+ .atZone(ZoneId.of('UTC'))
30
+ .toLocalDate()
31
+ .atStartOfDay(ZoneId.of('UTC'))
32
+ .toInstant()
33
+ .toEpochMilli();
21
34
 
22
35
  if (readyAt == null || completedAt == null) {
23
36
  return false;
package/index.d.ts CHANGED
@@ -54,6 +54,7 @@ declare namespace Utils {
54
54
  export function buildSortScript(query?: Query, customSort?: any[]): any;
55
55
  export function getTaskAge(task: any): any;
56
56
  export function getTaskAgeColor(task: any): any;
57
+ export function getDaysToComplete(task: any): undefined | number;
57
58
  }
58
59
 
59
60
  namespace projectPipeline {
@@ -172,6 +172,21 @@ class TaskPipeline {
172
172
  return null;
173
173
  }
174
174
 
175
+ getDaysToComplete = (task) => {
176
+ if (!task.ready_at || !task.completed_at) {
177
+ return;
178
+ }
179
+
180
+ const readyAt = moment(task.ready_at)
181
+ .utc()
182
+ .startOf('day');
183
+ const completedAt = moment(task.completed_at)
184
+ .utc()
185
+ .startOf('day');
186
+
187
+ return completedAt.diff(readyAt, 'days');
188
+ };
189
+
175
190
  getTaskAgeColor(task) {
176
191
  const taskAge = this.getTaskAge(task);
177
192
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@outliant/sunrise-utils",
3
3
  "description": "Helper functions for project Sunrise",
4
- "version": "1.1.9",
4
+ "version": "1.1.10",
5
5
  "license": "ISC",
6
6
  "author": "Outliant",
7
7
  "main": "index.js",
@@ -24,7 +24,7 @@ describe('taskFilter/daysToComplete', function () {
24
24
  expected: {
25
25
  script: {
26
26
  script: {
27
- source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value.toInstant().toEpochMilli();\n def completedAt = doc['completed_at'].value.toInstant().toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return daysToComplete != params.value\n } catch (Exception err) {\n return false;\n }\n ",
27
+ source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n def completedAt = doc['completed_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return daysToComplete != params.value\n } catch (Exception err) {\n return false;\n }\n ",
28
28
  lang: "painless",
29
29
  params: {
30
30
  value: 1
@@ -41,7 +41,7 @@ describe('taskFilter/daysToComplete', function () {
41
41
  expected: {
42
42
  script: {
43
43
  script: {
44
- source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value.toInstant().toEpochMilli();\n def completedAt = doc['completed_at'].value.toInstant().toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return daysToComplete < params.value\n } catch (Exception err) {\n return false;\n }\n ",
44
+ source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n def completedAt = doc['completed_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return daysToComplete < params.value\n } catch (Exception err) {\n return false;\n }\n ",
45
45
  lang: "painless",
46
46
  params: {
47
47
  value: 1
@@ -58,7 +58,7 @@ describe('taskFilter/daysToComplete', function () {
58
58
  expected: {
59
59
  script: {
60
60
  script: {
61
- source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value.toInstant().toEpochMilli();\n def completedAt = doc['completed_at'].value.toInstant().toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return daysToComplete <= params.value\n } catch (Exception err) {\n return false;\n }\n ",
61
+ source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n def completedAt = doc['completed_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return daysToComplete <= params.value\n } catch (Exception err) {\n return false;\n }\n ",
62
62
  lang: "painless",
63
63
  params: {
64
64
  value: 1,
@@ -76,7 +76,7 @@ describe('taskFilter/daysToComplete', function () {
76
76
  expected: {
77
77
  script: {
78
78
  script: {
79
- source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value.toInstant().toEpochMilli();\n def completedAt = doc['completed_at'].value.toInstant().toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return daysToComplete > params.value\n } catch (Exception err) {\n return false;\n }\n ",
79
+ source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n def completedAt = doc['completed_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return daysToComplete > params.value\n } catch (Exception err) {\n return false;\n }\n ",
80
80
  lang: "painless",
81
81
  params: {
82
82
  value: 1
@@ -93,7 +93,7 @@ describe('taskFilter/daysToComplete', function () {
93
93
  expected: {
94
94
  script: {
95
95
  script: {
96
- source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value.toInstant().toEpochMilli();\n def completedAt = doc['completed_at'].value.toInstant().toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return daysToComplete >= params.value\n } catch (Exception err) {\n return false;\n }\n ",
96
+ source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n def completedAt = doc['completed_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return daysToComplete >= params.value\n } catch (Exception err) {\n return false;\n }\n ",
97
97
  lang: "painless",
98
98
  params: {
99
99
  value: 1
@@ -110,7 +110,7 @@ describe('taskFilter/daysToComplete', function () {
110
110
  expected: {
111
111
  script: {
112
112
  script: {
113
- source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value.toInstant().toEpochMilli();\n def completedAt = doc['completed_at'].value.toInstant().toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return \n daysToComplete >= params.value &&\n daysToComplete <= params.second_value\n \n } catch (Exception err) {\n return false;\n }\n ",
113
+ source: "\n try {\n def isEmptyReadyAt = doc.containsKey('ready_at') && doc['ready_at'].empty;\n def isEmptyCompletedAt = doc.containsKey('completed_at') && doc['completed_at'].empty;\n\n if (isEmptyReadyAt || isEmptyCompletedAt) {\n return false;\n }\n\n def readyAt = doc['ready_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n def completedAt = doc['completed_at'].value\n .toInstant()\n .atZone(ZoneId.of('UTC'))\n .toLocalDate()\n .atStartOfDay(ZoneId.of('UTC'))\n .toInstant()\n .toEpochMilli();\n\n if (readyAt == null || completedAt == null) {\n return false;\n }\n\n def daysToComplete = (completedAt - readyAt) / (1000 * 3600 * 24);\n\n return \n daysToComplete >= params.value &&\n daysToComplete <= params.second_value\n \n } catch (Exception err) {\n return false;\n }\n ",
114
114
  lang: "painless",
115
115
  params: {
116
116
  value: 1,