{"id":32136837,"url":"https://github.com/wavebitscientific/datetime-fortran","last_synced_at":"2026-02-21T17:03:25.169Z","repository":{"id":8427695,"uuid":"10015743","full_name":"wavebitscientific/datetime-fortran","owner":"wavebitscientific","description":"Date and time manipulation for modern Fortran","archived":false,"fork":false,"pushed_at":"2023-06-20T14:15:25.000Z","size":329,"stargazers_count":148,"open_issues_count":10,"forks_count":52,"subscribers_count":21,"default_branch":"main","last_synced_at":"2025-12-28T15:13:48.393Z","etag":null,"topics":["datetime","fortran","strftime","timedelta"],"latest_commit_sha":null,"homepage":"","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wavebitscientific.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2013-05-12T15:53:35.000Z","updated_at":"2025-12-13T11:41:14.000Z","dependencies_parsed_at":"2023-02-17T03:15:50.695Z","dependency_job_id":"6014b5e9-d50e-45f0-a9a9-3a0265dbe184","html_url":"https://github.com/wavebitscientific/datetime-fortran","commit_stats":{"total_commits":272,"total_committers":10,"mean_commits":27.2,"dds":"0.16911764705882348","last_synced_commit":"9bd51beef9c4abdf0098854387987f0ac40dc879"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/wavebitscientific/datetime-fortran","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavebitscientific%2Fdatetime-fortran","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavebitscientific%2Fdatetime-fortran/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavebitscientific%2Fdatetime-fortran/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavebitscientific%2Fdatetime-fortran/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wavebitscientific","download_url":"https://codeload.github.com/wavebitscientific/datetime-fortran/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wavebitscientific%2Fdatetime-fortran/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29688216,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T15:51:39.154Z","status":"ssl_error","status_checked_at":"2026-02-21T15:49:03.425Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datetime","fortran","strftime","timedelta"],"created_at":"2025-10-21T04:42:11.082Z","updated_at":"2026-02-21T17:03:25.146Z","avatar_url":"https://github.com/wavebitscientific.png","language":"Fortran","funding_links":[],"categories":["Date and time manipulation"],"sub_categories":[],"readme":"# datetime-fortran\n\n[![Actions Status](https://github.com/wavebitscientific/datetime-fortran/workflows/ci/badge.svg)](https://github.com/wavebitscientific/datetime-fortran/actions)\n[![GitHub issues](https://img.shields.io/github/issues/wavebitscientific/datetime-fortran.svg)](https://github.com/wavebitscientific/datetime-fortran/issues)\n\nDate and time manipulation for modern Fortran.\nThe fundamental time step is one millisecond.\n\n## Getting started\n\nFirst, get the code by cloning this repo:\n\n```sh\ngit clone https://github.com/wavebitscientific/datetime-fortran\ncd datetime-fortran\n```\n\nor by downloading a [release tarball](https://github.com/wavebitscientific/datetime-fortran/releases).\nThe latter is recommended if you want to build datetime-fortran with autotools and make.\n\nYou can build datetime-fortran with FPM, autotools, CMake, or by simply including\nthe source file \"src/datetime_module.f90\" in your project.\nNOTE: Windows additionally requires \"src/strptime.cpp\" in your project.\n\n### FPM\n\nAs of version 1.7.0, datetime-fortran can be built using the\n[Fortran Package Manager](https://github.com/fortran-lang/fpm).\nFollow the directions on that page to install FPM if you haven't already.\n\nTo build, type:\n\n```sh\nfpm build\n```\n\nbinary artifacts are created in:\n\n* Library and module files: `build/gfortran_debug/library`\n* test executables: `build/gfortran_debug/tests`.\n\nTo run the tests, type:\n\n```sh\nfpm test\n```\n\n### Autotools\n\n```\n./configure\nmake check\nmake install\n```\n\nIf you cloned the repo instead of downloading a release tarball,\nrun `autoreconf -i` first to generate the `configure` script.\n\n### CMake\n\n```sh\ncmake -B build\ncmake --build build\n```\n\nbinary artifacts are created in:\n\n* Library: `build/lib/libdatetime`\n* module: `build/include/datetime.mod`\n* test executable: `build/bin/datetime_tests`\n\noptionally, to install (replace \"~/mylibs\" with your desired install directory):\n\n```sh\ncmake -B build -DCMAKE_INSTALL_PREFIX=~/mylibs\ncmake --install build\n```\n\noptionally, to run self-tests:\n\n```sh\ncd build\nctest -V\n```\n\n## Use\n\nStart using datetime-fortran in your code by importing derived types from the module:\n\n```fortran\nuse datetime_module, only: datetime, timedelta, clock\n```\n\nSee some basic examples [here](examples).\n\n\u003ca id=\"top\"\u003e\u003c/a\u003e\n\n## API\n\n* [Derived Types](#derived-types)\n    * [*datetime*](#datetime)\n        * [*getYear*](#getyear)\n        * [*getMonth*](#getmonth)\n        * [*getDay*](#getday)\n        * [*getHour*](#gethour)\n        * [*getMinute*](#getminute)\n        * [*getSecond*](#getsecond)\n        * [*getMillisecond*](#getmillisecond)\n        * [*isocalendar*](#isocalendar)\n        * [*isoformat*](#isoformat)\n        * [*isValid*](#isvalid)\n        * [*now*](#now)\n        * [*secondsSinceEpoch*](#secondssinceepoch)\n        * [*strftime*](#strftime)\n        * [*tm*](#tm)\n        * [*tzOffset*](#tzoffset)\n        * [*utc*](#utc)\n        * [*weekday*](#weekday)\n        * [*weekdayLong*](#weekdaylong)\n        * [*weekdayShort*](#weekdayshort)\n        * [*yearday*](#yearday)\n    * [*timedelta*](#timedelta)\n        * [*total_seconds*](#total_seconds)\n    * [*clock*](#clock)\n        * [*reset*](#reset)\n        * [*tick*](#tick)\n    * [*tm_struct*](#tm_struct)\n* [Overloaded operators](#overloaded-operators)\n    * [Arithmetic operators](#arithmetic-operators)\n    * [Comparison operators](#comparison-operators)\n* [Public procedures](#public-procedures)\n    * [*c_strftime*](#c_strftime)\n    * [*c_strptime*](#c_strptime)\n    * [*date2num*](#date2num)\n    * [*datetimeRange*](#datetimerange)\n    * [*daysInMonth*](#daysinmonth)\n    * [*daysInYear*](#daysinyear)\n    * [*isLeapYear*](#isleapyear)\n    * [*num2date*](#num2date)\n    * [*strptime*](#strptime)\n    * [*tm2date*](#tm2date)\n    * [*machinetimezone*](#machinetimezone)\n    * [*epochdatetime*](#epochdatetime)\n    * [*localtime*](#localtime)\n    * [*gmtime*](#gmtime)\n\n## Derived Types\u003ca id=\"derived-types\"\u003e\u003c/a\u003e\n\n*datetime-fortran* library provides the following derived types:\n[*datetime*](#datetime), [*timedelta*](#timedelta),\n[*clock*](#clock) and [*tm_struct*](#tm_struct).\n\n### datetime \u003ca id=\"datetime\"\u003e\u003c/a\u003e\n\nMain date and time object, defined as:\n\n```fortran\ntype :: datetime\n\n  !! Main datetime class for date and time representation.\n\n  private\n\n  integer :: year        = 1 !! year [1-HUGE(year)]\n  integer :: month       = 1 !! month in year [1-12]\n  integer :: day         = 1 !! day in month [1-31]\n  integer :: hour        = 0 !! hour in day [0-23]\n  integer :: minute      = 0 !! minute in hour [0-59]\n  integer :: second      = 0 !! second in minute [0-59]\n  integer :: millisecond = 0 !! milliseconds in second [0-999]\n\n  real(kind=real64) :: tz = 0 !! timezone offset from UTC [hours]\n\n  contains\n\n  ! getter functions\n  procedure,pass(self),public :: getYear\n  procedure,pass(self),public :: getMonth\n  procedure,pass(self),public :: getDay\n  procedure,pass(self),public :: getHour\n  procedure,pass(self),public :: getMinute\n  procedure,pass(self),public :: getSecond\n  procedure,pass(self),public :: getMillisecond\n  procedure,pass(self),public :: getTz\n\n  ! public methods\n  procedure,pass(self),public :: isocalendar\n  procedure,pass(self),public :: isoformat\n  procedure,pass(self),public :: isValid\n  procedure,nopass,    public :: now\n  procedure,pass(self),public :: secondsSinceEpoch\n  procedure,pass(self),public :: strftime\n  procedure,pass(self),public :: tm\n  procedure,pass(self),public :: tzOffset\n  procedure,pass(self),public :: utc\n  procedure,pass(self),public :: weekday\n  procedure,pass(self),public :: isoweekday\n  procedure,pass(self),public :: weekdayLong\n  procedure,pass(self),public :: isoweekdayLong\n  procedure,pass(self),public :: weekdayShort\n  procedure,pass(self),public :: isoweekdayShort\n  procedure,pass(self),public :: yearday\n\n  ! private methods\n  procedure,pass(self),private :: addMilliseconds\n  procedure,pass(self),private :: addSeconds\n  procedure,pass(self),private :: addMinutes\n  procedure,pass(self),private :: addHours\n  procedure,pass(self),private :: addDays\n\n  ! operator overloading procedures\n  procedure,pass(d0),private :: datetime_plus_timedelta\n  procedure,pass(d0),private :: timedelta_plus_datetime\n  procedure,pass(d0),private :: datetime_minus_datetime\n  procedure,pass(d0),private :: datetime_minus_timedelta\n  procedure,pass(d0),private :: eq\n  procedure,pass(d0),private :: neq\n  procedure,pass(d0),private :: gt\n  procedure,pass(d0),private :: ge\n  procedure,pass(d0),private :: lt\n  procedure,pass(d0),private :: le\n\n  generic :: operator(+)  =\u003e datetime_plus_timedelta,\u0026\n                             timedelta_plus_datetime\n  generic :: operator(-)  =\u003e datetime_minus_datetime,\u0026\n                             datetime_minus_timedelta\n  generic :: operator(==) =\u003e eq\n  generic :: operator(/=) =\u003e neq\n  generic :: operator(\u003e)  =\u003e gt\n  generic :: operator(\u003e=) =\u003e ge\n  generic :: operator(\u003c)  =\u003e lt\n  generic :: operator(\u003c=) =\u003e le\n\nendtype datetime\n```\n\n[*datetime*](#datetime) components are initialized by default, so all arguments are optional.\nArguments may be provided as positional arguments, in the order of their declaration,\nor as keyword arguments, in any order. If both positional and keyword arguments are used,\nno positional arguments may appear after a keyword argument.\n\n#### Example usage\n\n```fortran\nuse datetime_module, only:datetime\n\ntype(datetime) :: a\n\n! Initialize as default:\na = datetime() ! 0001-01-01 00:00:00\n\n! Components can be specified by position:\na = datetime(1984, 12, 10) ! 1984-12-10 00:00:00\n\n! Or by keyword:\na = datetime(month=1, day=1, year=1970) ! 1970-01-01 00:00:00\n\n! Or combined:\na = datetime(2013, 2, minute=23, day=5) ! 2013-02-05 00:23:00\n\n! With timezone offset:\na = datetime(2013, 2, minute=23, day=5, tz=-4) ! 2013-02-05 00:23:00 -0400\n\n! Do not use positional after keyword arguments:\na = datetime(year=2013, 2, minute=23, day=5) ! ILLEGAL\n```\n\nNote that the current implementation of [*datetime*](#datetime)\ndoes not support daylight saving time (DST) information.\n\n#### See also\n\n* [*timedelta*](#timedelta)\n\n* [*tm_struct*](#tm_struct)\n\n[Back to top](#top)\n\n\u003chr\u003e\n\n### getYear\u003ca id=\"getyear\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental integer function getYear(self)\n  class(datetime),intent(in) :: self\n```\nReturns the year of a `datetime` instance.\n\n[Back to top](#top)\n\u003chr\u003e\n\n### getMonth\u003ca id=\"getmonth\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental integer function getMonth(self)\n  class(datetime),intent(in) :: self\n```\nReturns the month of a `datetime` instance.\n\n[Back to top](#top)\n\u003chr\u003e\n\n### getDay\u003ca id=\"getday\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental integer function getDay(self)\n  class(datetime),intent(in) :: self\n```\nReturns the day of a `datetime` instance.\n\n[Back to top](#top)\n\u003chr\u003e\n\n### getHour\u003ca id=\"gethour\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental integer function getHour(self)\n  class(datetime),intent(in) :: self\n```\nReturns the hour of a `datetime` instance.\n\n[Back to top](#top)\n\u003chr\u003e\n\n### getMinute\u003ca id=\"getminute\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental integer function getMinute(self)\n  class(datetime),intent(in) :: self\n```\nReturns the minute of a `datetime` instance.\n\n[Back to top](#top)\n\u003chr\u003e\n\n### getSecond\u003ca id=\"getsecond\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental integer function getSecond(self)\n  class(datetime),intent(in) :: self\n```\nReturns the second of a `datetime` instance.\n\n[Back to top](#top)\n\u003chr\u003e\n\n### getMillisecond\u003ca id=\"getmillisecond\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental integer function getMillisecond(self)\n  class(datetime),intent(in) :: self\n```\nReturns the millisecond of a `datetime` instance.\n\n[Back to top](#top)\n\u003chr\u003e\n\n### isocalendar\u003ca id=\"isocalendar\"\u003e\u003c/a\u003e\n\n```fortran\nfunction isocalendar(self)\n  class(datetime),intent(in) :: self\n  integer,dimension(3)       :: isocalendar\n```\n\nReturns an array of 3 integers: year, week number, and week day,\nas defined by [ISO 8601 week date](http://en.wikipedia.org/wiki/ISO_week_date).\nThe ISO calendar is a widely used variant of the Gregorian calendar.\nThe ISO year consists of 52 or 53 full weeks.\nA week starts on a Monday (1) and ends on a Sunday (7).\nThe first week of an ISO year is the first (Gregorian) calendar week\nof a year containing a Thursday.\nThis is called week number 1, and the ISO year of that Thursday\nis the same as its Gregorian year.\n\n[*datetime%isocalendar()*](#isocalendar) is equivalent to Python's\n[*datetime.datetime.isocalendar()*](http://docs.python.org/2/library/datetime.html#datetime.datetime.isocalendar).\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime) :: a\n\na = datetime(2013,1,1)\nprint *, a % isocalendar() ! Prints: 2013  1  2\n```\n\n#### See also\n\n* [*weekday*](#weekday)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### isoformat\u003ca id=\"isoformat\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental character(len=23) function isoformat(self,sep)\n  class(datetime), intent(in)          :: self\n  character(len=1),intent(in),optional :: sep\n```\n\nReturns a character string of length 23 that contains date and time in ISO 8601\nformat.\n\n[*datetime%isoformat()*](#isoformat) is equivalent to Python's\n[*datetime.datetime.isoformat()*](http://docs.python.org/2/library/datetime.html#datetime.datetime.isoformat),\nwith the only difference being that [*datetime%isoformat()*](#isoformat) returns the milliseconds\nat the end of the string, where as\n[*datetime.datetime.isoformat()*](http://docs.python.org/2/library/datetime.html#datetime.datetime.isoformat)\nreturns microseconds.\n\n#### Arguments\n\n`sep` is an optional argument that specifies which character of length 1 will\nseparate date and time entries. If ommited, defaults to `T`.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime) :: a\n\na = datetime(1984,12,10,13,5,0)\n\n! Without arguments:\nprint *, a % isoformat() ! Prints 1984-12-10T13:05:00.000\n\n! With a specified separator:\nprint *, a % isoformat(' ') ! Prints 1984-12-10 13:05:00.000\n```\n\n#### See also\n\n[Back to top](#top)\n\u003chr\u003e\n\n### isValid\u003ca id=\"isvalid\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental logical function isValid(self)\n  class(datetime),intent(in) :: self\n```\n\nReturns `.true.` if all [*datetime*](#datetime) instance components\nhave valid values, and .false. otherwise. Components have valid values\nif they are within the range indicated in [*datetime*](#datetime)\nderived type description.\n\nUseful for debugging and validating user input.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime) :: a\n\na = datetime(1984,12,10,13,5,0)\n\nprint *, a % isValid()! .true.\n\na = datetime(1984,13,10,13,5,0)\n\nprint *, a % isValid() ! .false.\n```\n\n#### See also\n\n[Back to top](#top)\n\u003chr\u003e\n\n### now\u003ca id=\"now\"\u003e\u003c/a\u003e\n\n```fortran\ntype(datetime) function now(self)\n  class(datetime),intent(in) :: self\n```\n\nReturns the [*datetime*](#datetime) instance representing\nthe current machine time. Does not support timezones.\n\n#### Return value\n\n`self` A `datetime` instance with current machine time.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime) :: a\n\na = a % now() ! Assigns current machine time to a\n```\n\n[Back to top](#top)\n\u003chr\u003e\n\n### secondsSinceEpoch\u003ca id=\"secondssinceepoch\"\u003e\u003c/a\u003e\n\n```fortran\ninteger function secondsSinceEpoch(self)\n  class(datetime),intent(in) :: self\n```\n\nReturns an integer number of seconds since the\nUNIX Epoch, `1970-01-01 00:00:00 +0000` (UTC).\n\n#### Return value\n\n`secondsSinceEpoch` An `integer` scalar containing number of seconds since\nUNIX Epoch.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime) :: a\n\n! Initialize:\na = datetime(2013,1,1)\n\nprint *, a%secondsSinceEpoch()\n```\n\n[Back to top](#top)\n\u003chr\u003e\n\n### strftime\u003ca id=\"strfime\"\u003e\u003c/a\u003e\n\n```fortran\ncharacter(len=maxstrlen) function strftime(self,format)\n  class(datetime), intent(in) :: self\n  character(len=*),intent(in) :: format\n```\n\nA *datetime*-bound method that serves as a wrapper around the\nC routine *strftime*.\n`datetime%strftime` takes only the format string as argument,\nand returns the character string representation of the time\ninformation contained in the datetime instance. Thus, this function\ntakes care of the conversion to `tm_struct` and calling the raw C *strftime*.\nBecause Fortran does not allow assumed-length character strings as\nthe type of the function result, a fixed length of `MAXSTRLEN` is used.\n`MAXSTRLEN` is currently set to `99`. It is assumed that the desired\ntime string is shorter than this value.\nAny resulting string shorter than `MAXSTRLEN` is padded with spaces,\nso it is best to trim the result using the `TRIM` intrinsic function\n(see the usage example below).\nThis *datetime*-bound method is available since version `0.3.0`.\n\n#### Arguments\n\n`format` A character string describing the desired format of date and time.\nSame as the format for the raw C [*strftime*](#c_strftime).\n\n#### Return value\n\nA `character(len=maxstrlen)` representation of *datetime* using `format`.\n\n#### Example usage\n\n```fortran\nuse datetime_module\n\ntype(datetime)  :: a\n\na = a % now()\nprint *, a % isoformat()\n\nprint *, trim(a % strftime(\"%Y %B %d\"))\n```\n\n#### See also\n\n* [*c_strftime*](#c_strftime)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### tm\u003ca id=\"tm\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental type(tm_struct) function tm(self)\n  CLASS(datetime),intent(in) :: self\n```\n\nReturns a [*tm_struct*](#tm_struct) instance that matches the\ntime and date information in the caller [*datetime*](#datetime)\ninstance.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime)  :: a\ntype(tm_struct) :: tm\n\n! Initialize:\na = datetime(2013,1,1)\n\n! Get tm_struct from datetime:\ntm = a % tm()\n```\n\n#### See also\n\n* [*tm_struct*](#tm_struct)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### tzOffset\n\n```fortran\npure elemental character(len=5) function tzOffset(self)\n  class(datetime),intent(in) :: self\n```\n\nGiven a [*datetime*](#datetime) instance, returns a character string with timezone\noffset in hours from UTC (Coordinated Universal Time), in format `+hhmm`\nor `-hhmm`, depending on the sign, where `hh` are hours and `mm` are minutes.\n\n#### Arguments\n\nNone.\n\n#### Return value\n\n`tzOffset` A `character(len=5)` in the form `+hhmm`\nor `-hhmm`, depending on the sign.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime)  :: a\ntype(tm_struct) :: tm\n\n! Initialize a datetime instance with timezone offset of -4.75 hours:\na = datetime(2013,1,1,tz=-4.75)\n\n! Write tzOffset on screen:\nprint *, a % tzOffset ! -0445 (offset of 4 hours and 45 minutes)\n```\n\n[Back to top](#top)\n\u003chr\u003e\n\n### utc\n\n```fortran\npure elemental type(datetime) function utc(self)\n  class(datetime),intent(in) :: self\n```\n\nReturns the datetime instance at Coordinated Universal Time (UTC).\n\n#### Return value\n\n`utc` A `datetime` instance with at UTC (tz = 0).\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime)  :: a\ntype(tm_struct) :: tm\n\n! Initialize a datetime instance with timezone offset of -4.75 hours:\na = datetime(2013,1,1,tz=-4.75)\n\nprint *, a % isoformat() // a % tzOffset() ! 2013-01-01T00:00:00.000-0445\n\n! Convert a to UTC:\na = a % utc()\n\nprint *, a % isoformat() // a % tzOffset() ! 2013-01-01T04:45:00.000+0000\n```\n\n#### See also\n\n* [*tzOffset*](#tzoffset)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### weekday\u003ca id=\"weekday\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental integer function weekday(self)\n  class(datetime),intent(in) :: self\n```\n\nA [*datetime*](#datetime)-bound method to calculate day of the week using\n [Zeller's congruence](http://en.wikipedia.org/wiki/Zeller%27s_congruence).\nReturns an integer scalar in the range of [0-6], starting from Sunday.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime)  :: a\n\n! Initialize:\na = datetime(2013,1,1)\n\nprint *, a % weekday() ! 2\n```\n\n#### See also\n\n* [*weekdayLong*](#weekdaylong)\n\n* [*weekdayShort*](#weekdayshort)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### weekdayLong\u003ca id=\"weekdaylong\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental character(len=9) function weekdayLong(self)\n  class(datetime),intent(in) :: self\n```\n\nReturns the full name of the day of the week.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime)  :: a\n\n! Initialize:\na = datetime(2013,1,1)\n\nprint *, a % weekdayLong() ! Tuesday\n```\n\n#### See also\n\n* [*weekday*](#weekday)\n\n* [*weekdayShort*](#weekdayshort)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### weekdayShort\u003ca id=\"weekdayshort\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental character(len=3) function weekdayShort(self)\n  class(datetime),intent(in) :: self\n```\n\nReturns the abbreviated (e.g. Mon) name of the day of the week.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime)  :: a\n\n! Initialize:\na = datetime(2013,1,1)\n\nprint *, a % weekdayShort() ! Tue\n```\n\n#### See also\n\n* [*weekday*](#weekday)\n\n* [*weekdayLong*](#weekdaylong)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### yearday\u003ca id=\"yearday\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental integer function yearday(self)\n  class(datetime),intent(in) :: self\n```\n\n[*datetime*](#datetime)-bound procedure.\nReturns integer day of the year (ordinal date).\nEquals to `1` for any January 1, `365` for a December 31 on a non-leap year,\nand `366` for a December 31 on a leap year.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime\n\ntype(datetime)  :: a\n\n! Initialize:\na = datetime(2013,5,1)\n\nprint *, a % yearday() ! 121\n```\n\n#### See also\n\n* [*isocalendar*](#isocalendar)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### timedelta\u003ca id=\"timedelta\"\u003e\u003c/a\u003e\n\nRepresents a duration of time, and a difference between\ntwo [*datetime*](#datetime) objects. It is defined as:\n\n```fortran\ntype :: timedelta\n\n  !! Class of objects that define difference between two datetime\n  !! instances.\n\n  private\n\n  integer :: days         = 0 !! number of days\n  integer :: hours        = 0 !! number of hours\n  integer :: minutes      = 0 !! number of minutes\n  integer :: seconds      = 0 !! number of seconds\n  integer :: milliseconds = 0 !! number of milliseconds\n\n  contains\n\n  ! getter functions\n  procedure,pass(self),public :: getDays\n  procedure,pass(self),public :: getHours\n  procedure,pass(self),public :: getMinutes\n  procedure,pass(self),public :: getSeconds\n  procedure,pass(self),public :: getMilliseconds\n\n  ! public methods\n  procedure,public :: total_seconds\n\n  ! operator overloading procedures\n  procedure,private :: timedelta_plus_timedelta\n  procedure,private :: timedelta_minus_timedelta\n  procedure,private :: unary_minus_timedelta\n  procedure,private :: eq\n  procedure,private :: neq\n  procedure,private :: gt\n  procedure,private :: ge\n  procedure,private :: lt\n  procedure,private :: le\n\n  generic :: operator(+)  =\u003e timedelta_plus_timedelta\n  generic :: operator(-)  =\u003e timedelta_minus_timedelta,\u0026\n                             unary_minus_timedelta\n  generic :: operator(==) =\u003e eq\n  generic :: operator(/=) =\u003e neq\n  generic :: operator(\u003e)  =\u003e gt\n  generic :: operator(\u003e=) =\u003e ge\n  generic :: operator(\u003c)  =\u003e lt\n  generic :: operator(\u003c=) =\u003e le\n\nendtype timedelta\n```\n\nAll arguments are optional and default to 0.\nSimilarly to [*datetime*](#datetime) objects,\n[*timedelta*](#timedelta) instances can be initialized\nusing positional and/or keyword arguments.\nIn addition, a [*timedelta*](#timedelta) object is a result\nof subtraction between two [*datetime*](#datetime) objects.\n\n#### Example usage\n\n```fortran\nuse datetime_module\n\ntype(datetime)  :: a,b\ntype(timedelta) :: c\n\n! Initialize as default\nc = timedelta()\n\n! Positional arguments:\nc = timedelta(0,1,15,0,0) ! 1 hour and 15 minutes\n\n! Keyword arguments:\nc = timedelta(days=1,hours=12) ! 1 day and 12 hours\n\n! Difference between datetimes:\na = datetime(2013,5,12,22,0,0) ! 2013-05-12 22:00:00\nb = datetime(2012,9,18,14,0,0) ! 2012-09-18 14:00:00\n\n! Subtract to get timedelta:\nc = a-b\n```\n\n[Back to top](#top)\n\u003chr\u003e\n\n### total_seconds\u003ca id=\"totalseconds\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental real(kind=real_dp) function total_seconds(self)\n  class(timedelta), intent(in) :: self\n```\n\nA [*timedelta*](#timedelta)-bound method that returns a number\nof seconds contained in the time interval defined by the\n[*timedelta*](#timedelta) instance. This method is equivalent\nto Python's [*datetime.timedelta.total_seconds*](http://docs.python.org/2/library/datetime.html#timedelta-objects) function.\n\n#### Return value\n\n`total_seconds` A total number of seconds (of type `real(kind=real_dp)`)\ncontained in the [*timedelta*](#timedelta) instance.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:timedelta\n\ntype(timedelta) :: td\n\ntd = timedelta(days=5,hours=12,minutes=15,seconds=7,milliseconds=123)\n\nprint *, td%total_seconds() ! 476107.12300000002\n```\n\n[Back to top](#top)\n\u003chr\u003e\n\n### clock\u003ca id=\"clock\"\u003e\u003c/a\u003e\n\nA generic clock object that contains start and stop times,\ntick increment and reset and tick methods.\nMost useful when needing to keep track of many [*datetime*](#datetime) instances\nthat change at different rates, for example, physical models with different\ntime steps.\n\nDefinition:\n\n```fortran\ntype :: clock\n\n  !! A clock object with a start, stop and current times, tick interval\n  !! and tick methods.\n\n  type(datetime) :: startTime\n  type(datetime) :: stopTime\n  type(datetime) :: currentTime\n\n  type(timedelta) :: tickInterval\n\n  logical :: alarm = .false.\n\n  ! Clock status flags\n  logical :: started = .false.\n  logical :: stopped = .false.\n\n  contains\n\n  procedure :: reset\n  procedure :: tick\n\nendtype clock\n```\n\n[*clock*](#clock) instance must be initialized\nwith some sane values of `clock%startTime`, `clock%stopTime` and `clock%tickIncrement`\nin order to be useful.\n\n#### Example usage\n\n```fortran\nuse datetime_module\n\ntype(clock)    :: myClock\ntype(datetime) :: myTime\n\n! Initialize myTime\nmyTime = myTime%now()\n\n! Initialize myClock\n! Starts from myTime, stops 1 hour later, 1 minute per tick\nmyClock = clock(startTime    = myTime,                   \u0026\n                stopTime     = myTime+timedelta(hours=1),\u0026\n                tickInterval = timedelta(minutes=1))\n\ndo\n\n  call myClock % tick()\n\n  ! Report current time after each tick\n  print *, myClock % currentTime % isoformat(' ')\n\n  ! If clock has reached stopTime, exit loop\n  if(myClock % stopped)THEN\n    exit\n  endif\n\nenddo\n```\n#### See also\n\n* [*datetime*](#datetime)\n\n* [*timedelta*](#timedelta)\n\n\n[Back to top](#top)\n\u003chr\u003e\n\n### reset\n\n```fortran\npure elemental subroutine reset(self)\n  class(clock),intent(inout) :: self\n```\n\nResets the clock to its start time.\n\n#### Example usage\n\n```fortran\ncall myClock%reset() ! Resets myClock%currentTime to myClock%startTime\n```\n\n[Back to top](#top)\n\u003chr\u003e\n\n### tick\n\n```fortran\npure elemental subroutine tick(self)\n  class(clock),intent(inout) :: self\n```\n\nIncrements the `currentTime` of the clock instance by one `tickInterval`.\nSets the `clock%stopped` flag to `.TRUE.` if `clock%currentTime` equals\nor exceeds `clock%stopTime`.\n\n#### Example usage\n\nSee [*clock*](#clock) for an example.\n\n#### See also\n\n[Back to top](#top)\n\u003chr\u003e\n\n### **tm_struct**\u003ca id=\"tm_struct\"\u003e\u003c/a\u003e\n\nTime object compatible with C/C++ *tm* struct. Available mainly\nfor the purpose of calling [*c_strftime*](#c_strftime)\nand [*c_strptime*](#c_strptime) procedures.\n\n```fortran\ntype,bind(c) :: tm_struct\n\n  !! A derived type provided for compatibility with C/C++ time struct.\n  !! Allows for calling strftime and strptime procedures through the\n  !! iso_c_binding.\n\n  integer(kind=c_int) :: tm_sec   !! Seconds      [0-60] (1 leap second)\n  integer(kind=c_int) :: tm_min   !! Minutes      [0-59]\n  integer(kind=c_int) :: tm_hour  !! Hours        [0-23]\n  integer(kind=c_int) :: tm_mday  !! Day          [1-31]\n  integer(kind=c_int) :: tm_mon   !! Month        [0-11]\n  integer(kind=c_int) :: tm_year  !! Year - 1900\n  integer(kind=c_int) :: tm_wday  !! Day of week  [0-6]\n  integer(kind=c_int) :: tm_yday  !! Days in year [0-365]\n  integer(kind=c_int) :: tm_isdst !! DST          [-1/0/1]\n\nendtype tm_struct\n```\n\n#### See also\n\n* [*datetime*](#datetime)\n\n* [*tm*](#tm)\n\n* [*strftime*](#c_strftime)\n\n* [*strptime*](#c_strptime)\n\n[Back to top](#top)\n\u003chr\u003e\n\n## Overloaded operators\u003ca id=\"overloaded-operators\"\u003e\u003c/a\u003e\n\n*datetime-fortran* provides arithmetic and comparison operators\nfor [*datetime*](#datetime) and [*timedelta*](#timedelta) objects.\n\n### Arithmetic operators\n\nAddition (`+`) and subtraction (`-`) operators are available for\nthe following combination of derived type pairs:\n\n* `datetime  + timedelta`, returns a `datetime` instance;\n\n* `timedelta + datetime`, returns a `datetime` instance;\n\n* `timedelta + timedelta`, returns a `timedelta` instance;\n\n* `timedelta - timedelta`, returns a `timedelta` instance;\n\n* `datetime  - datetime`, returns a `timedelta` instance;\n\n* `-timedelta` (unary minus), returns a `timedelta` instance.\n\nNote that `datetime  - datetime` operation accounts for timezone (`tz`)\noffsets in each of the `datetime` instances.\nThe resulting `timedelta`thus  includes the difference between timezones.\n\n### Comparison operators\n\n*datetime-fortran* supports following binary comparison operators for\n[*datetime*](#datetime) and [*timedelta*](#timedelta) objects:\n`==`, `/=`, `\u003e`, `\u003e=`, `\u003c` and `\u003c=`.\n\nSince version 1.0.5, all comparison operators respect the timezone\nparameter of the datetime instances, so the operands are first\nadjusted to UTC time before making the comparison.\n\n[Back to top](#top)\n\u003chr\u003e\n\n## Public procedures\u003ca id=\"#public-procedures\"\u003e\u003c/a\u003e\n\n### c_strftime\u003ca id=\"c_strftime\"\u003e\u003c/a\u003e\n\n```fortran\nfunction c_strftime(str,slen,format,tm) bind(c,name='strftime') result(rc)\n  character(kind=c_char),dimension(*),intent(out) :: str\n  integer(kind=c_int),value,          intent(in)  :: slen\n  character(kind=c_char),dimension(*),intent(in)  :: format\n  type(tm_struct),                    intent(in)  :: tm\n  integer(kind=c_int)                             :: rc\n```\n\nAn interface to a C/C++ standard library routine.\nCopies into `str` the content of format, expanding its format specifiers\ninto the corresponding values that represent the time described in `tm`,\nwith a limit of `slen` characters.\n\nNote: This function was renamed from *strftime* to *c_strftime* in version 0.3.0\nto avoid name conflict with *datetime*-bound method [*strftime*](#strftime).\nIf working with *datetime* instances, use [*datetime%strftime*](#strftime) instead.\n\n#### Arguments\n\n`str` is the destination character string with the requested date and time.\n\n`slen` is the maximum number of characters to be copied to `str`,\nincluding the terminating null-character, `char(0)`.\n\n`format` is the character string containing any combination of regular characters and special format specifiers.\nThese format specifiers are replaced by the function to the corresponding values to represent the time specified in `tm`.\nFor more information on format specifiers see http://www.cplusplus.com/reference/ctime/strftime/.\n\n`tm` is an instance of the type `tm_struct`, containing date and time values to be processed.\n\n#### Return value\n\nIf the resulting string fits in less than `slen` characters including the terminating null-character,\nthe total number of characters copied to `str` (not including the terminating null-character) is returned.\nOtherwise, zero is returned and the contents of the array are indeterminate.\n\n#### Example usage\n\n```fortran\nuse datetime_module\n\ntype(datetime)    :: a\ncharacter(len=20) :: res\ninteger           :: rc\n\na = a % now()\n\nrc = c_strftime(res,20,\"%Y %B %d\"//CHAR(0),a%tm())\n```\n\n#### See also\n\n* [*datetime%strftime*](#strftime)\n\n* [*c_strptime*](#c_strptime)\n\n* [*strptime*](#strptime)\n\n* [*tm*](#tm)\n\n* [*tm_struct*](#tm_struct)\n\n\n[Back to top](#top)\n\u003chr\u003e\n\n### c_strptime\u003ca id=\"c_strptime\"\u003e\u003c/a\u003e\n\n```fortran\nfunction c_strptime(str,format,tm) bind(c,name='strptime') result(rc)\n  character(kind=c_char),dimension(*),intent(in)  :: str\n  character(kind=c_char),dimension(*),intent(in)  :: format\n  type(tm_struct),                    intent(out) :: tm\n  character(kind=c_char,len=1)                    :: rc\n```\n\nAn interface to a C/C++ standard library routine.\nConverts the character string `str` to values which are stored in `tm`, using the format specified by `format`.\n\nNote: This function was renamed from *strptime* to *c_strptime* in version 0.3.0 to avoid\nname conflicts with [*strptime*](#strptime) which operates on *datetime* instances.\nIf working with *datetime* instances, use [*strptime*](#strptime) instead.\n\n#### Arguments\n\n`str` is the character string containing date and time information.\n\n`format` is the character string containing any combination of regular characters and special format specifiers,\ndescribing the date and time information in `str`.\n\n`tm` is an instance of the type `tm_struct`, in which the date and time values will be filled upon successful completion\nof the [*c_strptime*](#c_strptime) function.\n\n#### Return value\n\nUpon successful completion, [*c_strptime*](#c_strptime) returns the character\nfollowing the last character parsed. Otherwise, a null character is returned.\n\n#### Example usage\n\nExtracting time difference between two time strings using [*c_strptime*](#c_strptime)\nand [*tm2date*](#tm2date):\n\n```fortran\nuse datetime_module\n\ntype(datetime)  :: date1,date2\ntype(tm_struct) :: ctime\ntype(timedelta) :: timediff\n\n! Return code for strptime\ncharacter(len=1) :: rc\n\n! Example times in \"YYYYMMDD hhmmss\" format\ncharacter(len=15) :: str1 = \"20130512 091519\"\ncharacter(len=15) :: str2 = \"20131116 120418\"\n\n! Get tm_struct instance from str1\nrc = c_strptime(str1,\"%Y%m%d %H%M%S\"//char(0),ctime)\ndate1 = tm2date(ctime)\n\n! Get tm_struct instance from str2\nrc = c_strptime(str2,\"%Y%m%d %H%M%S\"//char(0),ctime)\ndate2 = tm2date(ctime)\n\ntimediff = date2-date1\n\nprint *, timediff\nprint *, timediff % total_seconds()\n```\n\nThis example outputs the following:\n\n```\n        188           2          48          58        1000\n   16253339.0000000\n```\n\n#### See also\n\n* [*strptime*](#strptime)\n\n* [*tm2date*](#tm2date)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### date2num\u003ca id=\"date2num\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental real(kind=real_dp) function date2num(d)\n  type(datetime),intent(in) :: d\n```\n\nReturns the number of days since `0001-01-01 00:00:00 UTC`,\ngiven a [*datetime*](#datetime) instance `d`.\n\nThis function is similar in what it returns to analogous functions\nin Python ([*matplotlib.dates.date2num*](http://matplotlib.org/api/dates_api.html#matplotlib.dates.date2num))\nand MATLAB's [*datenum*](http://www.mathworks.com/help/matlab/ref/datenum.html).\nNote that [*matplotlib.dates.date2num*](http://matplotlib.org/api/dates_api.html#matplotlib.dates.date2num) returns the number of days since `0001-01-01 00:00:00 UTC` plus `1`\n(for historical reasons),\nand MATLAB's [*datenum*](http://www.mathworks.com/help/matlab/ref/datenum.html)\nreturns the number of days since `0000-01-01 00:00:00 UTC`.\nIn *datetime-fortran*, we choose the reference time of `0001-01-01 00:00:00 UTC`\nas we consider it to be the least astonishing for the average user.\nThus, MATLAB and Python users should be cautious when using\n*datetime-fortran*'s [*date2num()*](#date2num) function.\n\nSince version 1.0.5, [date2num](#date2num) is timezone aware, i.e.\nthe datetime instance is first converted to UTC before calculating\nthe number of days.\n\n[date2num](#date2num) is the inverse function of [num2date](#num2date),\nso by definition, `a % utc() == num2date(date2num(a))` evaluates as `.true.`\nfor any `datetime` instance `a`.\n\n#### Arguments\n\n`d` A [*datetime*](#datetime) instance.\n\n#### Return value\n\n`date2num` A `REAL(KIND=real64)` number of days since `0001-01-01 00:00:00 UTC`.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime,date2num\n\ntype(datetime)  :: a\n\n! Initialize:\na = datetime(2013,1,1,6)\n\nprint *, date2num(a) ! 734869.25000000000\n```\n\n#### See also\n\n* [*datetime*](#datetime)\n\n* [*num2date*](#num2date)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### datetimeRange\u003ca id=\"datetimerange\"\u003e\u003c/a\u003e\n\n```fortran\npure function datetimeRange(d0,d1,t)\n  type(datetime), intent(in) :: d0\n  type(datetime), intent(in) :: d1\n  type(timedelta),intent(in) :: t\n```\n\nGiven start and end [*datetime*](#datetime) instances `d0` and `d1`,\nand time increment as [*timedelta*](#timedelta) instance `t`,\nreturns an array of datetime instances.\nThe number of elements is the number of whole time increments\ncontained between datetimes `d0` and `d1`.\n\n#### Arguments\n\n`d0` A [*datetime*](#datetime) instance with start time. Will be the first element\nof the resulting array.\n\n`d1` A [*datetime*](#datetime) instance with end time. Will be the equal to or greater than\nthe last element of the resulting array.\n\n`t` A [*timedelta*](#timedelta) instance being the time increment for the resulting array.\n\n#### Return value\n\n`datetimeRange` An array of [*datetime*](#datetime) instances of length\n `floor((d1-d0)/t)+1`\n\n#### Example usage\n\n```fortran\ntype(datetime)  :: a,b\ntype(timedelta) :: td\n\ntype(datetime),dimension(:),allocatable :: dtRange\n\na  = datetime(2014,5,1)\nb  = datetime(2014,5,3)\ntd = timedelta(days=1)\n\ndtRange = datetimeRange(a,b,td)\n\n! Returns:\n!\n! dtRange = [datetime(2014,5,1),\n!            datetime(2014,5,2),\n!            datetime(2014,5,3)]\n\na  = datetime(2014,5,1)\nb  = datetime(2014,5,3)\ntd = timedelta(hours=7)\n\ndtRange = datetimeRange(a,b,td)\n\n! Returns:\n!\n! dtRange = [datetime(2014,5,1,0),\n!            datetime(2014,5,1,7),\n!            datetime(2014,5,1,14),\n!            datetime(2014,5,1,21),\n!            datetime(2014,5,2, 4),\n!            datetime(2014,5,2,11),\n!            datetime(2014,5,2,18)]\n```\n\n#### See also\n\n* [*datetime*](#datetime)\n\n* [*timedelta*](#timedelta)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### daysInMonth\u003ca id=\"daysinmonth\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental integer function daysInMonth(month,year)\n  integer,intent(in) :: month\n  integer,intent(in) :: year\n```\n\nReturns the number of days in month for a given month and year.\nThis function is declared as `elemental`, so it can be called\nwith scalar or n-dimensional array arguments.\n\n#### Arguments\n\n`month` Integer number of month in year. Valid values are in the range [1-12].\n\n`year` Integer year.\n\n#### Return value\n\nReturns an integer number of days in requested month and year.\nReturns `0` if `month` is not in valid range.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:daysInMonth\n\n! January on leap year:\nprint *, daysInMonth(1,2012)   ! 31\n\n! February on leap year:\nprint *, daysInMonth(2,2012)   ! 29\n\n! February on non-leap year\nprint *, daysInMonth(2,2013)   ! 28\n```\n\n#### See also\n\n* [*daysInYear*](#daysinyear)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### daysInYear\u003ca id=\"daysinyear\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental integer Function daysInYear(year)\n  integer,intent(in) :: year\n```\n\nGiven an integer `year`, returns an integer number of days in that year.\nCalls the [*isLeapYear*](#isleapyear) function.\n\n#### Arguments\n\n`year` An `integer` scalar or array containing the desired year number(s).\n\n#### Return value\n\n`daysInYear` An `integer` scalar or array. Represents the number of days in `year`.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:daysInYear\n\n! Leap year:\nprint *, daysInYear(2012) ! 366\n\n! Non-leap year:\nprint *, daysInYear(2013) ! 365\n```\n\n#### See also\n\n* [*daysInMonth*](#daysinmonth)\n\n* [*isLeapYear*](#isleapyear)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### isLeapYear\u003ca id=\"isleapyear\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental logical function isLeapYear(year)\n  integer,intent(in) :: year\n```\n\nReturns a `logical` value indicating whether the reqested year is a leap year.\n\n#### Arguments\n\n`year` An `integer` scalar or array representing year number.\n\n#### Return value\n\n`isLeapYear` A `logical` scalar or array indicating whether a given year is leap year.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:isLeapYear\n\n! Leap year:\nprint *, isLeapYear(2012) ! .true.\n\n! Non-leap year:\nprint *, isLeapYear(2013) ! .false.\n```\n\n#### See also\n\n* [*daysInYear*](#daysInYear)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### num2date\u003ca id=\"num2date\"\u003e\u003c/a\u003e\n\n```fortran\npure elemental type(datetime) function num2date(num)\n  real(kind=real_dp),intent(in) :: num\n```\n\nGiven the number of days since `0001-01-01 00:00:00 UTC`, returns a\ncorrespoding [datetime](#datetime) instance.\n\nThis function is similar to analogous function\nin Python ([*matplotlib.dates.num2date*](http://matplotlib.org/api/dates_api.html#matplotlib.dates.num2date)).\n\n[num2date](#num2date) is the inverse function of [date2num](#date2num),\nso by definition, `a == num2date(date2num(a))` evaluates as `.true.`\nfor any `datetime` instance `a`.\nSimilarly, `b == date2num(num2date(b))` evaluates as `.true.`\nfor any variable `b` of type `real(kind=real64)`.\n\n#### Arguments\n\n`num` Number of days since `0001-01-01 00:00:00 UTC`.\n\n#### Return value\n\n`num2date` A [*datetime*](#datetime) instance.\n\n#### Example usage\n\n```fortran\nuse datetime_module,only:datetime,num2date\n\ntype(datetime)  :: a\n\na = num2date(734869.25d0) ! a becomes datetime(2013,1,1,6,0,0,0)\n```\n\n#### See also\n\n* [*date2num*](#date2num)\n\n* [*datetime*](#datetime)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### strptime\u003ca id=\"strptime\"\u003e\u003c/a\u003e\n\n```fortran\ntype(datetime) function strptime(str,format)\n  character(len=*),intent(in) :: str\n  character(len=*),intent(in) :: format\n```\n\nA wrapper function around [*c_strptime*](#c_strptime).\nGiven a character string `str` with the format `format`, returns\nan appropriate *datetime* instance containing that time information.\nThis function is analogous to Python's *datetime.datetime.strptime()* function.\nAvailable since version 0.3.0.\n\n#### Arguments\n\n`str` is the character string containing date and time information.\n\n`format` is the character string containing any combination of regular characters and special format specifiers,\ndescribing the date and time information in `str`.\n\n#### Return value\n\nUpon successful completion, [*strptime*](#strptime) returns the [*datetime*](#datetime)\ninstance corresponding to the time information contained in *str*.\n\n#### Example usage\n\nExtracting time difference between two time strings using [*strptime*](#strptime):\n\n```fortran\nuse datetime_module\n\ntype(datetime)  :: date1,date2\ntype(timedelta) :: timediff\n\n! Example times in \"YYYYMMDD hhmmss\" format\ncharacter(len=15) :: str1 = \"20130512 091519\"\ncharacter(len=15) :: str2 = \"20131116 120418\"\n\ndate1 = strptime(str1,\"%Y%m%d %H%M%S\")\ndate2 = strptime(str2,\"%Y%m%d %H%M%S\")\n\ntimediff = date2-date1\n\nprint *, timediff\nprint *, timediff%total_seconds()\n```\n\nThis example outputs the following:\n\n```\n        188           2          48          58        1000\n   16253339.0000000\n```\nThis is the same example as in [*c_strptime*](#c_strptime) but with fewer\nnecessary steps.\n\n#### See also\n\n* [*c_strptime*](#c_strptime)\n\n* [*tm2date*](#tm2date)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### tm2date\n\n```fortran\npure elemental type(datetime) function tm2date(ctime)\n  type(tm_struct),intent(in) :: ctime\n```\n\nGiven a [*tm_struct*](#tm_struct) instance,\nreturns a corresponding [*datetime*](#datetime) instance.\nMostly useful for obtaining a *datetime* instance after a *tm_struct*\nis returned from [*strptime*](#strptime).\n\n#### Arguments\n\n`ctime` A `tm_struct` instance.\n\n#### Return value\n\n`tm2date` A `datetime` instance.\n\n#### Example usage\n\nSee example usage for [*strptime*](#strptime).\n\n#### See also\n\n* [*datetime*](#datetime)\n\n* [*tm_struct*](#tm_struct)\n\n* [*strptime*](#strptime)\n\n### machinetimezone\n\n```fortran\nreal(real64) function machinetimezone()\n```\n\nreturns the machine's time zone in hours.\n\n#### Arguments\n\nNone\n\n#### Return value\n\n`real(real64)` A `tz` value.\n\n#### Example usage\n\nExtracting your local machine's time zone information.\n\n```fortran\ntype(datetime) :: date\ndate = datetime(1970, 1, 1, tz=machinetimezone())\n```\n\n#### See also\n\n* [*datetime*](#datetime)\n\n* [*localtime*](#localtime)\n\n* [*gmtime*](#gmtime)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### epochdatetime\n\n```fortran\npure elemental type(datetime) function epochdatetime()\n    epochdatetime = datetime(1970,1,1,0,0,0,0,tz=0.)\n```\nreturns a `datetime` that corresponds to the UNIX epoch.\n\n#### Arguments\n\nNone\n\n#### Return value\n\n`type(datetime)` A `datetime(1970,1,1,0,0,0,0,tz=0.0)` value.\n\n#### Example usage\n\n```fortran\ntype(datetime) :: epochday\nepochday = epochdatetime()\n```\n\n#### See also\n\n* [*datetime*](#datetime)\n\n* [*localtime*](#localtime)\n\n* [*gmtime*](#gmtime)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### localtime\n\n```fortran\n  pure elemental type(datetime) function localtime(epoch, tz)\n    ! Returns a `datetime` instance from epoch.\n    ! tz can be obtained from `machinetimezone`\n    integer(int64),intent(in) :: epoch\n    real(real64),intent(in) :: tz !! local machine time zone information\n```\nGenerating a *datetime* type from epoch and timezone.\n\n#### Arguments\n\n`epoch` A epoch time (second)\n\n`tz` A time zone (hour). This value can be generated by using [*machinetimezone*](#machinetimezone)\n\n#### Return value\n\n`type(datetime)` A `datetime` instance.\n\n#### Example usage\n\nConvert the epoch seconds to an expression in your machine's time zone.\n\n```fortran\ninteger(int64), parameter :: epoch = 3600\nreal(real64) :: tz\ntype(datetime) :: date\ntz = machinetimezone()\ndate = localtime(epoch, tz)\n```\n\n#### See also\n\n* [*datetime*](#datetime)\n\n* [*machinetimezone*](#machinetimezone)\n\n* [*gmtime*](#gmtime)\n\n[Back to top](#top)\n\u003chr\u003e\n\n### gmtime\n\n```fortran\n  pure elemental type(datetime) function gmtime(epoch)\n    ! Returns a `datetime` instance from epoch.\n    integer(int64),intent(in) :: epoch\n```\nGenerating a *datetime* type from epoch.\n\n#### Arguments\n\n`epoch` A epoch time (second)\n\n#### Return value\n\n`type(datetime)` A `datetime` instance.\nResult is represented with UTC time.\n\n#### Example usage\n\nConvert the epoch seconds to an expression in UTC time zone.\n\n```fortran\ninteger(int64) :: epoch = 3600\ntype(datetime) :: day\nday = gmtime(epoch)\n```\n\n#### See also\n\n* [*datetime*](#datetime)\n\n* [*machinetimezone*](#machinetimezone)\n\n* [*localtime*](#localtime)\n\n[Back to top](#top)\n\u003chr\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwavebitscientific%2Fdatetime-fortran","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwavebitscientific%2Fdatetime-fortran","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwavebitscientific%2Fdatetime-fortran/lists"}