candy-date.d.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * Use of this source code is governed by an MIT-style license that can be
  3. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  4. */
  5. import { IndexableObject } from 'ng-zorro-antd/core/types';
  6. export type CandyDateMode = 'decade' | 'year' | 'quarter' | 'month' | 'day' | 'hour' | 'minute' | 'second';
  7. export type NormalizedMode = 'decade' | 'year' | 'month';
  8. export type WeekDayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
  9. export type CandyDateType = CandyDate | Date | null;
  10. export type SingleValue = CandyDate | null;
  11. export type CompatibleValue = SingleValue | SingleValue[];
  12. export declare function wrongSortOrder(rangeValue: SingleValue[]): boolean;
  13. export declare function normalizeRangeValue(value: SingleValue[], hasTimePicker: boolean, type?: NormalizedMode, activePart?: 'left' | 'right'): CandyDate[];
  14. export declare function cloneDate(value: CompatibleValue): CompatibleValue;
  15. /**
  16. * Wrapping kind APIs for date operating and unify
  17. * NOTE: every new API return new CandyDate object without side effects to the former Date object
  18. * NOTE: most APIs are based on local time other than customized locale id (this needs tobe support in future)
  19. * TODO: support format() against to angular's core API
  20. */
  21. export declare class CandyDate implements IndexableObject {
  22. nativeDate: Date;
  23. constructor(date?: Date | string | number);
  24. calendarStart(options?: {
  25. weekStartsOn: WeekDayIndex | undefined;
  26. }): CandyDate;
  27. getYear(): number;
  28. getMonth(): number;
  29. getDay(): number;
  30. getTime(): number;
  31. getDate(): number;
  32. getHours(): number;
  33. getMinutes(): number;
  34. getSeconds(): number;
  35. getMilliseconds(): number;
  36. clone(): CandyDate;
  37. setHms(hour: number, minute: number, second: number): CandyDate;
  38. setYear(year: number): CandyDate;
  39. addYears(amount: number): CandyDate;
  40. setMonth(month: number): CandyDate;
  41. addMonths(amount: number): CandyDate;
  42. setDay(day: number, options?: {
  43. weekStartsOn: WeekDayIndex;
  44. }): CandyDate;
  45. setDate(amount: number): CandyDate;
  46. getQuarter(): number;
  47. setQuarter(quarter: number): CandyDate;
  48. addDays(amount: number): CandyDate;
  49. add(amount: number, mode: NormalizedMode): CandyDate;
  50. isSame(date: CandyDateType, grain?: CandyDateMode): boolean;
  51. isSameYear(date: CandyDateType): boolean;
  52. isSameQuarter(date: CandyDateType): boolean;
  53. isSameMonth(date: CandyDateType): boolean;
  54. isSameDay(date: CandyDateType): boolean;
  55. isSameHour(date: CandyDateType): boolean;
  56. isSameMinute(date: CandyDateType): boolean;
  57. isSameSecond(date: CandyDateType): boolean;
  58. isBefore(date: CandyDateType, grain?: CandyDateMode): boolean;
  59. isBeforeYear(date: CandyDateType): boolean;
  60. isBeforeQuarter(date: CandyDateType): boolean;
  61. isBeforeMonth(date: CandyDateType): boolean;
  62. isBeforeDay(date: CandyDateType): boolean;
  63. isToday(): boolean;
  64. isValid(): boolean;
  65. isFirstDayOfMonth(): boolean;
  66. isLastDayOfMonth(): boolean;
  67. private toNativeDate;
  68. }