CodeSampleX

샘플

nesbot/carbon 3.13.2: Choose between Carbon and CarbonImmutable, and get timezone conversion, DST arithmetic and a frozen test clock right

검증된 샘플 — composer nesbot/carbon 3.13.2: Choose between Carbon and CarbonImmutable, and get timezone conversion, DST arithmetic and a frozen test clock right.…

sha256:db94b10dc83113f829139d9b6b88de71e978906568855aa20a460ba480bc0062

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
2
선언된 환경 php 8 linux x64 php 8 php composer

검증 실행 환경

환경 컨트랙트 단계 실행일
php 8 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · composer@1
2026-08-14
php 8 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · composer@1
2026-08-18

케이스

HOW
목표
Choose between Carbon and CarbonImmutable, and get timezone conversion, DST arithmetic and a frozen test clock right
패키지
심벌
  • Carbon.Carbon
  • Carbon.CarbonImmutable
  • CarbonInterface::addDay
  • CarbonInterface::avoidMutation
  • CarbonInterface::setTimezone
  • CarbonInterface::shiftTimezone
  • CarbonInterface::diffInDays
  • CarbonInterface::diffInHours
  • CarbonInterface::startOfDay
  • Carbon::parse
  • Carbon::setTestNow
  • Carbon::withTestNow
환경
php 8
생성일
2026-08-14T12:55:47Z

컨트랙트

  1. assert addDay on a Carbon rewrites the receiver and every other reference to it and returns that same object, while addDay on a CarbonImmutable leaves the receiver alone and only the returned value moves
  2. assert a bare addDay statement whose result is discarded is a write on Carbon and a silent no-op on CarbonImmutable
  3. assert Carbon extends DateTime and CarbonImmutable extends DateTimeImmutable and neither is an instance of the other, so only DateTimeInterface or CarbonInterface accepts both
  4. assert a Carbon and a CarbonImmutable holding the same instant compare equal with == and equalTo even across timezones, so comparison cannot detect the mixup
  5. assert copy clones on both classes while avoidMutation clones a Carbon and returns the same instance for a CarbonImmutable
  6. assert one slot-building loop returns three distinct dates on CarbonImmutable and three references to one date three days later on Carbon, and that it also advances the caller's start date
  7. assert the same loop written with avoidMutation returns the identical three dates for both classes and leaves the caller's start date alone
  8. assert setTimezone keeps the instant and changes the wall clock while shiftTimezone keeps the wall clock and moves the instant back by the offset, so the two answers print differently in Paris and have different UTC timestamps
  9. assert setTimezone and shiftTimezone both rewrite a Carbon argument in place and return that same object, so the shifting helper moves the caller's instant two hours while its wall clock still prints unchanged
  10. assert diffInDays reports 2.0 calendar days across both Paris DST boundaries while its third utc argument reports 47/24 and 49/24 elapsed days
  11. assert diffInDays applies that utc conversion on its own when the two dates name different zones, so reading either side in UTC returns the elapsed answer unasked
  12. assert diffInHours always reports elapsed hours, 47 and 49 across those same two spans, and has no utc parameter at all, so a third argument passed to it is discarded in silence
  13. assert the Carbon 3 diffs are signed floats, so reversing the arguments gives -2.0 days and -47.0 hours unless absolute is requested
  14. assert addDay across the spring-forward day moves 23 real hours while addHours(24) moves 86400 seconds and lands an hour later, and that startOfDay to endOfDay spans 23 hours less a microsecond on that day and 25 on the autumn one
  15. assert Carbon::parse reads a slash-separated numeric date as American m/d/y and a dash or dot separated one as European d-m-y, and throws InvalidFormatException only when the American reading is impossible
  16. assert parsing the repeated wall clock hour of the autumn transition yields the standard-time reading with isDST false, one hour later than the same wall clock reached by adding an hour, and that the nonexistent spring hour rolls forward instead of failing
  17. assert startOfDay uses the instance timezone, so midnight in Paris is the previous calendar day in UTC and converting to UTC before taking the boundary gives an instant one offset hour later
  18. assert Carbon::setTestNow freezes now, the constructor, parse('now') and CarbonImmutable::now to the identical microsecond for both classes through one shared switch
  19. assert the frozen clock is rendered in the ambient default timezone rather than the timezone of the value that was set, that relative strings resolve against it while PHP's own time() does not, and that setTestNowAndTimezone moves and restores the default timezone
  20. assert setTestNow with no argument clears the frozen clock for both classes, and that withTestNow restores the previous state even when its callback throws

파일

  • composer.json
  • composer.lock
  • csx.json
  • phpunit.xml
  • src/Schedule.php
  • test/ScheduleTest.php

소스 아티팩트 내려받기 (tar.gz)

오리진 시더

anonymous