TIMEAGO

이 함수를 사용하면 두 시점 간에 경과된 시간을 계산할 수 있습니다.

설명
app.jsx
app-func.jsx
app-class.jsx
index.html
styles.css

구문

=TIMEAGO(time1)
인수 설명
time1 (필수) - 경과 시간을 계산해야 하는 시작 날짜 및 시간을 표시합니다.

TIMEAGO 함수를 위의 코드에서 직접 셀에 입력하거나 setFormula 메서드를 사용하여 수식을 적용할 수 있습니다.

    var spread = GC.Spread.Sheets.findControl(document.getElementById('ss'));
    var sheet = spread.getActiveSheet();
    //set formula
    sheet.setFormula(0, 1, '=TIMEAGO(A1)');

사용법 참고 사항

TIMEAGO 함수를 사용하면 시작 시점부터 현재 시점까지 경과한 시간을 보다 쉽게 계산할 수 있습니다.

프로젝트 관리에 이 함수를 일반적으로 사용합니다. 간단한 날짜보다 구체적인 시간과 관련이 있는 것을 표시하려는 경우 TIMEAGO 함수를 사용할 수 있습니다.

이점

이 함수를 사용하면 복잡한 사용자 정의 함수 및 메서드를 만들지 않고 두 시점 간에 경과한 시간 간격을 계산할 수 있습니다.

