deno.land / std@0.224.0 / datetime / day_of_year_test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertEquals } from "../assert/mod.ts";import { dayOfYear, dayOfYearUtc } from "./day_of_year.ts";
Deno.test({ name: "dayOfYearUtc()", fn: () => { // from https://golang.org/src/time/time_test.go // Test YearDay in several different scenarios // and corner cases // Non-leap-year tests assertEquals(dayOfYearUtc(new Date("2007-01-01T00:00:00.000Z")), 1); assertEquals(dayOfYearUtc(new Date("2007-01-15T00:00:00.000Z")), 15); assertEquals(dayOfYearUtc(new Date("2007-02-01T00:00:00.000Z")), 32); assertEquals(dayOfYearUtc(new Date("2007-02-15T00:00:00.000Z")), 46); assertEquals(dayOfYearUtc(new Date("2007-03-01T00:00:00.000Z")), 60); assertEquals(dayOfYearUtc(new Date("2007-03-15T00:00:00.000Z")), 74); assertEquals(dayOfYearUtc(new Date("2007-04-01T00:00:00.000Z")), 91); assertEquals(dayOfYearUtc(new Date("2007-12-31T00:00:00.000Z")), 365);
assertEquals(dayOfYearUtc(new Date("2007-01-01T00:00:00.000Z")), 1); assertEquals( dayOfYearUtc(new Date("2007-02-01T00:00:00.000Z")), 31 + 1, ); assertEquals( dayOfYearUtc(new Date("2007-03-01T00:00:00.000Z")), 31 + 28 + 1, ); assertEquals( dayOfYearUtc(new Date("2007-03-24T00:00:00.000Z")), 31 + 28 + 24, ); assertEquals( dayOfYearUtc(new Date("2007-03-25T00:00:00.000Z")), 31 + 28 + 25, ); assertEquals( dayOfYearUtc(new Date("2007-04-01T00:00:00.000Z")), 31 + 28 + 31 + 1, ); assertEquals( dayOfYearUtc(new Date("2007-05-01T00:00:00.000Z")), 31 + 28 + 31 + 30 + 1, ); assertEquals( dayOfYearUtc(new Date("2007-06-01T00:00:00.000Z")), 31 + 28 + 31 + 30 + 31 + 1, ); assertEquals( dayOfYearUtc(new Date("2007-07-01T00:00:00.000Z")), 31 + 28 + 31 + 30 + 31 + 30 + 1, ); assertEquals( dayOfYearUtc(new Date("2007-08-01T00:00:00.000Z")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 1, ); assertEquals( dayOfYearUtc(new Date("2007-09-01T00:00:00.000Z")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 1, ); assertEquals( dayOfYearUtc(new Date("2007-10-01T00:00:00.000Z")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 1, ); assertEquals( dayOfYearUtc(new Date("2007-10-27T00:00:00.000Z")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 27, ); assertEquals( dayOfYearUtc(new Date("2007-10-28T00:00:00.000Z")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 28, ); assertEquals( dayOfYearUtc(new Date("2007-11-01T00:00:00.000Z")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 1, ); assertEquals( dayOfYearUtc(new Date("2007-12-01T00:00:00.000Z")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 1, );
// Leap-year tests assertEquals(dayOfYearUtc(new Date("2008-01-01T00:00:00.000Z")), 1); assertEquals(dayOfYearUtc(new Date("2008-01-15T00:00:00.000Z")), 15); assertEquals(dayOfYearUtc(new Date("2008-02-01T00:00:00.000Z")), 32); assertEquals(dayOfYearUtc(new Date("2008-02-15T00:00:00.000Z")), 46); assertEquals(dayOfYearUtc(new Date("2008-03-01T00:00:00.000Z")), 61); assertEquals(dayOfYearUtc(new Date("2008-03-15T00:00:00.000Z")), 75); assertEquals(dayOfYearUtc(new Date("2008-04-01T00:00:00.000Z")), 92); assertEquals(dayOfYearUtc(new Date("2008-12-31T00:00:00.000Z")), 366);
// Looks like leap-year (but isn't) tests assertEquals(dayOfYearUtc(new Date("1900-01-01T00:00:00.000Z")), 1); assertEquals(dayOfYearUtc(new Date("1900-01-15T00:00:00.000Z")), 15); assertEquals(dayOfYearUtc(new Date("1900-02-01T00:00:00.000Z")), 32); assertEquals(dayOfYearUtc(new Date("1900-02-15T00:00:00.000Z")), 46); assertEquals(dayOfYearUtc(new Date("1900-03-01T00:00:00.000Z")), 60); assertEquals(dayOfYearUtc(new Date("1900-03-15T00:00:00.000Z")), 74); assertEquals(dayOfYearUtc(new Date("1900-04-01T00:00:00.000Z")), 91); assertEquals(dayOfYearUtc(new Date("1900-12-31T00:00:00.000Z")), 365);
// Year one tests (non-leap) assertEquals(dayOfYearUtc(new Date("0001-01-01T00:00:00.000Z")), 1); assertEquals(dayOfYearUtc(new Date("0001-01-15T00:00:00.000Z")), 15); assertEquals(dayOfYearUtc(new Date("0001-02-01T00:00:00.000Z")), 32); assertEquals(dayOfYearUtc(new Date("0001-02-15T00:00:00.000Z")), 46); assertEquals(dayOfYearUtc(new Date("0001-03-01T00:00:00.000Z")), 60); assertEquals(dayOfYearUtc(new Date("0001-03-15T00:00:00.000Z")), 74); assertEquals(dayOfYearUtc(new Date("0001-04-01T00:00:00.000Z")), 91); assertEquals(dayOfYearUtc(new Date("0001-12-31T00:00:00.000Z")), 365);
// Year minus one tests (non-leap) assertEquals( dayOfYearUtc(new Date("-000001-01-01T00:00:00.000Z")), 1, ); assertEquals( dayOfYearUtc(new Date("-000001-01-15T00:00:00.000Z")), 15, ); assertEquals( dayOfYearUtc(new Date("-000001-02-01T00:00:00.000Z")), 32, ); assertEquals( dayOfYearUtc(new Date("-000001-02-15T00:00:00.000Z")), 46, ); assertEquals( dayOfYearUtc(new Date("-000001-03-01T00:00:00.000Z")), 60, ); assertEquals( dayOfYearUtc(new Date("-000001-03-15T00:00:00.000Z")), 74, ); assertEquals( dayOfYearUtc(new Date("-000001-04-01T00:00:00.000Z")), 91, ); assertEquals( dayOfYearUtc(new Date("-000001-12-31T00:00:00.000Z")), 365, );
// 400 BC tests (leap-year) assertEquals( dayOfYearUtc(new Date("-000400-01-01T00:00:00.000Z")), 1, ); assertEquals( dayOfYearUtc(new Date("-000400-01-15T00:00:00.000Z")), 15, ); assertEquals( dayOfYearUtc(new Date("-000400-02-01T00:00:00.000Z")), 32, ); assertEquals( dayOfYearUtc(new Date("-000400-02-15T00:00:00.000Z")), 46, ); assertEquals( dayOfYearUtc(new Date("-000400-03-01T00:00:00.000Z")), 61, ); assertEquals( dayOfYearUtc(new Date("-000400-03-15T00:00:00.000Z")), 75, ); assertEquals( dayOfYearUtc(new Date("-000400-04-01T00:00:00.000Z")), 92, ); assertEquals( dayOfYearUtc(new Date("-000400-12-31T00:00:00.000Z")), 366, );
// Special Cases
// Gregorian calendar change (no effect) assertEquals(dayOfYearUtc(new Date("1582-10-04T03:24:00.000Z")), 277); assertEquals(dayOfYearUtc(new Date("1582-10-15T03:24:00.000Z")), 288); },});
Deno.test({ name: "dayOfYear()", fn: () => { // from https://golang.org/src/time/time_test.go // Test YearDay in several different scenarios // and corner cases // Non-leap-year tests assertEquals(dayOfYear(new Date("2007-01-01T00:00:00.000")), 1); assertEquals(dayOfYear(new Date("2007-01-15T00:00:00.000")), 15); assertEquals(dayOfYear(new Date("2007-02-01T00:00:00.000")), 32); assertEquals(dayOfYear(new Date("2007-02-15T00:00:00.000")), 46); assertEquals(dayOfYear(new Date("2007-03-01T00:00:00.000")), 60); assertEquals(dayOfYear(new Date("2007-03-15T00:00:00.000")), 74); assertEquals(dayOfYear(new Date("2007-04-01T00:00:00.000")), 91); assertEquals(dayOfYear(new Date("2007-12-31T00:00:00.000")), 365);
assertEquals(dayOfYear(new Date("2007-01-01T00:00:00.000")), 1); assertEquals( dayOfYear(new Date("2007-02-01T00:00:00.000")), 31 + 1, ); assertEquals( dayOfYear(new Date("2007-03-01T00:00:00.000")), 31 + 28 + 1, ); assertEquals( dayOfYear(new Date("2007-03-24T00:00:00.000")), 31 + 28 + 24, ); assertEquals( dayOfYear(new Date("2007-03-25T00:00:00.000")), 31 + 28 + 25, ); assertEquals( dayOfYear(new Date("2007-04-01T00:00:00.000")), 31 + 28 + 31 + 1, ); assertEquals( dayOfYear(new Date("2007-05-01T00:00:00.000")), 31 + 28 + 31 + 30 + 1, ); assertEquals( dayOfYear(new Date("2007-06-01T00:00:00.000")), 31 + 28 + 31 + 30 + 31 + 1, ); assertEquals( dayOfYear(new Date("2007-07-01T00:00:00.000")), 31 + 28 + 31 + 30 + 31 + 30 + 1, ); assertEquals( dayOfYear(new Date("2007-08-01T00:00:00.000")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 1, ); assertEquals( dayOfYear(new Date("2007-09-01T00:00:00.000")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 1, ); assertEquals( dayOfYear(new Date("2007-10-01T00:00:00.000")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 1, ); assertEquals( dayOfYear(new Date("2007-10-27T00:00:00.000")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 27, ); assertEquals( dayOfYear(new Date("2007-10-28T00:00:00.000")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 28, ); assertEquals( dayOfYear(new Date("2007-11-01T00:00:00.000")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 1, ); assertEquals( dayOfYear(new Date("2007-12-01T00:00:00.000")), 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 1, );
// Leap-year tests assertEquals(dayOfYear(new Date("2008-01-01T00:00:00.000")), 1); assertEquals(dayOfYear(new Date("2008-01-15T00:00:00.000")), 15); assertEquals(dayOfYear(new Date("2008-02-01T00:00:00.000")), 32); assertEquals(dayOfYear(new Date("2008-02-15T00:00:00.000")), 46); assertEquals(dayOfYear(new Date("2008-03-01T00:00:00.000")), 61); assertEquals(dayOfYear(new Date("2008-03-15T00:00:00.000")), 75); assertEquals(dayOfYear(new Date("2008-04-01T00:00:00.000")), 92); assertEquals(dayOfYear(new Date("2008-12-31T00:00:00.000")), 366);
// Looks like leap-year (but isn't) tests assertEquals(dayOfYear(new Date("1900-01-01T00:00:00.000")), 1); assertEquals(dayOfYear(new Date("1900-01-15T00:00:00.000")), 15); assertEquals(dayOfYear(new Date("1900-02-01T00:00:00.000")), 32); assertEquals(dayOfYear(new Date("1900-02-15T00:00:00.000")), 46); assertEquals(dayOfYear(new Date("1900-03-01T00:00:00.000")), 60); assertEquals(dayOfYear(new Date("1900-03-15T00:00:00.000")), 74); assertEquals(dayOfYear(new Date("1900-04-01T00:00:00.000")), 91); assertEquals(dayOfYear(new Date("1900-12-31T00:00:00.000")), 365);
// Year one tests (non-leap) assertEquals(dayOfYear(new Date("0001-01-01T00:00:00.000")), 1); assertEquals(dayOfYear(new Date("0001-01-15T00:00:00.000")), 15); assertEquals(dayOfYear(new Date("0001-02-01T00:00:00.000")), 32); assertEquals(dayOfYear(new Date("0001-02-15T00:00:00.000")), 46); assertEquals(dayOfYear(new Date("0001-03-01T00:00:00.000")), 60); assertEquals(dayOfYear(new Date("0001-03-15T00:00:00.000")), 74); assertEquals(dayOfYear(new Date("0001-04-01T00:00:00.000")), 91); assertEquals(dayOfYear(new Date("0001-12-31T00:00:00.000")), 365);
// Year minus one tests (non-leap) assertEquals( dayOfYear(new Date("-000001-01-01T00:00:00.000")), 1, ); assertEquals( dayOfYear(new Date("-000001-01-15T00:00:00.000")), 15, ); assertEquals( dayOfYear(new Date("-000001-02-01T00:00:00.000")), 32, ); assertEquals( dayOfYear(new Date("-000001-02-15T00:00:00.000")), 46, ); assertEquals( dayOfYear(new Date("-000001-03-01T00:00:00.000")), 60, ); assertEquals( dayOfYear(new Date("-000001-03-15T00:00:00.000")), 74, ); assertEquals( dayOfYear(new Date("-000001-04-01T00:00:00.000")), 91, ); assertEquals( dayOfYear(new Date("-000001-12-31T00:00:00.000")), 365, );
// 400 BC tests (leap-year) assertEquals( dayOfYear(new Date("-000400-01-01T00:00:00.000")), 1, ); assertEquals( dayOfYear(new Date("-000400-01-15T00:00:00.000")), 15, ); assertEquals( dayOfYear(new Date("-000400-02-01T00:00:00.000")), 32, ); assertEquals( dayOfYear(new Date("-000400-02-15T00:00:00.000")), 46, ); assertEquals( dayOfYear(new Date("-000400-03-01T00:00:00.000")), 61, ); assertEquals( dayOfYear(new Date("-000400-03-15T00:00:00.000")), 75, ); assertEquals( dayOfYear(new Date("-000400-04-01T00:00:00.000")), 92, ); assertEquals( dayOfYear(new Date("-000400-12-31T00:00:00.000")), 366, );
// Special Cases
// Gregorian calendar change (no effect) assertEquals(dayOfYear(new Date("1582-10-04T03:24:00.000")), 277); assertEquals(dayOfYear(new Date("1582-10-15T03:24:00.000")), 288); },});
Version Info