|
1 | 1 | package com.yourssu.logging.system
|
2 | 2 |
|
| 3 | +import android.annotation.SuppressLint |
3 | 4 | import android.content.Context
|
| 5 | +import android.os.Build |
4 | 6 | import android.util.Log
|
5 | 7 | import androidx.work.OneTimeWorkRequestBuilder
|
6 | 8 | import androidx.work.WorkManager
|
7 | 9 | import androidx.work.workDataOf
|
8 | 10 | import com.google.gson.Gson
|
9 | 11 | import com.yourssu.logging.system.remote.RemoteLoggingWorker
|
10 | 12 | import java.security.MessageDigest
|
| 13 | +import java.text.SimpleDateFormat |
11 | 14 | import java.time.OffsetDateTime
|
12 | 15 | import java.time.ZoneOffset
|
13 | 16 | import java.time.format.DateTimeFormatter
|
| 17 | +import java.util.Date |
| 18 | +import java.util.TimeZone |
14 | 19 |
|
15 | 20 | /**
|
16 | 21 | * Yourssu Logging System, inspired by [Timber](https://github.com/JakeWharton/timber)
|
@@ -222,11 +227,20 @@ class YLS private constructor() {
|
222 | 227 | /**
|
223 | 228 | * 현재 시각을 ISO 8601 포맷의 문자열을 반환합니다.
|
224 | 229 | *
|
| 230 | + * "yyyy-MM-dd'T'HH:mm:ss'Z'" |
| 231 | + * |
225 | 232 | * @return ISO 8601 format string of current
|
226 | 233 | */
|
| 234 | + @SuppressLint("SimpleDateFormat") |
227 | 235 | fun getTimestamp(): String {
|
228 |
| - return OffsetDateTime.now(ZoneOffset.UTC) |
229 |
| - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")) |
| 236 | + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| 237 | + OffsetDateTime.now(ZoneOffset.UTC) |
| 238 | + .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) |
| 239 | + } else { |
| 240 | + SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").apply { |
| 241 | + timeZone = TimeZone.getTimeZone("UTC") |
| 242 | + }.format(Date()) |
| 243 | + } |
230 | 244 | }
|
231 | 245 |
|
232 | 246 | /** SHA-256 알고리즘으로 `origin`을 암호화 한 문자열을 반환합니다. */
|
|
0 commit comments