Skip to content

Commit

Permalink
Primera version cronometro OK
Browse files Browse the repository at this point in the history
  • Loading branch information
mugan86 committed Feb 14, 2019
1 parent 1aa47b0 commit 560f701
Show file tree
Hide file tree
Showing 105 changed files with 9,328 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
package-lock.json
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test.js
package-lock.json
node_modules/
lib/
documentation/
tsconfig.doc.json
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Cronometro
Un cronometro que cuenta y descuenta

## Instalación

```
npm install proyecto-2c-crono
```

## Uso

### Contador
```
const modulo = require('proyecto-2c-crono');
const cont = new modulo.Contador(2);
var d = cont.start().subscribe(
data => {
console.log(data);
if (data === 'FINISH') {
d.unsubscribe();
}
}
);
//Espera estos resultados
00:00:00
00:00:01
FINISH
```

### Descontador
```
const modulo = require('proyecto-2c-crono');
const cont = new modulo.Descontador(4);
var d = cont.start().subscribe(
data => {
console.log(data);
if (data === 'FINISH') {
d.unsubscribe();
}
}
);//Espera estos resultados
00:00:04
00:00:03
00:00:02
00:00:01
FINISH
```
9 changes: 9 additions & 0 deletions dist/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Constantes de tiempo
*/
export declare enum Tiempo {
SG_MIN = 60,
SG_HORA = 3600,
HORAS_DIA = 24,
SG_DIA = 86400
}
12 changes: 12 additions & 0 deletions dist/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Constantes de tiempo
*/
var Tiempo;
(function (Tiempo) {
Tiempo[Tiempo["SG_MIN"] = 60] = "SG_MIN";
Tiempo[Tiempo["SG_HORA"] = 3600] = "SG_HORA";
Tiempo[Tiempo["HORAS_DIA"] = 24] = "HORAS_DIA";
Tiempo[Tiempo["SG_DIA"] = 86400] = "SG_DIA";
})(Tiempo = exports.Tiempo || (exports.Tiempo = {}));
17 changes: 17 additions & 0 deletions dist/contador.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Cuenta de manera ascendente de 1 en 1
*/
export declare class Contador {
/**
* @ignore
*/
valorLImite: number;
/**
* @ignore
*/
constructor(limite?: number);
/**
* CUenta de 0 hasta el límite establecido
*/
start(): import("../../../../../../../../Volumes/DATA/Udemy/Proyects/NPM-Projects-Course/nodets/proyecto-2c-crono/node_modules/rxjs/internal/Observable").Observable<string>;
}
29 changes: 29 additions & 0 deletions dist/contador.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const interval_1 = require("rxjs/internal/observable/interval");
const map_1 = require("rxjs/internal/operators/map");
const conversion_1 = require("./conversion");
/**
* Cuenta de manera ascendente de 1 en 1
*/
class Contador {
/**
* @ignore
*/
constructor(limite = 5) {
/**
* @ignore
*/
this.valorLImite = -1;
this.valorLImite = limite;
}
/**
* CUenta de 0 hasta el límite establecido
*/
start() {
return interval_1.interval(1000).pipe(map_1.map((sg) => {
return conversion_1.convertirSgAFormatoReloj(sg, 1, this.valorLImite);
}));
}
}
exports.Contador = Contador;
7 changes: 7 additions & 0 deletions dist/conversion.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Convierte los segundos en HH:MM:SS
* @param sg Segundos del momento
* @param tipo 1: COntador / 2: Descontador
* @param limite Valor limite hasta el momento que funcionará
*/
export declare function convertirSgAFormatoReloj(sg: number, tipo: number, limite: number): string;
38 changes: 38 additions & 0 deletions dist/conversion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("./constants");
/**
* Convierte los segundos en HH:MM:SS
* @param sg Segundos del momento
* @param tipo 1: COntador / 2: Descontador
* @param limite Valor limite hasta el momento que funcionará
*/
function convertirSgAFormatoReloj(sg, tipo, limite) {
if (tipo === 1 && limite === sg || tipo === 2 && sg === 0) {
return 'FINISH';
}
// COnseguir el tiempo formateado para devolverlo
// Horas
const horas = Math.floor((sg % constants_1.Tiempo.SG_DIA) / constants_1.Tiempo.SG_HORA);
// Minutos
const minutos = Math.floor((sg % constants_1.Tiempo.SG_HORA) / constants_1.Tiempo.SG_MIN);
// segundos
const sgs = Math.floor((sg % constants_1.Tiempo.SG_MIN));
return adaptarAlReloj(horas, minutos, sgs);
}
exports.convertirSgAFormatoReloj = convertirSgAFormatoReloj;
/**
* @ignore
*/
function adaptarAlReloj(horas, minutos, sg) {
const h = darNumeroFormatoCorrecto(horas);
const m = darNumeroFormatoCorrecto(minutos);
const s = darNumeroFormatoCorrecto(sg);
return `${h}:${m}:${s}`;
}
/**
* @ignore
*/
function darNumeroFormatoCorrecto(n) {
return (n < 10) ? '0'.concat(String(n)) : String(n);
}
17 changes: 17 additions & 0 deletions dist/descontador.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Descuenta de uno en uno desde el valor establecido hasta 0
*/
export declare class Descontador {
/**
* @ignore
*/
valorInicial: number;
/**
* @ignore
*/
constructor(valor?: number);
/**
* Va descontando del valor inicial introducido hasta 0
*/
start(): import("../../../../../../../../Volumes/DATA/Udemy/Proyects/NPM-Projects-Course/nodets/proyecto-2c-crono/node_modules/rxjs/internal/Observable").Observable<string>;
}
29 changes: 29 additions & 0 deletions dist/descontador.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const interval_1 = require("rxjs/internal/observable/interval");
const map_1 = require("rxjs/internal/operators/map");
const conversion_1 = require("./conversion");
/**
* Descuenta de uno en uno desde el valor establecido hasta 0
*/
class Descontador {
/**
* @ignore
*/
constructor(valor = 5) {
/**
* @ignore
*/
this.valorInicial = -1;
this.valorInicial = valor;
}
/**
* Va descontando del valor inicial introducido hasta 0
*/
start() {
return interval_1.interval(1000).pipe(map_1.map((sg) => {
return conversion_1.convertirSgAFormatoReloj(this.valorInicial - sg, 2, this.valorInicial);
}));
}
}
exports.Descontador = Descontador;
4 changes: 4 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './constants';
export * from './conversion';
export * from './contador';
export * from './descontador';
9 changes: 9 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./constants"));
__export(require("./conversion"));
__export(require("./contador"));
__export(require("./descontador"));
Loading

0 comments on commit 560f701

Please sign in to comment.