1/* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {Timestamp, TimezoneInfo} from 'common/time'; 18import {TimestampConverter} from 'common/timestamp_converter'; 19 20class TimestampConverterTestUtils { 21 readonly ASIA_TIMEZONE_INFO: TimezoneInfo = { 22 timezone: 'Asia/Kolkata', 23 locale: 'en-US', 24 }; 25 readonly UTC_TIMEZONE_INFO: TimezoneInfo = { 26 timezone: 'UTC', 27 locale: 'en-US', 28 }; 29 30 readonly TIMESTAMP_CONVERTER = new TimestampConverter( 31 this.UTC_TIMEZONE_INFO, 32 0n, 33 0n, 34 ); 35 36 readonly TIMESTAMP_CONVERTER_WITH_UTC_OFFSET = new TimestampConverter( 37 this.ASIA_TIMEZONE_INFO, 38 0n, 39 0n, 40 ); 41 42 private readonly TIMESTAMP_CONVERTER_NO_RTE_OFFSET = new TimestampConverter({ 43 timezone: 'UTC', 44 locale: 'en-US', 45 }); 46 47 constructor() { 48 this.TIMESTAMP_CONVERTER_WITH_UTC_OFFSET.initializeUTCOffset( 49 this.TIMESTAMP_CONVERTER_WITH_UTC_OFFSET.makeTimestampFromRealNs(0n), 50 ); 51 } 52 53 makeRealTimestamp(valueNs: bigint): Timestamp { 54 return this.TIMESTAMP_CONVERTER.makeTimestampFromRealNs(valueNs); 55 } 56 57 makeRealTimestampWithUTCOffset(valueNs: bigint): Timestamp { 58 return this.TIMESTAMP_CONVERTER_WITH_UTC_OFFSET.makeTimestampFromRealNs( 59 valueNs, 60 ); 61 } 62 63 makeElapsedTimestamp(valueNs: bigint): Timestamp { 64 return this.TIMESTAMP_CONVERTER_NO_RTE_OFFSET.makeTimestampFromMonotonicNs( 65 valueNs, 66 ); 67 } 68} 69 70export const TimestampConverterUtils = new TimestampConverterTestUtils(); 71