Skip to content

Commit

Permalink
not locate on init
Browse files Browse the repository at this point in the history
  • Loading branch information
csbun committed Dec 23, 2015
1 parent 9c809fb commit 6704ee0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
11 changes: 8 additions & 3 deletions dest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var LOCALE_ZH_CN = {
yy: '%s年'
};
// 当前本地化语言对象
var _curentLocale = {};
var _curentLocale = undefined;

/**
* 修改本地化语言
Expand All @@ -85,14 +85,15 @@ function locate(arg) {
} else {
newLocale = arg;
}
if (!_curentLocale) {
_curentLocale = {};
}
for (prop in newLocale) {
if (newLocale.hasOwnProperty(prop) && typeof newLocale[prop] === 'string') {
_curentLocale[prop] = newLocale[prop];
}
}
}
// 初始化本地化语言为 en
locate('');

/**
* CONST for .fromNow
Expand All @@ -112,6 +113,10 @@ var DET_STD = [['yy', 31536e6], // 1000 * 60 * 60 * 24 * 365 一年月按 365
*/
// 只要大于等于 0 都是秒
function fromNow(datetime) {
if (!_curentLocale) {
// 初始化本地化语言为 en
locate('');
}
var det = +new Date() - +getDateObject(datetime);
var format = undefined,
str = undefined,
Expand Down
11 changes: 8 additions & 3 deletions dest/index.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
yy: '%s年'
};
// 当前本地化语言对象
var _curentLocale = {};
var _curentLocale = undefined;

/**
* 修改本地化语言
Expand All @@ -89,14 +89,15 @@
} else {
newLocale = arg;
}
if (!_curentLocale) {
_curentLocale = {};
}
for (prop in newLocale) {
if (newLocale.hasOwnProperty(prop) && typeof newLocale[prop] === 'string') {
_curentLocale[prop] = newLocale[prop];
}
}
}
// 初始化本地化语言为 en
locate('');

/**
* CONST for .fromNow
Expand All @@ -116,6 +117,10 @@
*/
// 只要大于等于 0 都是秒
function fromNow(datetime) {
if (!_curentLocale) {
// 初始化本地化语言为 en
locate('');
}
var det = +new Date() - +getDateObject(datetime);
var format = undefined,
str = undefined,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "silly-datetime",
"version": "0.1.1",
"version": "0.1.2",
"description": "simple datetime formater",
"main": "dest/index.js",
"jsnext:main": "src/index.js",
"scripts": {
"prepublish": "node rollup.js",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
"repository": {
Expand Down
11 changes: 8 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const LOCALE_ZH_CN = {
yy: '%s年'
};
// 当前本地化语言对象
let _curentLocale = {};
let _curentLocale;


/**
Expand All @@ -88,14 +88,15 @@ export function locate(arg) {
} else {
newLocale = arg;
}
if (!_curentLocale) {
_curentLocale = {};
}
for (prop in newLocale) {
if (newLocale.hasOwnProperty(prop) && typeof newLocale[prop] === 'string') {
_curentLocale[prop] = newLocale[prop];
}
}
}
// 初始化本地化语言为 en
locate('');


/**
Expand All @@ -117,6 +118,10 @@ const DET_STD = [
* @return {string} 时间距离
*/
export function fromNow(datetime) {
if (!_curentLocale) {
// 初始化本地化语言为 en
locate('');
}
let det = +new Date() - (+getDateObject(datetime));
let format, str, i = 0, detDef, detDefVal;
if (det < 0) {
Expand Down

0 comments on commit 6704ee0

Please sign in to comment.