@zohodesk/i18n 1.0.0-beta.2 → 1.0.0-beta.20
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/README.md +80 -5
- package/es/I18NContext.js +1 -2
- package/es/components/DateTimeDiffFormat.js +191 -184
- package/es/components/FormatText.js +4 -25
- package/es/components/HOCI18N.js +33 -45
- package/es/components/I18N.js +46 -63
- package/es/components/I18NProvider.js +54 -84
- package/es/components/PluralFormat.js +29 -48
- package/es/components/UserTimeDiffFormat.js +65 -70
- package/es/components/__tests__/DateTimeDiffFormat.spec.js +868 -657
- package/es/components/__tests__/FormatText.spec.js +20 -17
- package/es/components/__tests__/HOCI18N.spec.js +18 -22
- package/es/components/__tests__/I18N.spec.js +20 -19
- package/es/components/__tests__/I18NProvider.spec.js +36 -45
- package/es/components/__tests__/PluralFormat.spec.js +20 -17
- package/es/components/__tests__/UserTimeDiffFormat.spec.js +1343 -1095
- package/es/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/es/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/es/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/es/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/es/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/es/index.js +2 -6
- package/es/utils.js +250 -385
- package/lib/I18NContext.js +6 -6
- package/lib/components/DateTimeDiffFormat.js +166 -123
- package/lib/components/FormatText.js +32 -22
- package/lib/components/HOCI18N.js +47 -23
- package/lib/components/I18N.js +60 -36
- package/lib/components/I18NProvider.js +76 -69
- package/lib/components/PluralFormat.js +42 -32
- package/lib/components/UserTimeDiffFormat.js +81 -54
- package/lib/components/__tests__/DateTimeDiffFormat.spec.js +815 -629
- package/lib/components/__tests__/FormatText.spec.js +23 -25
- package/lib/components/__tests__/HOCI18N.spec.js +26 -34
- package/lib/components/__tests__/I18N.spec.js +21 -26
- package/lib/components/__tests__/I18NProvider.spec.js +43 -51
- package/lib/components/__tests__/PluralFormat.spec.js +24 -28
- package/lib/components/__tests__/UserTimeDiffFormat.spec.js +1256 -1039
- package/lib/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -258
- package/lib/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -15
- package/lib/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -13
- package/lib/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -17
- package/lib/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -366
- package/lib/index.js +73 -119
- package/lib/utils.js +222 -329
- package/package.json +29 -29
- package/src/I18NContext.js +3 -0
- package/src/components/DateTimeDiffFormat.js +256 -0
- package/src/components/FormatText.js +14 -0
- package/src/components/HOCI18N.js +37 -0
- package/src/components/I18N.js +72 -0
- package/src/components/I18NProvider.js +110 -0
- package/src/components/PluralFormat.js +37 -0
- package/src/components/UserTimeDiffFormat.js +97 -0
- package/src/components/__tests__/DateTimeDiffFormat.spec.js +618 -0
- package/src/components/__tests__/FormatText.spec.js +27 -0
- package/src/components/__tests__/HOCI18N.spec.js +33 -0
- package/src/components/__tests__/I18N.spec.js +30 -0
- package/src/components/__tests__/I18NProvider.spec.js +65 -0
- package/src/components/__tests__/PluralFormat.spec.js +28 -0
- package/src/components/__tests__/UserTimeDiffFormat.spec.js +1076 -0
- package/src/components/__tests__/__snapshots__/DateTimeDiffFormat.spec.js.snap +258 -0
- package/src/components/__tests__/__snapshots__/FormatText.spec.js.snap +17 -0
- package/src/components/__tests__/__snapshots__/HOCI18N.spec.js.snap +15 -0
- package/src/components/__tests__/__snapshots__/I18N.spec.js.snap +17 -0
- package/src/components/__tests__/__snapshots__/I18NProvider.spec.js.snap +13 -0
- package/src/components/__tests__/__snapshots__/PluralFormat.spec.js.snap +17 -0
- package/src/components/__tests__/__snapshots__/UserTimeDiffFormat.spec.js.snap +366 -0
- package/src/index.js +33 -0
- package/src/utils.js +527 -0
- package/.DS_Store +0 -0
- package/es/components/NewDateFormat.js +0 -50
- package/es/offset.js +0 -629
- package/es/timezones.js +0 -112
- package/lib/components/NewDateFormat.js +0 -68
- package/lib/offset.js +0 -634
- package/lib/timezones.js +0 -120
package/README.md
CHANGED
|
@@ -1,5 +1,80 @@
|
|
|
1
|
-
# i18n
|
|
2
|
-
|
|
3
|
-
# 1.0.0-beta.
|
|
4
|
-
|
|
5
|
-
-
|
|
1
|
+
# i18n
|
|
2
|
+
|
|
3
|
+
# 1.0.0-beta.20
|
|
4
|
+
|
|
5
|
+
- Date field issue fixed in UserTimeDiffFormat component
|
|
6
|
+
|
|
7
|
+
# 1.0.0-beta.19
|
|
8
|
+
|
|
9
|
+
- In this version we have made changes in i18n provider to call user date format function only if the time zone data is available.
|
|
10
|
+
# 1.0.0-beta.18
|
|
11
|
+
|
|
12
|
+
- Localization feature added and incorporated into getI18NValue Method.
|
|
13
|
+
|
|
14
|
+
# 1.0.0-beta.17
|
|
15
|
+
|
|
16
|
+
- There was some i18n changes done in live before moving the date format build to live. Since we need these changes we have published it as new version.
|
|
17
|
+
|
|
18
|
+
# 1.0.0-beta.16
|
|
19
|
+
|
|
20
|
+
- DatePattern and dateTimePattern key has been changed for the date format build.
|
|
21
|
+
|
|
22
|
+
# 1.0.0-beta.15.1
|
|
23
|
+
|
|
24
|
+
- Zoho security version updated.
|
|
25
|
+
|
|
26
|
+
# 1.0.0-beta.15
|
|
27
|
+
|
|
28
|
+
- When working on date format build we have published I18n. Also, before moving date format build to master we had a emergency fix that need to be sent, so when publishing I18n we have published the date format changes with the next version.
|
|
29
|
+
|
|
30
|
+
# 1.0.0-beta.14
|
|
31
|
+
|
|
32
|
+
- Issue fixed in enable current year.
|
|
33
|
+
|
|
34
|
+
# 1.0.0-beta.13
|
|
35
|
+
|
|
36
|
+
- Issue fixed in due date.
|
|
37
|
+
|
|
38
|
+
# 1.0.0-beta.12
|
|
39
|
+
|
|
40
|
+
- Issue fixed in date Format Pattern.
|
|
41
|
+
|
|
42
|
+
# 1.0.0-beta.11
|
|
43
|
+
|
|
44
|
+
- Date Format Changes
|
|
45
|
+
|
|
46
|
+
# 1.0.0-beta.10
|
|
47
|
+
|
|
48
|
+
- Date Format Issue Fixes
|
|
49
|
+
|
|
50
|
+
# 1.0.0-beta.9
|
|
51
|
+
|
|
52
|
+
- Date Format Changes
|
|
53
|
+
|
|
54
|
+
# 1.0.0-beta.8
|
|
55
|
+
|
|
56
|
+
- ES Module Support Changes
|
|
57
|
+
|
|
58
|
+
# 1.0.0-beta.7
|
|
59
|
+
|
|
60
|
+
- 'userDateFormat' util method - 'others' function fix
|
|
61
|
+
|
|
62
|
+
# 1.0.0-beta.6
|
|
63
|
+
|
|
64
|
+
- Added new prop 'isNeedTime' for DateTimeDiffFormat Component
|
|
65
|
+
|
|
66
|
+
# 1.0.0-beta.5
|
|
67
|
+
|
|
68
|
+
- Timezone logic moved to @zohodesk/datetimejs
|
|
69
|
+
|
|
70
|
+
# 1.0.0-beta.4
|
|
71
|
+
|
|
72
|
+
- Added new prop 'page' for DateTimeDiffFormat Component
|
|
73
|
+
|
|
74
|
+
# 1.0.0-beta.3
|
|
75
|
+
|
|
76
|
+
- Added support for exact times along with relative times in format() function
|
|
77
|
+
|
|
78
|
+
# 1.0.0-beta.0
|
|
79
|
+
|
|
80
|
+
- Test Publish
|
package/es/I18NContext.js
CHANGED
|
@@ -1,204 +1,210 @@
|
|
|
1
|
-
import _typeof from 'babel-runtime/helpers/typeof';
|
|
2
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
3
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
4
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
5
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
6
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
7
1
|
import React from 'react';
|
|
8
2
|
import PropTypes from 'prop-types';
|
|
9
|
-
import { pad, getValues, getDiffObj, formatDate, getLyears,
|
|
3
|
+
import { pad, getValues, getDiffObj, formatDate, getLyears, getDatePatternWithoutYear } from '../utils';
|
|
10
4
|
import FormatText from './FormatText';
|
|
5
|
+
import datetime from '@zohodesk/datetimejs';
|
|
6
|
+
export default class DateTimeDiffFormat extends React.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.getSuffix = this.getSuffix.bind(this);
|
|
10
|
+
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function DateTimeDiffFormat(props) {
|
|
16
|
-
_classCallCheck(this, DateTimeDiffFormat);
|
|
12
|
+
getSuffix(min) {
|
|
13
|
+
let suffix;
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
if (this.props.ago && min < 0) {
|
|
16
|
+
suffix = this.props.ago || '';
|
|
17
|
+
} else if (this.props.later || min > 0) {
|
|
18
|
+
suffix = this.props.later || '';
|
|
19
|
+
} else {
|
|
20
|
+
suffix = '';
|
|
21
|
+
}
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
return _this;
|
|
23
|
+
return suffix;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
render() {
|
|
27
|
+
const {
|
|
28
|
+
type,
|
|
29
|
+
page,
|
|
30
|
+
isNeedTime,
|
|
31
|
+
from,
|
|
32
|
+
fromTzData,
|
|
33
|
+
to,
|
|
34
|
+
toTzData,
|
|
35
|
+
today,
|
|
36
|
+
yesterday,
|
|
37
|
+
tomorrow,
|
|
38
|
+
others,
|
|
39
|
+
format,
|
|
40
|
+
dataId,
|
|
41
|
+
className = null,
|
|
42
|
+
title = null,
|
|
43
|
+
isOverdue,
|
|
44
|
+
timeFormat,
|
|
45
|
+
datePattern,
|
|
46
|
+
isEnabledCurrentYear,
|
|
47
|
+
isDateField
|
|
48
|
+
} = this.props;
|
|
49
|
+
let fromDateObj = datetime.toDate(datetime.tz.utcToTz(from, fromTzData)).getTime();
|
|
50
|
+
let toDateObj = datetime.toDate(isDateField ? to : datetime.tz.utcToTz(to, toTzData)).getTime();
|
|
51
|
+
let diffMin = new Date(to).getTime() - new Date(from).getTime();
|
|
52
|
+
let suffix = this.getSuffix(diffMin);
|
|
53
|
+
let diff = getDiffObj(diffMin);
|
|
54
|
+
let withInAWeak = diff.y === 0 && diff.yd <= 7;
|
|
55
|
+
let diffObj = {
|
|
56
|
+
h: diff.h,
|
|
57
|
+
m: diff.m,
|
|
58
|
+
s: diff.s,
|
|
59
|
+
y: diff.y,
|
|
60
|
+
hh: pad(diff.h, 2),
|
|
61
|
+
mm: pad(diff.m, 2),
|
|
62
|
+
ss: pad(diff.s, 2),
|
|
63
|
+
yy: pad(diff.y, 2),
|
|
64
|
+
days: diff.yd,
|
|
65
|
+
yDays: pad(diff.yd, 2),
|
|
66
|
+
isWithInAWeek: withInAWeak,
|
|
67
|
+
suffix: suffix
|
|
68
|
+
};
|
|
69
|
+
let diffObj1 = {
|
|
70
|
+
to: to,
|
|
71
|
+
type: type,
|
|
72
|
+
page: page,
|
|
73
|
+
isNeedTime: isNeedTime,
|
|
74
|
+
hours: diff.h,
|
|
75
|
+
minutes: diff.m,
|
|
76
|
+
seconds: diff.s,
|
|
77
|
+
years: diff.y,
|
|
78
|
+
yDays: diff.yd,
|
|
79
|
+
isWithInAWeek: withInAWeak,
|
|
80
|
+
suffix: suffix,
|
|
81
|
+
crntDate: new Date(from).getDate(),
|
|
82
|
+
crntMonth: new Date(from).getMonth(),
|
|
83
|
+
crntYear: new Date(from).getFullYear(),
|
|
84
|
+
crntHours: new Date(from).getHours(),
|
|
85
|
+
crntMinutes: new Date(from).getMinutes(),
|
|
86
|
+
crntSeconds: new Date(from).getSeconds(),
|
|
87
|
+
tDate: new Date(to).getDate(),
|
|
88
|
+
tMonth: new Date(to).getMonth(),
|
|
89
|
+
tYear: new Date(to).getFullYear(),
|
|
90
|
+
tHours: new Date(to).getHours(),
|
|
91
|
+
tMinutes: new Date(to).getMinutes(),
|
|
92
|
+
tSeconds: new Date(to).getSeconds(),
|
|
93
|
+
betweenleepYears: getLyears(from, to),
|
|
94
|
+
isOverdue: isOverdue,
|
|
95
|
+
timeFormat: timeFormat,
|
|
96
|
+
datePattern: datePattern,
|
|
97
|
+
dateTimePattern: `${datePattern} ${timeFormat}`
|
|
98
|
+
}; //In if condition we'll remove year and set date format if the current year is not required
|
|
99
|
+
//In else part we'll set the date format as it is
|
|
100
|
+
|
|
101
|
+
if (isEnabledCurrentYear === true && diffObj1.years === 0 && diffObj1.tYear === diffObj1.crntYear) {
|
|
102
|
+
let dateFormat = getDatePatternWithoutYear(datePattern);
|
|
103
|
+
diffObj1.dateFormat = dateFormat;
|
|
104
|
+
diffObj1.dateTimeFormat = `${dateFormat} ${timeFormat}`;
|
|
105
|
+
} else {
|
|
106
|
+
diffObj1.dateFormat = datePattern;
|
|
107
|
+
diffObj1.dateTimeFormat = `${datePattern} ${timeFormat}`;
|
|
36
108
|
}
|
|
37
|
-
|
|
38
|
-
key
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var toDateObj = convertUtcToUserTz(to, toTzData).getTime();
|
|
59
|
-
|
|
60
|
-
var diffMin = new Date(to).getTime() - new Date(from).getTime();
|
|
61
|
-
var suffix = this.getSuffix(diffMin);
|
|
62
|
-
var diff = getDiffObj(diffMin);
|
|
63
|
-
var withInAWeak = diff.y === 0 && diff.yd <= 7;
|
|
64
|
-
|
|
65
|
-
var diffObj = {
|
|
66
|
-
h: diff.h,
|
|
67
|
-
m: diff.m,
|
|
68
|
-
s: diff.s,
|
|
69
|
-
y: diff.y,
|
|
70
|
-
hh: pad(diff.h, 2),
|
|
71
|
-
mm: pad(diff.m, 2),
|
|
72
|
-
ss: pad(diff.s, 2),
|
|
73
|
-
yy: pad(diff.y, 2),
|
|
74
|
-
days: diff.yd,
|
|
75
|
-
yDays: pad(diff.yd, 2),
|
|
76
|
-
isWithInAWeek: withInAWeak,
|
|
77
|
-
suffix: suffix
|
|
78
|
-
};
|
|
79
|
-
var diffObj1 = {
|
|
80
|
-
hours: diff.h,
|
|
81
|
-
minutes: diff.m,
|
|
82
|
-
seconds: diff.s,
|
|
83
|
-
years: diff.y,
|
|
84
|
-
yDays: diff.yd,
|
|
85
|
-
isWithInAWeek: withInAWeak,
|
|
86
|
-
suffix: suffix,
|
|
87
|
-
crntMonth: new Date(to).getMonth(),
|
|
88
|
-
betweenleepYears: getLyears(from, to)
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
var key = '';
|
|
92
|
-
var values = [];
|
|
93
|
-
var text = null;
|
|
94
|
-
var isSuffixEnable = false;
|
|
95
|
-
if (format) {
|
|
96
|
-
var years = void 0,
|
|
97
|
-
months = void 0,
|
|
98
|
-
days = void 0,
|
|
99
|
-
hours = void 0,
|
|
100
|
-
minutes = void 0,
|
|
101
|
-
seconds = void 0;
|
|
102
|
-
years = diffObj1.years > 1 ? '2' : diffObj1.years;
|
|
103
|
-
|
|
104
|
-
days = diff.yd > 1 ? '2' : diff.yd;
|
|
105
|
-
hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
|
|
106
|
-
minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
|
|
107
|
-
|
|
108
|
-
var count = 0;
|
|
109
|
-
var pattern = [years, days, hours, minutes].reduce(function (res, next) {
|
|
110
|
-
if (count === 2) {
|
|
111
|
-
res = res + '0';
|
|
112
|
-
} else if (next !== 0) {
|
|
113
|
-
count++;
|
|
114
|
-
res = res + next;
|
|
115
|
-
} else {
|
|
116
|
-
res = res + next;
|
|
117
|
-
}
|
|
118
|
-
return res;
|
|
119
|
-
}, '');
|
|
120
|
-
|
|
121
|
-
var _value = format(diffObj1, pattern);
|
|
122
|
-
if (_value && (typeof _value === 'undefined' ? 'undefined' : _typeof(_value)) === 'object') {
|
|
123
|
-
key = _value.key;
|
|
124
|
-
values = getValues(_value.params, diffObj);
|
|
125
|
-
if (pattern.indexOf('00000') === 0) {
|
|
126
|
-
//suffix ignore for second hook
|
|
127
|
-
isSuffixEnable = false;
|
|
128
|
-
} else {
|
|
129
|
-
isSuffixEnable = true;
|
|
130
|
-
}
|
|
131
|
-
} else if (typeof _value === 'string') {
|
|
132
|
-
text = formatDate(toDateObj, _value, diffObj1);
|
|
109
|
+
|
|
110
|
+
let key = '';
|
|
111
|
+
let values = [];
|
|
112
|
+
let text = null;
|
|
113
|
+
let isSuffixEnable = false;
|
|
114
|
+
|
|
115
|
+
if (format) {
|
|
116
|
+
let years, months, days, hours, minutes, seconds;
|
|
117
|
+
years = diffObj1.years > 1 ? '2' : diffObj1.years;
|
|
118
|
+
days = diff.yd > 1 ? '2' : diff.yd;
|
|
119
|
+
hours = diffObj1.hours > 1 ? '2' : diffObj1.hours;
|
|
120
|
+
minutes = diffObj1.minutes > 1 ? '2' : diffObj1.minutes;
|
|
121
|
+
let count = 0;
|
|
122
|
+
let pattern = [years, days, hours, minutes].reduce((res, next) => {
|
|
123
|
+
if (count === 2) {
|
|
124
|
+
res = `${res}0`;
|
|
125
|
+
} else if (next !== 0) {
|
|
126
|
+
count++;
|
|
127
|
+
res = res + next;
|
|
128
|
+
} else {
|
|
129
|
+
res = res + next;
|
|
133
130
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
isSuffixEnable = true;
|
|
147
|
-
} else if (typeof today === 'string') {
|
|
148
|
-
text = formatDate(toDateObj, today);
|
|
149
|
-
}
|
|
150
|
-
} else if (dateObj.getDate() < curDateObj.getDate()) {
|
|
151
|
-
if (typeof yesterday === 'function') {
|
|
152
|
-
var value = yesterday(diffObj1);
|
|
153
|
-
key = value.key;
|
|
154
|
-
values = getValues(value.params, diffObj);
|
|
155
|
-
} else if ((typeof yesterday === 'undefined' ? 'undefined' : _typeof(yesterday)) === 'object') {
|
|
156
|
-
key = yesterday.key;
|
|
157
|
-
values = getValues(yesterday.params, diffObj);
|
|
158
|
-
} else if (typeof yesterday === 'string') {
|
|
159
|
-
text = formatDate(toDateObj, yesterday);
|
|
160
|
-
}
|
|
161
|
-
} else if (dateObj.getDate() > curDateObj.getDate()) {
|
|
162
|
-
if (typeof tomorrow === 'function') {
|
|
163
|
-
var value = tomorrow(diffObj1);
|
|
164
|
-
key = value.key;
|
|
165
|
-
text = getValues(value.params, diffObj);
|
|
166
|
-
} else if ((typeof tomorrow === 'undefined' ? 'undefined' : _typeof(tomorrow)) === 'object') {
|
|
167
|
-
key = tomorrow.key;
|
|
168
|
-
values = getValues(tomorrow.params, diffObj);
|
|
169
|
-
} else if (typeof tomorrow === 'string') {
|
|
170
|
-
text = formatDate(toDateObj, tomorrow);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
131
|
+
|
|
132
|
+
return res;
|
|
133
|
+
}, '');
|
|
134
|
+
let value = format(diffObj1, pattern);
|
|
135
|
+
|
|
136
|
+
if (value && typeof value === 'object') {
|
|
137
|
+
key = value.key;
|
|
138
|
+
values = getValues(value.params, diffObj);
|
|
139
|
+
|
|
140
|
+
if (pattern.indexOf('00000') === 0) {
|
|
141
|
+
//suffix ignore for second hook
|
|
142
|
+
isSuffixEnable = false;
|
|
173
143
|
} else {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
144
|
+
isSuffixEnable = true;
|
|
145
|
+
}
|
|
146
|
+
} else if (typeof value === 'string') {
|
|
147
|
+
text = formatDate(toDateObj, value, diffObj1);
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
let dateObj = new Date(toDateObj);
|
|
151
|
+
let curDateObj = new Date(fromDateObj);
|
|
152
|
+
let diffDayType = diffObj1.yDays; //In this condition, to calculate different days we have copied it from live --> diffDayType
|
|
153
|
+
|
|
154
|
+
if (isOverdue && dateObj.getDate() < curDateObj.getDate() && diffObj1.yDays == 0) {
|
|
155
|
+
diffDayType = -1;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!isOverdue) {
|
|
159
|
+
let diffHr = dateObj.getHours() - curDateObj.getHours();
|
|
160
|
+
|
|
161
|
+
if (diffHr < 0) {
|
|
162
|
+
diffDayType += 1;
|
|
163
|
+
} else if (diffHr == 0) {
|
|
164
|
+
let diffMins = dateObj.getMinutes() - curDateObj.getMinutes();
|
|
165
|
+
|
|
166
|
+
if (diffMins < 0) {
|
|
167
|
+
diffDayType += 1;
|
|
168
|
+
} else if (diffMins == 0) {
|
|
169
|
+
let diffSec = dateObj.getSeconds() - curDateObj.getSeconds();
|
|
170
|
+
|
|
171
|
+
if (diffSec < 0) {
|
|
172
|
+
diffDayType += 1;
|
|
173
|
+
}
|
|
181
174
|
}
|
|
182
175
|
}
|
|
183
176
|
}
|
|
184
|
-
return text ? React.createElement(
|
|
185
|
-
'span',
|
|
186
|
-
{ className: className, 'data-title': title, 'data-id': dataId },
|
|
187
|
-
text
|
|
188
|
-
) : React.createElement(FormatText, {
|
|
189
|
-
i18NKey: isSuffixEnable && suffix !== '' ? key + '.' + suffix : key,
|
|
190
|
-
values: values,
|
|
191
|
-
className: className,
|
|
192
|
-
'data-title': title
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}]);
|
|
196
177
|
|
|
197
|
-
|
|
198
|
-
|
|
178
|
+
if (diff.y === 0 && (diffDayType === 0 || diffDayType === 1)) {
|
|
179
|
+
if (dateObj.getDate() === curDateObj.getDate()) {
|
|
180
|
+
var value = today && today(diffObj1) || others(diffObj1);
|
|
181
|
+
text = formatDate(toDateObj, value);
|
|
182
|
+
} else if (dateObj.getMonth() === curDateObj.getMonth() && dateObj.getDate() < curDateObj.getDate() || dateObj.getMonth() < curDateObj.getMonth()) {
|
|
183
|
+
var value = yesterday && yesterday(diffObj1) || others(diffObj1);
|
|
184
|
+
text = formatDate(toDateObj, value);
|
|
185
|
+
} else if (!isOverdue && diff.y === 0 && diffDayType === 1) {
|
|
186
|
+
var value = tomorrow && tomorrow(diffObj1) || others(diffObj1);
|
|
187
|
+
text = formatDate(toDateObj, value);
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
var value = others(diffObj1);
|
|
191
|
+
text = formatDate(toDateObj, value);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
199
194
|
|
|
200
|
-
|
|
195
|
+
return text ? /*#__PURE__*/React.createElement("span", {
|
|
196
|
+
className: className,
|
|
197
|
+
"data-title": title,
|
|
198
|
+
"data-id": dataId
|
|
199
|
+
}, text) : /*#__PURE__*/React.createElement(FormatText, {
|
|
200
|
+
i18NKey: isSuffixEnable && suffix !== '' ? `${key}.${suffix}` : key,
|
|
201
|
+
values: values,
|
|
202
|
+
className: className,
|
|
203
|
+
"data-title": title
|
|
204
|
+
});
|
|
205
|
+
}
|
|
201
206
|
|
|
207
|
+
}
|
|
202
208
|
DateTimeDiffFormat.propTypes = {
|
|
203
209
|
ago: PropTypes.string,
|
|
204
210
|
className: PropTypes.string,
|
|
@@ -206,6 +212,7 @@ DateTimeDiffFormat.propTypes = {
|
|
|
206
212
|
format: PropTypes.func,
|
|
207
213
|
from: PropTypes.string,
|
|
208
214
|
fromTzData: PropTypes.object,
|
|
215
|
+
isDateField: PropTypes.bool,
|
|
209
216
|
later: PropTypes.string,
|
|
210
217
|
others: PropTypes.func,
|
|
211
218
|
title: PropTypes.string,
|
|
@@ -1,33 +1,12 @@
|
|
|
1
|
-
import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
|
|
2
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
3
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
4
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
5
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
6
1
|
import React from 'react';
|
|
7
2
|
import PropTypes from 'prop-types';
|
|
8
3
|
import I18N from './I18N';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function FormatText() {
|
|
14
|
-
_classCallCheck(this, FormatText);
|
|
15
|
-
|
|
16
|
-
return _possibleConstructorReturn(this, (FormatText.__proto__ || _Object$getPrototypeOf(FormatText)).apply(this, arguments));
|
|
4
|
+
export default class FormatText extends React.Component {
|
|
5
|
+
render() {
|
|
6
|
+
return /*#__PURE__*/React.createElement(I18N, this.props);
|
|
17
7
|
}
|
|
18
8
|
|
|
19
|
-
|
|
20
|
-
key: 'render',
|
|
21
|
-
value: function render() {
|
|
22
|
-
return React.createElement(I18N, this.props);
|
|
23
|
-
}
|
|
24
|
-
}]);
|
|
25
|
-
|
|
26
|
-
return FormatText;
|
|
27
|
-
}(React.Component);
|
|
28
|
-
|
|
29
|
-
export default FormatText;
|
|
30
|
-
|
|
9
|
+
}
|
|
31
10
|
FormatText.propTypes = {
|
|
32
11
|
i18NKey: PropTypes.string.isRequired,
|
|
33
12
|
isHtml: PropTypes.bool,
|
package/es/components/HOCI18N.js
CHANGED
|
@@ -1,60 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
|
4
|
-
import _createClass from 'babel-runtime/helpers/createClass';
|
|
5
|
-
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
|
6
|
-
import _inherits from 'babel-runtime/helpers/inherits';
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
7
3
|
import React, { Children } from 'react';
|
|
8
4
|
import PropTypes from 'prop-types';
|
|
9
5
|
import { replaceI18NValuesWithRegex, unescapeUnicode } from '../utils';
|
|
10
6
|
import { I18NContext } from '../I18NContext';
|
|
11
7
|
export default (function () {
|
|
12
|
-
|
|
13
|
-
return
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
let i18NKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
9
|
+
return Component => {
|
|
10
|
+
class HOCI18N extends React.Component {
|
|
11
|
+
constructor(props) {
|
|
12
|
+
super(props);
|
|
13
|
+
this.getI18NValue = this.getI18NValue.bind(this);
|
|
14
|
+
}
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
getI18NValue(key) {
|
|
17
|
+
const {
|
|
18
|
+
i18n
|
|
19
|
+
} = this.context || {};
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
if (typeof i18n === 'undefined') {
|
|
22
|
+
return key;
|
|
23
|
+
}
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
return _this;
|
|
24
|
-
}
|
|
25
|
+
let i18nStr = i18n[key];
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var _ref = this.context || {},
|
|
30
|
-
i18n = _ref.i18n;
|
|
27
|
+
if (i18nStr === undefined) {
|
|
28
|
+
return key;
|
|
29
|
+
}
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
return unescapeUnicode(i18nStr);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
render() {
|
|
35
|
+
let i18nProps = i18NKeys.reduce((result, key) => {
|
|
36
|
+
if (this.props[key]) {
|
|
37
|
+
result[key] = this.getI18NValue(this.props[key]);
|
|
38
38
|
}
|
|
39
|
-
return unescapeUnicode(i18nStr);
|
|
40
|
-
}
|
|
41
|
-
}, {
|
|
42
|
-
key: 'render',
|
|
43
|
-
value: function render() {
|
|
44
|
-
var _this2 = this;
|
|
45
|
-
|
|
46
|
-
var i18nProps = i18NKeys.reduce(function (result, key) {
|
|
47
|
-
if (_this2.props[key]) {
|
|
48
|
-
result[key] = _this2.getI18NValue(_this2.props[key]);
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
}, {});
|
|
52
|
-
return React.createElement(Component, _extends({}, this.props, i18nProps));
|
|
53
|
-
}
|
|
54
|
-
}]);
|
|
55
39
|
|
|
56
|
-
|
|
57
|
-
|
|
40
|
+
return result;
|
|
41
|
+
}, {});
|
|
42
|
+
return /*#__PURE__*/React.createElement(Component, _extends({}, this.props, i18nProps));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
}
|
|
58
46
|
|
|
59
47
|
HOCI18N.contextType = I18NContext;
|
|
60
48
|
return HOCI18N;
|