C.W.K.
Stream
Lesson 04 of 08 · published

Number, boolean, 날짜 — 네이티브 타입

~10 min · toml, numbers, dates

Level 0평문
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

JSON 위 TOML 의 가장 큰 이점: 진짜 날짜

Number

  • 정수 — 64-bit signed. 42, -17, 1_000_000 (밑줄 자릿수 그룹화). 16 진/8 진/2 진 리터럴: 0xff, 0o755, 0b1010.
  • Float — IEEE 754 double. 3.14, 1e6, 1.5e-3. 특수 값: inf, -inf, nan (literal — JSON 이 이건 허용 안 함).

Boolean

소문자만: true 또는 false. True 안 됨, TRUE 안 됨, yes 안 됨. Norway 문제 여기 못 일어남 — 각 표기 한 가지.

날짜와 시간 — 킬러 feature

  • Offset Date-Time — timezone 든 RFC 3339. 1979-05-27T07:32:00-08:00. 가장 정밀한 형태.
  • Local Date-Time — timezone 없음. 1979-05-27T07:32:00.
  • Local Date1979-05-27.
  • Local Time07:32:00.

네이티브 날짜가 datetime 객체 (Python), chrono::DateTime (Rust), time.Time (Go) 로 직접 파싱. config loader 에 'ISO 8601 string 으로 파싱' 코드 없음.

원칙: 데이터에 날짜 있으면 JSON 위 TOML 선호. JSON 이 '관행상 string' + 파서 통과 강제; TOML 이 박스 밖 강타입 값. downstream 코드 짧고 버그 적음.

Code

Number — 모든 형태·toml
# 정수
int_dec    = 1_000_000
int_hex    = 0xff
int_oct    = 0o755
int_bin    = 0b1010
int_neg    = -17

# Float
float_basic = 3.14
float_sci   = 6.022e23
float_neg   = -1.5e-3

# 특수 — TOML 이 허용, JSON 안 함
float_inf  = inf
float_ninf = -inf
float_nan  = nan
Boolean + JSON 대비·toml
is_active = true
is_admin  = false

# 이건 다 파스 에러:
# is_active = True
# is_active = TRUE
# is_active = yes
# is_active = 1
날짜 — 네 가지 flavor·toml
offset_dt = 1979-05-27T07:32:00-08:00
utc_dt    = 1979-05-27T07:32:00Z
local_dt  = 1979-05-27T07:32:00
local_d   = 1979-05-27
local_t   = 07:32:00
Python parse — 박스 밖 강타입·python
import tomllib
from datetime import datetime, date, time

data = tomllib.loads('''
started_at = 2026-05-04T01:30:11+09:00
launch_date = 2026-05-15
''')

assert isinstance(data['started_at'], datetime)
assert isinstance(data['launch_date'], date)
# Reviver 없음, string 파싱 없음 — 박스 밖 강타입 값.

External links

Exercise

UTC timestamp, local-only 날짜, 16 진 리터럴 byte mask, 자릿수 그룹화 정수 든 TOML config 작성. Python tomllib 으로 파싱하고 타입 검증 — datetime, date, int, int. JSON 등가와 비교: 모든 날짜가 string 이고 파싱 잊으면 안 되는 거.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.