How to use timeutil method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

TimeUtil.ts

Source:TimeUtil.ts Github

copy

Full Screen

1module Pan3d {2 export class TimeUtil {3 static START_TIME: number;4 public static funAry: Array<Function> = new Array;5 public static timefunAry: Array<TimeFunTick> = new Array;6 public static outTimeFunAry: Array<TimeFunOut> = new Array;7 public static time: number = 0;89 public static getTimer(): number {10 return Date.now() - TimeUtil.START_TIME;11 }1213 public static getTimerSecond(): number {14 return TimeUtil.getTimer() / 1000;15 }1617 private static lastTime: number = 0;18 //标记现在时间19 public static saveNowTime(): void {20 this.lastTime = this.getTimer()21 }22 //得到使用的时间23 public static getUseTime(): number {24 return this.getTimer() - this.lastTime25 }2627 public static getZeroTime(nS: number): number {28 var timestamp4: Date = new Date(nS * 1000);29 timestamp4.setHours(0);30 timestamp4.setMinutes(0);31 timestamp4.setSeconds(0);3233 return timestamp4.getTime() / 1000;34 }35 /**36 * YYYY-mm-DD HH:MM37 **/38 public static getLocalTime(nS: number): string {394041 var timestamp4 = new Date(nS * 1000);//直接用 new Date(时间戳) 格式转化获得当前时间1-004243 return timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 5)44454647 }48 /**49 * YYYY-mm-DD50 **/51 public static getLocalTime0(nS: number): string {525354 var timestamp4 = new Date(nS * 1000);//直接用 new Date(时间戳) 格式转化获得当前时间1-00555657 return timestamp4.toLocaleDateString().replace(/\//g, "-")58596061 }6263 /**64 * YYYY-mm-DD HH:MM:SS65 **/66 public static getLocalTime1(nS: number): string {676869 var timestamp4 = new Date(nS * 1000);//直接用 new Date(时间戳) 格式转化获得当前时间1-00707172 return timestamp4.toLocaleDateString().replace(/\//g, "-") + " " + timestamp4.toTimeString().substr(0, 8)73747576 }7778 /**79 * HH:MM:SS80 **/81 public static getLocalTime2(nS: number): string {828384 // var timestamp4 = new Date(nS * 1000 - 8 * 60 * 60 * 1000);//直接用 new Date(时间戳) 格式转化获得当前时间1-0085 var timestamp4 = new Date(nS * 1000);//直接用 new Date(时间戳) 格式转化获得当前时间1-0086 ////console.log("--time=",timestamp4.toTimeString());87 return timestamp4.toTimeString().substr(0, 8)8889 }90 /**91 * HH:MM92 **/93 public static getLocalTime6(nS: number): string {94 // var timestamp4 = new Date(nS * 1000 - 8 * 60 * 60 * 1000);//直接用 new Date(时间戳) 格式转化获得当前时间1-0095 var timestamp4 = new Date(nS * 1000);//直接用 new Date(时间戳) 格式转化获得当前时间1-0096 //console.log("--time=",timestamp4.toTimeString());97 return timestamp4.toTimeString().substr(0, 5)9899 }100101 /**102 * MM:SS103 **/104 public static getLocalTime3(nS: number): string {105106107 var timestamp4 = new Date(nS * 1000);//直接用 new Date(时间戳) 格式转化获得当前时间1-00108109 return timestamp4.toTimeString().substr(3, 5)110111 }112 /**113 * MM分SS秒114 */115 public static getLocalTime4(nS: number): string {116 return float2int(nS / 60) + "分" + (nS % 60) + "秒";117 }118 /**119 * HH时MM分SS秒120 */121 public static getLocalTime5(nS: number): string {122 var timestamp4 = new Date(nS * 1000);123 var str = timestamp4.toTimeString().substr(0, 8)124 var strAry = str.split(":");125 return strAry[0] + "时" + strAry[1] + "分" + strAry[2] + "秒";126 }127 public static dayTime: number = 24 * 60 * 60;128 public static HourTime: number = 60 * 60;129 public static MinuteTime: number = 60;130 /**131 * 时间差转换132 * DD天HH时MM分SS秒133 */134 public static getDiffTime1(nS: number): string {135136 var day: number = float2int(nS / this.dayTime);137 nS -= day * this.dayTime;138 var hour: number = float2int(nS / this.HourTime);139 nS -= hour * this.HourTime;140 var minus: number = float2int(nS / this.MinuteTime);141 nS -= minus * this.MinuteTime;142143 return day + "天" + hour + "时" + minus + "分" + nS + "秒";144145 }146147 /**148 * HH:MM:SS149 **/150 public static getDiffTime2(nS: number): string {151 var hour: number = float2int(nS / this.HourTime);152 nS -= hour * this.HourTime;153 var minus: number = float2int(nS / this.MinuteTime);154 nS -= minus * this.MinuteTime;155 return this.zeroStr(hour) + ":" + this.zeroStr(minus) + ":" + this.zeroStr(nS);156 }157158 public static zeroStr(num: number): string {159 if (num > 9) {160 return String(num);161 } else {162 return "0" + num;163 }164 }165166 public static getDelayTimeStr($hourtime: number): string {167 var hourtime: number = Math.floor($hourtime / 3600)168169 var timeStr: string = "";170 if (hourtime > 24) {171 timeStr = Math.floor(hourtime / 24) + "天前";172 } else {173 if (hourtime >= 1) {174 timeStr = hourtime + "小时前";175 } else {176 timeStr = "刚刚";177 }178 }179 return timeStr;180 }181182 public static compareTime($hour: number, $min: number): boolean {183 //服务器当前标准时间184185 return false;186 }187188189190 public static init(): void {191 TimeUtil.START_TIME = Date.now();192 }193194195 public static addTimeTick($time: number, $fun: Function, $beginTime: number = 0): void {196 var timeFunTick: TimeFunTick = new TimeFunTick();197 timeFunTick.alltime = $time;198 timeFunTick.fun = $fun;199 timeFunTick.time = $time - $beginTime;200 TimeUtil.timefunAry.push(timeFunTick);201 }202203 public static removeTimeTick($fun: Function): void {204 for (var i: number = 0; i < TimeUtil.timefunAry.length; i++) {205 if (TimeUtil.timefunAry[i]) {206 if (TimeUtil.timefunAry[i].fun == $fun) {207 //TimeUtil.timefunAry.splice(i, 1);208 TimeUtil.timefunAry[i] = null;209 break;210 }211 } else {212 // throw Error("有重复移除嫌疑"); 213 }214 }215 }216217 public static addTimeOut($time: number, $fun: Function): void {218 if (this.hasTimeOut($fun)) {219 return;220 }221 var timeFunTick: TimeFunOut = new TimeFunOut();222 timeFunTick.alltime = $time;223 timeFunTick.fun = $fun;224 timeFunTick.time = 0;225 TimeUtil.outTimeFunAry.push(timeFunTick);226 }227228 public static removeTimeOut($fun: Function): void {229 for (var i: number = 0; i < TimeUtil.outTimeFunAry.length; i++) {230231 if (TimeUtil.outTimeFunAry[i] && TimeUtil.outTimeFunAry[i].fun == $fun) {232 //TimeUtil.outTimeFunAry.splice(i, 1);233 TimeUtil.outTimeFunAry[i] = null;234 break;235 }236237 }238 }239240 public static hasTimeOut($fun: Function): boolean {241 for (var i: number = 0; i < TimeUtil.outTimeFunAry.length; i++) {242243 if (TimeUtil.outTimeFunAry[i] && TimeUtil.outTimeFunAry[i].fun == $fun) {244 return true;245 }246247 }248 return false;249 }250251252253 public static addFrameTick($fun: Function): void {254 if (TimeUtil.funAry.indexOf($fun) == -1) {255 TimeUtil.funAry.push($fun);256 }257 }258259 public static hasFrameTick($fun: Function): boolean {260 var index: number = TimeUtil.funAry.indexOf($fun);261 if (index != -1) {262 return true;263 }264 return false;265 }266267 public static removeFrameTick($fun: Function): void {268 var index: number = TimeUtil.funAry.indexOf($fun);269 if (index != -1) {270 TimeUtil.funAry[index] = null;271 //TimeUtil.funAry.splice(index, 1);272 }273 }274275 public static update(): void {276 var dtime: number = TimeUtil.getTimer() - TimeUtil.time;277278 for (var i: number = 0; i < TimeUtil.funAry.length; i++) {279 if (TimeUtil.funAry[i]) {280 TimeUtil.funAry[i](dtime);281 }282 }283284285 for (var i: number = 0; i < TimeUtil.timefunAry.length; i++) {286 if (TimeUtil.timefunAry[i]) {287 TimeUtil.timefunAry[i].update(dtime);288 }289 }290291 for (var i: number = TimeUtil.outTimeFunAry.length - 1; i >= 0; i--) {292 if (TimeUtil.outTimeFunAry[i] && TimeUtil.outTimeFunAry[i].update(dtime)) {293 TimeUtil.outTimeFunAry[i] = null;294 }295 }296297 for (var i: number = TimeUtil.funAry.length - 1; i >= 0; i--) {298 if (!TimeUtil.funAry[i]) {299 TimeUtil.funAry.splice(i, 1);300 }301 }302303 for (var i: number = TimeUtil.timefunAry.length - 1; i >= 0; i--) {304 if (!TimeUtil.timefunAry[i]) {305 TimeUtil.timefunAry.splice(i, 1);306 }307 }308309 for (var i: number = TimeUtil.outTimeFunAry.length - 1; i >= 0; i--) {310 if (!TimeUtil.outTimeFunAry[i]) {311 TimeUtil.outTimeFunAry.splice(i, 1);312 }313 }314315316317 TimeUtil.time = TimeUtil.getTimer();318 }319320 }321322 class TimeFunTick {323 public alltime: number = 0;324 public time: number = 0;325 public fun: Function;326 public update(t: number): void {327 this.time += t;328 if (this.time >= this.alltime) {329 this.fun();330 this.time = 0;331 }332 }333 }334335 class TimeFunOut {336 public alltime: number = 0;337 public time: number = 0;338 public fun: Function;339 public update(t: number): boolean {340 this.time += t;341 if (this.time >= this.alltime) {342 this.fun();343 return true;344 }345 return false;346 }347 }348349 ...

Full Screen

Full Screen

timeUtilTests.js

Source:timeUtilTests.js Github

copy

Full Screen

1define([2 'widgets/timeZone/timeUtil'3 ], function(TimeUtil) {4 var datetime = new Date();5 var dst = TimeUtil.IsClientDSTEnabled();6 var offset = TimeUtil.GetClientTimezoneOffset();7 if (dst) {8 if (offset < 0) {9 offset -= 60;10 } else {11 offset += 60;12 }13 }14 offset /= 60;15 console.log('datetime: ' + datetime.toString() + ', offset: ' + offset + " hours, dst: " + dst);16 describe('TimeUtil - Unit tests', function() {17 it('GMT: UTC +/-0:00', function() {18 TimeUtil.GetTimezoneString(0, false).should.be.equal('UTC +/-0:00');19 });20 if (offset == -5) {21 it('EST: client machine', function() {22 TimeUtil.GetTimezoneString().should.be.equal('UTC -5:00');23 });24 }25 it('EST: UTC -5:00 with DST on', function() {26 TimeUtil.GetTimezoneString(-240, true).should.be.equal(dst ? 'UTC -5:00' : 'UTC -4:00');27 });28 it('EST: UTC -5:00 with DST off', function() {29 TimeUtil.GetTimezoneString(-300, false).should.be.equal('UTC -5:00');30 });31 if (offset == -8) {32 it('PST: client machine', function() {33 TimeUtil.GetTimezoneString().should.be.equal('UTC -8:00');34 });35 }36 it('PST: UTC -8:00 with DST on', function() {37 TimeUtil.GetTimezoneString(-420, true).should.be.equal(dst ? 'UTC -8:00' : 'UTC -7:00');38 });39 it('PST UTC -8:00 with DST off', function() {40 TimeUtil.GetTimezoneString(-480, false).should.be.equal('UTC -8:00');41 });42 it('IST: UTC +5:30', function() {43 TimeUtil.GetTimezoneString(330, false).should.be.equal('UTC +5:30');44 });45 it('SBT: UTC +11:00', function() {46 TimeUtil.GetTimezoneString(660, false).should.be.equal('UTC +11:00');47 }); 48 it('NZST: UTC +12:00', function() {49 TimeUtil.GetTimezoneString(720, false).should.be.equal('UTC +12:00');50 }); 51 }); 52 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var timeutil = require('devicefarmer-stf').timeutil;2var time = timeutil.now();3console.log(time);4var timeutil = require('devicefarmer-stf').timeutil;5var time = timeutil.now();6console.log(time);

Full Screen

Using AI Code Generation

copy

Full Screen

1var timeutil = require('timeutil');2var date = new Date();3var date1 = new Date();4var date2 = new Date();5var date3 = new Date();6var date4 = new Date();7var date5 = new Date();8var date6 = new Date();9var date7 = new Date();10var date8 = new Date();11var date9 = new Date();12var date10 = new Date();13var date11 = new Date();14var date12 = new Date();15var date13 = new Date();16var date14 = new Date();17var date15 = new Date();18var date16 = new Date();19var date17 = new Date();20var date18 = new Date();21var date19 = new Date();22var date20 = new Date();23date1.setHours(10);24date1.setMinutes(0);25date1.setSeconds(0);26date1.setMilliseconds(0);27date2.setHours(11);28date2.setMinutes(0);29date2.setSeconds(0);30date2.setMilliseconds(0);31date3.setHours(12);32date3.setMinutes(0);33date3.setSeconds(0);34date3.setMilliseconds(0);35date4.setHours(13);36date4.setMinutes(0);37date4.setSeconds(0);38date4.setMilliseconds(0);39date5.setHours(14);40date5.setMinutes(0);41date5.setSeconds(0);42date5.setMilliseconds(0);43date6.setHours(15);44date6.setMinutes(0);45date6.setSeconds(0);46date6.setMilliseconds(0);47date7.setHours(16);48date7.setMinutes(0);49date7.setSeconds(0);50date7.setMilliseconds(0);51date8.setHours(17);52date8.setMinutes(0);53date8.setSeconds(0);54date8.setMilliseconds(0);55date9.setHours(18);56date9.setMinutes(0);57date9.setSeconds(0);58date9.setMilliseconds(0);59date10.setHours(19);60date10.setMinutes(0);61date10.setSeconds(0);62date10.setMilliseconds(0);63date11.setHours(20);64date11.setMinutes(0);65date11.setSeconds(0);66date11.setMilliseconds(0);67date12.setHours(21);68date12.setMinutes(0);69date12.setSeconds(0);70date12.setMilliseconds(0);71date13.setHours(22);

Full Screen

Using AI Code Generation

copy

Full Screen

1var timeutil = require('devicefarmer-stf-utils').timeutil;2var time = timeutil.getTime();3console.log(time);4var timeutil = require('devicefarmer-stf-utils').timeutil;5var time = timeutil.getTime();6console.log(time);7Copyright (c) 2017 DeviceFarmer

Full Screen

Using AI Code Generation

copy

Full Screen

1var timeutil = require('devicefarmer-stf/lib/util/timeutil');2var time = timeutil.parseTime('1h 30m');3console.log(time);4{5 "scripts": {6 },7 "dependencies": {8 }9}

Full Screen

Using AI Code Generation

copy

Full Screen

1var timeutil = require('devicefarmer-stf').util.timeutil;2var time = timeutil.millisToHumanReadable(1000);3console.log(time);4var timeutil = require('devicefarmer-stf').util.timeutil;5var time = timeutil.humanReadableToMillis('1m');6console.log(time);7var timeutil = require('devicefarmer-stf').util.timeutil;8var time = timeutil.millisToHumanReadable(1000);9console.log(time);10var time = timeutil.humanReadableToMillis('1m');11console.log(time);12var timeutil = require('devicefarmer-stf').util.timeutil;13var time = timeutil.millisToHumanReadable(1000);14console.log(time);15var time = timeutil.humanReadableToMillis('1m');16console.log(time);17var timeutil = require('devicefarmer-stf').util.timeutil;18var time = timeutil.millisToHumanReadable(1000);19console.log(time);20var time = timeutil.humanReadableToMillis('1m');21console.log(time);22var timeutil = require('devicefarmer-stf').util.timeutil;23var time = timeutil.millisToHumanReadable(1000);24console.log(time);25var time = timeutil.humanReadableToMillis('1m');26console.log(time);27var timeutil = require('devicefarmer-stf').util.timeutil;28var time = timeutil.millisToHumanReadable(1000);29console.log(time);30var time = timeutil.humanReadableToMillis('1m');31console.log(time);32var timeutil = require('devicefarmer-stf').util.timeutil;33var time = timeutil.millisToHumanReadable(1000);34console.log(time);35var time = timeutil.humanReadableToMillis('1m');36console.log(time);

Full Screen

Using AI Code Generation

copy

Full Screen

1var timeutil = require('devicefarmer-stf').timeutil;2var time = timeutil.getNow();3console.log('time is ' + time);4{5 "scripts": {6 },7 "dependencies": {8 }9}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful