@@ -2,6 +2,7 @@ import { describe, expect, test } from 'vitest';
2
2
import {
3
3
dateToExcelFormat ,
4
4
excelFormatToDate ,
5
+ fromTimestamp ,
5
6
isExcelFormat ,
6
7
isISO8601DateTimeString ,
7
8
isISO9075DateString ,
@@ -113,6 +114,46 @@ describe('date-time-converter models', () => {
113
114
expect ( isTimestamp ( 'foo' ) ) . toBe ( false ) ;
114
115
expect ( isTimestamp ( '' ) ) . toBe ( false ) ;
115
116
} ) ;
117
+
118
+ test ( 'should return true for valid Unix timestamps in microseconds' , ( ) => {
119
+ expect ( isTimestamp ( '1701227351995845' ) ) . toBe ( true ) ;
120
+ } ) ;
121
+
122
+ test ( 'should return false for invalid Unix timestamps in microseconds' , ( ) => {
123
+ expect ( isTimestamp ( '170122735199584' ) ) . toBe ( false ) ;
124
+ expect ( isTimestamp ( '17012273519958' ) ) . toBe ( false ) ;
125
+ } ) ;
126
+ } ) ;
127
+
128
+ describe ( 'isTimestampMicroSeconds' , ( ) => {
129
+ test ( 'should return true for valid Unix timestamps in microseconds' , ( ) => {
130
+ expect ( isTimestamp ( '1649792026123123' ) ) . toBe ( true ) ;
131
+ expect ( isTimestamp ( '1701227351995845' ) ) . toBe ( true ) ;
132
+ expect ( isTimestamp ( '0' ) ) . toBe ( true ) ;
133
+ } ) ;
134
+
135
+ test ( 'should return false for invalid Unix timestamps in microseconds' , ( ) => {
136
+ expect ( isTimestamp ( 'foo' ) ) . toBe ( false ) ;
137
+ expect ( isTimestamp ( '' ) ) . toBe ( false ) ;
138
+ } ) ;
139
+
140
+ test ( 'should return false for invalid Unix timestamps not in microseconds' , ( ) => {
141
+ expect ( isTimestamp ( '170122735199584' ) ) . toBe ( false ) ;
142
+ expect ( isTimestamp ( '17012273519958' ) ) . toBe ( false ) ;
143
+ } ) ;
144
+ } ) ;
145
+
146
+ describe ( 'fromTimestamp' , ( ) => {
147
+ test ( 'should return valid Date for valid Unix timestamps in microseconds' , ( ) => {
148
+ expect ( fromTimestamp ( '1649792026123123' ) . toString ( ) ) . toBe ( new Date ( 1649792026123 ) . toString ( ) ) ;
149
+ expect ( fromTimestamp ( '1701227351995845' ) . toString ( ) ) . toBe ( new Date ( 1701227351995 ) . toString ( ) ) ;
150
+ expect ( fromTimestamp ( '0' ) . toString ( ) ) . toBe ( new Date ( 0 ) . toString ( ) ) ;
151
+ } ) ;
152
+
153
+ test ( 'should return Date(0) for invalid Unix timestamps not in microseconds' , ( ) => {
154
+ expect ( fromTimestamp ( '170122735199584' ) . toString ( ) ) . toBe ( new Date ( 0 ) . toString ( ) ) ;
155
+ expect ( fromTimestamp ( '17012273519958' ) . toString ( ) ) . toBe ( new Date ( 0 ) . toString ( ) ) ;
156
+ } ) ;
116
157
} ) ;
117
158
118
159
describe ( 'isUTCDateString' , ( ) => {
0 commit comments