@becollective/utils 1.5.2 → 1.5.5

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/bundle.js CHANGED
@@ -38,7 +38,7 @@ var password = {
38
38
  }
39
39
  };
40
40
 
41
- var moment = require('moment');
41
+ var moment = require('moment-timezone');
42
42
  /**
43
43
  * Get current age based on the given birth date
44
44
  * @param {string} dateOfBirth
@@ -87,6 +87,16 @@ var datesByThemselves = function datesByThemselves(a, b) {
87
87
  if (!a.from) return 1;
88
88
  return moment(a.from) - moment(b.from);
89
89
  };
90
+ var getShiftText = function getShiftText(from, to, timezone) {
91
+ try {
92
+ if (!from || !to || !timezone) return '';
93
+ var startToTimezone = moment(from).tz(timezone);
94
+ var endToTimezone = moment(to).tz(timezone);
95
+ return "".concat(moment(startToTimezone).format('dddd, DD MMMM YYYY, h:mma'), "-").concat(moment(endToTimezone).format('h:mma'));
96
+ } catch (e) {
97
+ return '';
98
+ }
99
+ };
90
100
 
91
101
  var _require = require('@becollective/constants'),
92
102
  currencies = _require.currencies; // We should probably throw and error on bad input instead of falling back to a default.
@@ -148,8 +158,8 @@ var _TYPE_MAP;
148
158
  var _require$1 = require('@becollective/constants'),
149
159
  opportunities = _require$1.opportunities;
150
160
 
151
- var opportunityTypes = opportunities.typesMap;
152
- var TYPE_MAP = (_TYPE_MAP = {}, _defineProperty(_TYPE_MAP, opportunityTypes.roleFlexible, 'One-Off Task'), _defineProperty(_TYPE_MAP, opportunityTypes.roleFixed, 'Shift(s)'), _defineProperty(_TYPE_MAP, opportunityTypes.ongoing, 'Ongoing'), _TYPE_MAP);
161
+ var opportunityTypes = opportunities.typesMapV2;
162
+ var TYPE_MAP = (_TYPE_MAP = {}, _defineProperty(_TYPE_MAP, opportunityTypes.shift, 'Shifts'), _defineProperty(_TYPE_MAP, opportunityTypes.flexible, 'Flexible'), _TYPE_MAP);
153
163
  var readableOpportunityType = function readableOpportunityType(type) {
154
164
  return TYPE_MAP[type] || null;
155
165
  };
@@ -199,6 +209,7 @@ var util = {
199
209
  },
200
210
  readableOpportunityType: readableOpportunityType,
201
211
  getTimeInfo: getTimeInfo,
202
- getHomeLocalityFromLocationList: getHomeLocalityFromLocationList
212
+ getHomeLocalityFromLocationList: getHomeLocalityFromLocationList,
213
+ getShiftText: getShiftText
203
214
  };
204
215
  module.exports = util;
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { password } from './src/password';
2
- import { isUnderSixteen, getAge, datesByThemselves } from './src/date-time';
2
+ import { isUnderSixteen, getAge, datesByThemselves, getShiftText } from './src/date-time';
3
3
  import { getCurrencyFromCurrencyCode, makeMoneyString } from './src/money';
4
4
  import { readableOpportunityType } from './src/opportunity';
5
5
  import { getTimeInfo } from './src/opportunityUser';
@@ -17,6 +17,7 @@ const util = {
17
17
  readableOpportunityType,
18
18
  getTimeInfo,
19
19
  getHomeLocalityFromLocationList,
20
+ getShiftText,
20
21
  };
21
22
 
22
23
  module.exports = util;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@becollective/utils",
3
- "version": "1.5.2",
3
+ "version": "1.5.5",
4
4
  "description": "Common utilities",
5
5
  "main": "bundle.js",
6
6
  "scripts": {
@@ -19,9 +19,10 @@
19
19
  "rollup-plugin-node-resolve": "^3.4.0"
20
20
  },
21
21
  "dependencies": {
22
- "@becollective/constants": "^3.6.3",
22
+ "@becollective/constants": "^3.11.0",
23
23
  "lodash": "^4.17.15",
24
- "moment": "^2.24.0"
24
+ "moment": "^2.24.0",
25
+ "moment-timezone": "^0.5.26"
25
26
  },
26
27
  "jest": {
27
28
  "testMatch": [
package/src/date-time.js CHANGED
@@ -1,4 +1,4 @@
1
- const moment = require('moment');
1
+ const moment = require('moment-timezone');
2
2
 
3
3
  /**
4
4
  * Get current age based on the given birth date
@@ -42,3 +42,14 @@ export const datesByThemselves = (a, b) => {
42
42
  if (!a.from) return 1;
43
43
  return moment(a.from) - moment(b.from);
44
44
  };
45
+
46
+ export const getShiftText = (from, to, timezone) => {
47
+ try {
48
+ if (!from || !to || !timezone) return '';
49
+ const startToTimezone = moment(from).tz(timezone);
50
+ const endToTimezone = moment(to).tz(timezone);
51
+ return `${moment(startToTimezone).format('dddd, DD MMMM YYYY, h:mma')}-${moment(endToTimezone).format('h:mma')}`;
52
+ } catch (e) {
53
+ return '';
54
+ }
55
+ };
@@ -1,4 +1,4 @@
1
- const { isUnderSixteen, getAge } = require('../bundle.js');
1
+ const { isUnderSixteen, getAge, getShiftText } = require('../bundle.js');
2
2
  const moment = require('moment');
3
3
 
4
4
  describe('getAge', () => {
@@ -54,3 +54,19 @@ describe('isUnderSixteen', () => {
54
54
  expect(isUnderSixteen('not-valid')).toBe(false);
55
55
  });
56
56
  });
57
+
58
+ describe('getShiftText', () => {
59
+ const from = new Date(Date.UTC(2020, 6, 30, 0, 0, 0));
60
+ const to = new Date(Date.UTC(2020, 6, 30, 5, 30, 0));
61
+ const melbourne = 'Australia/Melbourne';
62
+ const auckland = 'Pacific/Auckland';
63
+ test('get shift text with melbourne timezone', () => {
64
+ expect(getShiftText(from, to,melbourne)).toBe("Thursday, 30 July 2020, 10:00am-3:30pm");
65
+ });
66
+ test('get shift text with auckland timezone', () => {
67
+ expect(getShiftText(from, to,auckland)).toBe("Thursday, 30 July 2020, 12:00pm-5:30pm");
68
+ });
69
+ test('with empty data', () => {
70
+ expect(getShiftText()).toBe('');
71
+ });
72
+ });
@@ -1,10 +1,9 @@
1
1
  const { opportunities } = require('@becollective/constants');
2
- const { typesMap: opportunityTypes } = opportunities;
2
+ const { typesMapV2: opportunityTypes } = opportunities;
3
3
 
4
4
  const TYPE_MAP = {
5
- [opportunityTypes.roleFlexible]: 'One-Off Task',
6
- [opportunityTypes.roleFixed]: 'Shift(s)',
7
- [opportunityTypes.ongoing]: 'Ongoing',
5
+ [opportunityTypes.shift]: 'Shifts',
6
+ [opportunityTypes.flexible]: 'Flexible',
8
7
  };
9
8
 
10
9
  export const readableOpportunityType = type => TYPE_MAP[type] || null;