@@ -16,6 +16,24 @@ export class TimeService {
16
16
return result . substr ( 11 , 8 )
17
17
}
18
18
19
+ public static async getTimeByTimeZone ( timeZone : string ) : Promise < string > {
20
+
21
+ const allTimeZones = JSON . parse ( await Persistence . readFromLocalFile ( `${ Deno . cwd ( ) } /timezones.json` ) )
22
+
23
+ const entry = allTimeZones . filter ( ( e : any ) => e . timezone === timeZone ) [ 0 ]
24
+
25
+ const minutes = Number ( TimeService . convertOffsetToMinutes ( entry . dayLightSavingTimeOffset ) . toString ( ) )
26
+
27
+ log . warning ( minutes )
28
+ let getDifferenceToUtcInMilisec = minutes * 60000 ;
29
+ let getUTCMilisecond = new Date ( ) . getTime ( ) ;
30
+
31
+ const result = new Date ( getUTCMilisecond - getDifferenceToUtcInMilisec ) . toISOString ( )
32
+
33
+
34
+ return result . substr ( 11 , 8 )
35
+ }
36
+
19
37
public static async getTimeZone ( countryCode : string , cityName : string ) : Promise < string > {
20
38
21
39
const entry = await TimeService . getTimeZoneEntry ( countryCode , cityName )
@@ -54,9 +72,8 @@ export class TimeService {
54
72
}
55
73
56
74
private static async getTimeZoneEntry ( countryCode : string , cityName : string ) : Promise < any > {
57
- const myPath = `${ Deno . cwd ( ) } /timezones.json`
58
- const allTimeZones = JSON . parse ( await Persistence . readFromLocalFile ( myPath ) )
59
75
76
+ const allTimeZones = JSON . parse ( await Persistence . readFromLocalFile ( `${ Deno . cwd ( ) } /timezones.json` ) )
60
77
61
78
const entry = allTimeZones . filter ( ( e : any ) => e . iso2 === countryCode && ( e . city === cityName || e . city_ascii === cityName ) ) [ 0 ]
62
79
if ( entry === undefined ) {
@@ -65,5 +82,4 @@ export class TimeService {
65
82
66
83
return entry
67
84
}
68
-
69
85
}
0 commit comments