Skip to content

Commit

Permalink
feat(uitl): handle new Date change new TinyDate
Browse files Browse the repository at this point in the history
  • Loading branch information
xinglu01 committed Jan 15, 2025
1 parent 2893bc0 commit 945c514
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Component, OnInit } from '@angular/core';
import { TinyDate } from 'ngx-tethys/util';

@Component({
selector: 'thy-calendar-disabled-mode-year-example',
templateUrl: './disabled-mode-year.component.html'
})
export class ThyCalendarDisabledYearExampleComponent implements OnInit {
date = new Date();
date = new TinyDate()?.nativeDate;

constructor() {}

Expand Down
46 changes: 23 additions & 23 deletions src/carousel/carousel.component.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import { Platform } from '@angular/cdk/platform';
import { NgTemplateOutlet } from '@angular/common';
import {
AfterContentInit,
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ContentChildren,
ElementRef,
EventEmitter,
inject,
Input,
NgZone,
numberAttribute,
OnChanges,
OnDestroy,
OnInit,
Output,
QueryList,
Renderer2,
ViewChild,
TemplateRef,
ViewEncapsulation,
AfterContentInit,
OnChanges,
SimpleChanges,
NgZone,
OnDestroy,
numberAttribute,
inject
TemplateRef,
ViewChild,
ViewEncapsulation
} from '@angular/core';
import { Platform } from '@angular/cdk/platform';
import { ThyDot } from 'ngx-tethys/dot';
import { ThyIcon } from 'ngx-tethys/icon';
import { coerceBooleanProperty, isNumber, TinyDate } from 'ngx-tethys/util';
import { fromEvent, Subject } from 'rxjs';
import { debounceTime, takeUntil } from 'rxjs/operators';
import { ThyCarouselItemDirective } from './carousel-item.directive';
import { ThyCarouselService } from './carousel.service';
import { ThyCarouselFadeEngine, ThyCarouselNoopEngine, ThyCarouselSlideEngine } from './engine';
import {
ThyCarouselEffect,
ThyCarouselEngine,
ThyDistanceVector,
ThyCarouselPause,
ThyCarouselSwitchData,
ThyCarouselEffect,
ThyCarouselTrigger,
ThyCarouselPause
ThyDistanceVector
} from './typings';
import { ThyCarouselSlideEngine, ThyCarouselNoopEngine, ThyCarouselFadeEngine } from './engine';
import { fromEvent, Subject } from 'rxjs';
import { debounceTime, takeUntil } from 'rxjs/operators';
import { ThyCarouselService } from './carousel.service';
import { ThyIcon } from 'ngx-tethys/icon';
import { ThyDot } from 'ngx-tethys/dot';
import { NgTemplateOutlet } from '@angular/common';
import { coerceBooleanProperty, isNumber } from 'ngx-tethys/util';

/**
* 走马灯组件
Expand Down Expand Up @@ -235,7 +235,7 @@ export class ThyCarousel implements OnInit, AfterViewInit, AfterContentInit, OnC

onDrag(event: TouchEvent | MouseEvent): void {
if (!this.isDragging && !this.isTransitioning && this.thyTouchable) {
const mouseDownTime = new Date().getTime();
const mouseDownTime = new TinyDate().getTime();
let mouseUpTime: number;
this.clearScheduledTransition();
this.wrapperDomRect = this.wrapperEl.getBoundingClientRect();
Expand All @@ -249,7 +249,7 @@ export class ThyCarousel implements OnInit, AfterViewInit, AfterContentInit, OnC
() => {},
() => {
if (this.isDragging) {
mouseUpTime = new Date().getTime();
mouseUpTime = new TinyDate().getTime();
const holdDownTime = mouseUpTime - mouseDownTime;
// Fast enough to switch to the next frame
// or
Expand Down
4 changes: 3 additions & 1 deletion src/core/request-animation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { TinyDate } from 'ngx-tethys/util';

const availablePrefixes = ['moz', 'ms', 'webkit'];

function requestAnimationFramePolyfill(): typeof requestAnimationFrame {
let lastTime = 0;
return function (callback: FrameRequestCallback): number {
const currTime = new Date().getTime();
const currTime = new TinyDate().getTime();
const timeToCall = Math.max(0, 16 - (currTime - lastTime));
const id = setTimeout(() => {
callback(currTime + timeToCall);
Expand Down
12 changes: 6 additions & 6 deletions src/date-picker/date-picker.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export const DEFAULT_DATE_PICKER_CONFIG: ThyDatePickerConfig = {
return [
{
title: '今天',
value: startOfDay(new Date()).getTime()
value: startOfDay(new TinyDate().getTime()).getTime()
},
{
title: '明天',
value: startOfDay(addDays(new Date(), 1)).getTime()
value: startOfDay(addDays(new TinyDate().getTime(), 1)).getTime()
},
{
title: '下周',
value: startOfWeek(addWeeks(new Date(), 1), { weekStartsOn: 1 }).getTime()
value: startOfWeek(addWeeks(new TinyDate().getTime(), 1), { weekStartsOn: 1 }).getTime()
}
];
},
Expand Down Expand Up @@ -72,15 +72,15 @@ export function useDatePickerDefaultConfig(): ThyDatePickerConfig {
return [
{
title: locale().today,
value: startOfDay(new Date()).getTime()
value: startOfDay(new TinyDate().getTime()).getTime()
},
{
title: locale().tomorrow,
value: startOfDay(addDays(new Date(), 1)).getTime()
value: startOfDay(addDays(new TinyDate().getTime(), 1)).getTime()
},
{
title: locale().nextWeek,
value: startOfWeek(addWeeks(new Date(), 1), { weekStartsOn: 1 }).getTime()
value: startOfWeek(addWeeks(new TinyDate().getTime(), 1), { weekStartsOn: 1 }).getTime()
}
];
},
Expand Down
4 changes: 2 additions & 2 deletions src/form/examples/full/full.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { ThyFormValidatorConfig, ThyFormDirective } from 'ngx-tethys/form';
import { TinyDate } from 'ngx-tethys/util';

const provinceCities = [
{
Expand Down Expand Up @@ -93,7 +93,7 @@ export class ThyFormFullExampleComponent implements OnInit {
}
];

date = { date: new Date(), with_time: 0 };
date = { date: new TinyDate()?.nativeDate, with_time: 0 };

dateNull: number = null;

Expand Down
3 changes: 2 additions & 1 deletion src/form/examples/reactive/reactive.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ThyFormValidatorConfig, ThyValidateOn } from 'ngx-tethys/form';

import { Component, OnInit, inject } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { TinyDate } from 'ngx-tethys/util';

const provinceCities = [
{
Expand Down Expand Up @@ -102,7 +103,7 @@ export class ThyFormReactiveExampleComponent implements OnInit {
}
];

date = { date: new Date(), with_time: 0 };
date = { date: new TinyDate().nativeDate, with_time: 0 };

dateNull: number = null;

Expand Down
5 changes: 3 additions & 2 deletions src/tree/examples/async/async.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, ViewChild } from '@angular/core';
import { ThyTree, ThyTreeEmitEvent, ThyTreeNodeData } from 'ngx-tethys/tree';
import { TinyDate } from 'ngx-tethys/util';

@Component({
selector: 'thy-tree-async-example',
Expand Down Expand Up @@ -38,8 +39,8 @@ export class ThyTreeAsyncExampleComponent {
setTimeout(
() =>
resolve([
{ title: 'Child Node', key: `${new Date().getTime()}-0` },
{ title: 'Child Node', key: `${new Date().getTime()}-1` }
{ title: 'Child Node', key: `${new TinyDate().getTime()}-0` },
{ title: 'Child Node', key: `${new TinyDate().getTime()}-1` }
]),
500
);
Expand Down
14 changes: 7 additions & 7 deletions src/upload/upload.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { coerceArray, humanizeBytes } from 'ngx-tethys/util';
import { coerceArray, humanizeBytes, TinyDate } from 'ngx-tethys/util';
import { from, Observable, Subscriber } from 'rxjs';
import { map, mergeMap, tap } from 'rxjs/operators';

import { XhrFactory } from '@angular/common';
import { Injectable, inject } from '@angular/core';
import { inject, Injectable } from '@angular/core';

export enum ThyUploadStatus {
pending = 'pending',
Expand Down Expand Up @@ -151,7 +151,7 @@ export class ThyUploadService {
private xhrFactory = inject(XhrFactory);

private secondsToHuman(sec: number): string {
return new Date(sec * 1000).toISOString().slice(11, 19);
return new TinyDate(new Date(sec * 1000)).nativeDate.toISOString().slice(11, 19);
}

private normalizeUploadFiles(uploadFiles: ThyUploadFile | ThyUploadFile[]) {
Expand All @@ -168,7 +168,7 @@ export class ThyUploadService {

private uploadByXhr(observer: Subscriber<ThyUploadResponse>, uploadFile: ThyUploadFile) {
const xhr = this.xhrFactory.build();
const time: number = new Date().getTime();
const time: number = new TinyDate().getTime();
let speed = 0;
let estimatedTime: number | null = null;

Expand All @@ -184,9 +184,9 @@ export class ThyUploadService {
if (percentage === 100) {
percentage = 99;
}
const diff = new Date().getTime() - time;
const diff = new TinyDate().getTime() - time;
speed = Math.round((event.loaded / diff) * 1000);
const progressStartTime = (uploadFile.progress && uploadFile.progress.startTime) || new Date().getTime();
const progressStartTime = (uploadFile.progress && uploadFile.progress.startTime) || new TinyDate().getTime();
estimatedTime = Math.ceil((event.total - event.loaded) / speed);

uploadFile.progress.status = ThyUploadStatus.uploading;
Expand All @@ -205,7 +205,7 @@ export class ThyUploadService {

const onReadyStateChange = () => {
if (xhr.readyState === XMLHttpRequest.DONE) {
const speedTime = (new Date().getTime() - uploadFile.progress.startTime) * 1000;
const speedTime = (new TinyDate().getTime() - uploadFile.progress.startTime) * 1000;
const speedAverage = Math.round(uploadFile.nativeFile.size / speedTime);

uploadFile.progress.status = ThyUploadStatus.done;
Expand Down

0 comments on commit 945c514

Please sign in to comment.