Skip to content

Commit

Permalink
ax5core 0.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasJang committed Jan 31, 2016
1 parent f758384 commit 4984ac9
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 39 deletions.
13 changes: 13 additions & 0 deletions API-ax5-util.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ ax5.util.isUndefined();

// return is undefined|''|null.
ax5.util.isNothing();

// return is Date
ax5.util.isDate();

```

## ax5.util.isDateFormat
`ax5.util.isDateFormat(String)`

```js
console.log(ax5.util.isDateFormat('20160101')); // true
console.log(ax5.util.isDateFormat('2016*01*01')); // true
console.log(ax5.util.isDateFormat('20161132')); // false
```

---
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ax5core",
"version": "0.7.3",
"version": "0.7.4",
"authors": [
"ThomasJ <[email protected]>"
],
Expand Down
102 changes: 71 additions & 31 deletions dist/ax5core.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,33 @@
return (typeof O === "undefined" || O === null || O === "");
}

function isDate(O) {
return (O instanceof Date && !isNaN(O.valueOf()));
}

function isDateFormat(O) {
var
result = false
;
if (O instanceof Date && !isNaN(O.valueOf())) {
result = true;
}
else {
O = O.replace(/\D/g, '');
if (O.length > 7) {
var
mm = O.substr(4, 2),
dd = O.substr(6, 2)
;
O = date(O);
if (O.getMonth() == (mm - 1) && O.getDate() == dd) {
result = true;
}
}
}
return result;
}

/**
* 오브젝트의 첫번째 아이템을 반환합니다.
* @method ax5.util.first
Expand Down Expand Up @@ -1453,6 +1480,15 @@
* @param {String|Data} d
* @param {Object} cond
* @returns {Number}
* @example
* ```js
* ax5.util.dday('2016-01-29');
* // 1
* ax5.util.dday('2016-01-29', {today:'2016-01-28'});
* // 1
* ax5.util.dday('1977-03-29', {today:'2016-01-28', age:true});
* // 39
* ```
*/
function dday(d, cond) {
var memoryDay = date(d), DyMilli = ((1000 * 60) * 60) * 24, today = new Date(), diffnum, thisYearMemoryDay;
Expand All @@ -1479,9 +1515,10 @@
thisYearMemoryDay = new Date(today.getFullYear() + 1, memoryDay.getMonth(), memoryDay.getDate());
diffnum = number((( getDayTime(thisYearMemoryDay) - getDayTime(today) ) / DyMilli), {floor: true});
}
if (cond["age"]) {
diffnum = thisYearMemoryDay.getFullYear() - memoryDay.getFullYear();
}
}
if (cond["age"]) {
thisYearMemoryDay = new Date(today.getFullYear(), memoryDay.getMonth(), memoryDay.getDate());
diffnum = thisYearMemoryDay.getFullYear() - memoryDay.getFullYear();
}

return diffnum;
Expand All @@ -1495,45 +1532,30 @@
* @returns {Object}
* @example
* ```js
* ax5.util.weeksOfMonth("2015-10-01"); // {year: 2015, month: 9, count: 5}
* ax5.util.weeksOfMonth("2015-09-19"); // {year: 2015, month: 9, count: 3}
* ax5.util.weeksOfMonth("2015-10-01"); // {year: 2015, month: 10, count: 1}
* ax5.util.weeksOfMonth("2015-09-19"); // {year: 2015, month: 10, count: 1}
* ```
*/
function weeksOfMonth(d) {
var myDate = date(d);
//sOfMonth = new Date(myDate.getFullYear(), myDate.getMonth(), 1);
//sOfMonth.getDay()
//console.log(sOfMonth.getDay(), myDate.getDay());
//console.log(parseInt(myDate.getDate() / 7 + 1));
return {
year: myDate.getFullYear(),
month: myDate.getMonth() + 1,
count: parseInt(myDate.getDate() / 7 + 1)
};
}

/**
* 원하는 횟수 만큼 자릿수 맞춤 문자열을 포함한 문자열을 반환합니다.
* @method ax5.util.setDigit
* @param {String|Number} num
* @param {Number} length
* @param {String} [padder=0]
* @param {Number} [radix]
* @returns {String}
*/
function setDigit(num, length, padder, radix) {
var s = num.toString(radix || 10);
return times((padder || '0'), (length - s.length)) + s;
}

function times(s, count) { return count < 1 ? '' : new Array(count + 1).join(s); }

/**
* 년월에 맞는 날자수를 반환합니다.
* @method ax5.util.daysOfMonth
* @param {Number} y
* @param {Number} m
* @returns {Number}
* @examples
* ```js
* ax5.util.daysOfMonth(2015, 11); // 31
* ax5.util.daysOfMonth(2015, 1); // 28
* ```
*/
function daysOfMonth(y, m) {
if (m == 3 || m == 5 || m == 8 || m == 10) {
Expand All @@ -1547,6 +1569,22 @@
}
}

/**
* 원하는 횟수 만큼 자릿수 맞춤 문자열을 포함한 문자열을 반환합니다.
* @method ax5.util.setDigit
* @param {String|Number} num
* @param {Number} length
* @param {String} [padder=0]
* @param {Number} [radix]
* @returns {String}
*/
function setDigit(num, length, padder, radix) {
var s = num.toString(radix || 10);
return times((padder || '0'), (length - s.length)) + s;
}

function times(s, count) { return count < 1 ? '' : new Array(count + 1).join(s); }

/**
* 타겟엘리먼트의 부모 엘리멘트 트리에서 원하는 조건의 엘리먼트를 얻습니다.
* @method ax5.util.findParentNode
Expand Down Expand Up @@ -1682,16 +1720,16 @@
var returns;
if (isObject(val)) {
returns = '';
for(var k in val){
for (var k in val) {
returns += k + ':' + val[k] + ';';
}
return returns;
}
else if (isString(val)) {
returns = {};
var valSplited = val.split(/[ ]*;[ ]*/g);
valSplited.forEach(function(v){
if((v = v.trim()) !== "") {
valSplited.forEach(function (v) {
if ((v = v.trim()) !== "") {
var vSplited = v.split(/[ ]*:[ ]*/g);
returns[vSplited[0]] = vSplited[1];
}
Expand Down Expand Up @@ -1737,13 +1775,15 @@
error: error,
date: date,
dday: dday,
setDigit: setDigit,
times: times,
daysOfMonth: daysOfMonth,
weeksOfMonth: weeksOfMonth,
setDigit: setDigit,
times: times,
findParentNode: findParentNode,
cssNumber: cssNumber,
css: css
css: css,
isDate: isDate,
isDateFormat: isDateFormat
}
})();

Expand Down
Loading

0 comments on commit 4984ac9

Please sign in to comment.