구문 인수 설명 time1 (필수) - 경과 시간을 계산해야 하는 시작 날짜 및 시간을 표시합니다. TIMEAGO 함수를 위의 코드에서 직접 셀에 입력하거나 setFormula 메서드를 사용하여 수식을 적용할 수 있습니다. 사용법 참고 사항 TIMEAGO 함수를 사용하면 시작 시점부터 현재 시점까지 경과한 시간을 보다 쉽게 계산할 수 있습니다. 프로젝트 관리에 이 함수를 일반적으로 사용합니다. 간단한 날짜보다 구체적인 시간과 관련이 있는 것을 표시하려는 경우 TIMEAGO 함수를 사용할 수 있습니다. 이점 이 함수를 사용하면 복잡한 사용자 정의 함수 및 메서드를 만들지 않고 두 시점 간에 경과한 시간 간격을 계산할 수 있습니다.
import * as React from 'react'; import * as ReactDOM from 'react-dom'; import './styles.css'; import { AppFunc } from './app-func'; import { App } from './app-class'; // 1. Functional Component sample ReactDOM.render(<AppFunc />, document.getElementById('app')); // 2. Class Component sample // ReactDOM.render(<App />, document.getElementById('app'));
import * as React from 'react'; import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react'; import './styles.css'; class TimeAgoFunction extends GC.Spread.CalcEngine.Functions.Function { constructor() { super("TIMEAGO", 1, 1); } evaluate(time1) { switch (typeof time1) { case 'number': break; case 'string': time1 = +new Date(time1); break; case 'object': if (time1.constructor === Date) time1 = time1.getTime(); break; default: time1 = +new Date(); } let time2 = +new Date(); if (time1 == time2) { return "just now"; } var isFuture = (time2 < time1); var seconds = (isFuture ? time1 - time2 : time2 - time1) / 1000; var interval = seconds / 31536000; if (interval >= 1) { var years = Math.floor(interval); return isFuture ? "in " + (years <= 1 ? "one year" : years + " years") : years <= 1 ? "one year ago" : years + " years ago"; } interval = seconds / 2592000; if (interval >= 1) { var months = Math.floor(interval); return isFuture ? "in " + (months <= 1 ? "one month" : months + " months") : months <= 1 ? "one month ago" : months + " months ago"; } interval = seconds / 86400; if (interval >= 1) { var days = Math.floor(interval); return isFuture ? "in " + (days <= 1 ? "tomorrow" : days + " days") : days <= 1 ? "yesterday" : days + " days ago"; } interval = seconds / 3600; if (interval > 1) { var hours = Math.floor(interval); return isFuture ? "in " + (hours <= 1 ? "an hour" : hours + " hours") : hours <= 1 ? "an hour ago" : hours + " hours ago"; } interval = seconds / 60; if (interval > 1) { var minutes = Math.floor(interval); return isFuture ? "in " + (minutes <= 1 ? "a minute" : minutes + " minutes") : minutes <= 1 ? "a minute ago" : minutes + " minutes ago"; } seconds = Math.floor(seconds); return isFuture ? "in " + (seconds <= 1 ? "one second" : seconds + " seconds") : seconds <= 1 ? "one second ago" : seconds + " seconds ago"; } } const autoGenerateColumns = true; export function AppFunc() { const initSpread = (spread) => { spread.suspendPaint(); const timeAgoFun = new TimeAgoFunction(); let sheet = spread.getSheet(0); sheet.addCustomFunction(timeAgoFun); sheet.setColumnWidth(0, 200); sheet.setColumnWidth(1, 200); sheet.setColumnWidth(2, 150); sheet.setValue(0, 0, 'Date'); sheet.setValue(0, 1, 'Formula'); sheet.setValue(0, 2, 'Result'); sheet.setFormula(1, 0, 'TODAY()'); sheet.setValue(1, 1, '=TIMEAGO(A2)'); sheet.setFormula(1, 2, 'TIMEAGO(A2)'); sheet.setValue(2, 0, new Date('2020-01-20')); sheet.setValue(2, 1, '=TIMEAGO(A3)'); sheet.setFormula(2, 2, 'TIMEAGO(A3)'); sheet.setValue(3, 0, new Date('2021-02-10')); sheet.setValue(3, 1, '=TIMEAGO(A4)'); sheet.setFormula(3, 2, 'TIMEAGO(A4)'); sheet.setValue(4, 0, new Date('2021-11-29 17:12:00')); sheet.setValue(4, 1, '=TIMEAGO(A5)'); sheet.setFormula(4, 2, 'TIMEAGO(A5)'); spread.resumePaint(); } return <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => initSpread(spread)}> <Worksheet autoGenerateColumns={autoGenerateColumns}> </Worksheet> </SpreadSheets> </div> </div>; }
import * as React from 'react'; import GC from '@mescius/spread-sheets'; import '@mescius/spread-sheets-resources-ko'; GC.Spread.Common.CultureManager.culture("ko-kr"); import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react'; import './styles.css'; const Component = React.Component; class TimeAgoFunction extends GC.Spread.CalcEngine.Functions.Function { constructor() { super("TIMEAGO", 1, 1); } evaluate(time1) { switch (typeof time1) { case 'number': break; case 'string': time1 = +new Date(time1); break; case 'object': if (time1.constructor === Date) time1 = time1.getTime(); break; default: time1 = +new Date(); } let time2 = +new Date(); if (time1 == time2) { return "just now"; } var isFuture = (time2 < time1); var seconds = (isFuture ? time1 - time2 : time2 - time1) / 1000; var interval = seconds / 31536000; if (interval >= 1) { var years = Math.floor(interval); return isFuture ? "in " + (years <= 1 ? "one year" : years + " years") : years <= 1 ? "one year ago" : years + " years ago"; } interval = seconds / 2592000; if (interval >= 1) { var months = Math.floor(interval); return isFuture ? "in " + (months <= 1 ? "one month" : months + " months") : months <= 1 ? "one month ago" : months + " months ago"; } interval = seconds / 86400; if (interval >= 1) { var days = Math.floor(interval); return isFuture ? "in " + (days <= 1 ? "tomorrow" : days + " days") : days <= 1 ? "yesterday" : days + " days ago"; } interval = seconds / 3600; if (interval > 1) { var hours = Math.floor(interval); return isFuture ? "in " + (hours <= 1 ? "an hour" : hours + " hours") : hours <= 1 ? "an hour ago" : hours + " hours ago"; } interval = seconds / 60; if (interval > 1) { var minutes = Math.floor(interval); return isFuture ? "in " + (minutes <= 1 ? "a minute" : minutes + " minutes") : minutes <= 1 ? "a minute ago" : minutes + " minutes ago"; } seconds = Math.floor(seconds); return isFuture ? "in " + (seconds <= 1 ? "one second" : seconds + " seconds") : seconds <= 1 ? "one second ago" : seconds + " seconds ago"; } } export class App extends Component { constructor(props) { super(props); this.autoGenerateColumns = true; } render() { return <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => this.initSpread(spread)}> <Worksheet autoGenerateColumns={this.autoGenerateColumns}> </Worksheet> </SpreadSheets> </div> </div>; } initSpread(spread) { spread.suspendPaint(); this.timeAgoFun = new TimeAgoFunction(); let sheet = spread.getSheet(0); sheet.addCustomFunction(this.timeAgoFun); sheet.setColumnWidth(0, 200); sheet.setColumnWidth(1, 200); sheet.setColumnWidth(2, 150); sheet.setValue(0, 0, 'Date'); sheet.setValue(0, 1, 'Formula'); sheet.setValue(0, 2, 'Result'); sheet.setFormula(1, 0, 'TODAY()'); sheet.setValue(1, 1, '=TIMEAGO(A2)'); sheet.setFormula(1, 2, 'TIMEAGO(A2)'); sheet.setValue(2, 0, new Date('2020-01-20')); sheet.setValue(2, 1, '=TIMEAGO(A3)'); sheet.setFormula(2, 2, 'TIMEAGO(A3)'); sheet.setValue(3, 0, new Date('2021-02-10')); sheet.setValue(3, 1, '=TIMEAGO(A4)'); sheet.setFormula(3, 2, 'TIMEAGO(A4)'); sheet.setValue(4, 0, new Date('2021-11-29 17:12:00')); sheet.setValue(4, 1, '=TIMEAGO(A5)'); sheet.setFormula(4, 2, 'TIMEAGO(A5)'); spread.resumePaint(); } }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ko/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/ko/react/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('$DEMOROOT$/ko/lib/react/license.js').then(function () { System.import('./src/app'); }); </script> </head> <body> <div id="app"></div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; padding: 5px; margin-top: 10px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } #app { height: 100% }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true, react: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-resources-ko': 'npm:@mescius/spread-sheets-resources-ko/index.js', '@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js', 'react': 'npm:react/umd/react.production.min.js', 'react-dom': 'npm:react-dom/umd/react-dom.production.min.js', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'jsx' }, "node_modules": { defaultExtension: 'js' }, } }); })(this);