{"id":22525384,"url":"https://github.com/wdbm/shijian","last_synced_at":"2025-08-03T21:32:30.317Z","repository":{"id":22496755,"uuid":"25836225","full_name":"wdbm/shijian","owner":"wdbm","description":"change, time, file, list, statistics, language and other utilities","archived":false,"fork":false,"pushed_at":"2023-10-19T02:17:43.000Z","size":5075,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-29T12:22:33.217Z","etag":null,"topics":["clock","statistics","time"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wdbm.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}},"created_at":"2014-10-27T19:51:54.000Z","updated_at":"2023-10-19T02:17:47.000Z","dependencies_parsed_at":"2022-08-21T06:00:50.143Z","dependency_job_id":null,"html_url":"https://github.com/wdbm/shijian","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdbm%2Fshijian","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdbm%2Fshijian/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdbm%2Fshijian/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wdbm%2Fshijian/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wdbm","download_url":"https://codeload.github.com/wdbm/shijian/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228567024,"owners_count":17937986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["clock","statistics","time"],"created_at":"2024-12-07T06:10:01.987Z","updated_at":"2024-12-07T06:10:03.096Z","avatar_url":"https://github.com/wdbm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# shijian\n\nPython change, time, file, list, statistics and other utilities\n\n# setup\n\n```Bash\nsudo pip install shijian\n```\n\n# usage\n\n## time expressions\n\nFunction `style_datetime_object` accepts a `datetime` object and returns a string representation of a time. The default style is \"YYYY-MM-DDTHHMMSS\" and it can be changed by argument. Styles available are as follows:\n\n|**time representation** |**comment**                              |\n|------------------------|-----------------------------------------|\n|YYYY-MM-DDTHHMMSSZ      |filename safe (default)                  |\n|YYYY-MM-DDTHHMMSSMMMMMMZ|microseconds                             |\n|YYYY-MM-DD HH:MM:SS UTC |elegant                                  |\n|UNIX time S.SSSSSS      |UNIX time in seconds with second fraction|\n|UNIX time S             |UNIX time in seconds rounded             |\n\nFunctions `time_UTC` and `time_UNIX` are sorts of special cases of function `style_datetime_object` which return representations of the current time (as opposed to any specified datetime object) in a style. For `time_UTC`, the default style is \"YYYY-MM-DDTHHMMSS\" and for `time_UNIX`, the default style is \"UNIX time S\" and these styles can be changed by argument.\n\n```Python\n\u003e\u003e\u003e shijian.time_UTC()\n'2015-01-05T092125Z'\n\u003e\u003e\u003e shijian.time_UNIX()\n1420449720\n```\n\n## unique identifiers\n\nFunction `propose_filename` proposes a safe filename. It can accept a filename suggestion or, by default, can generate its own filename suggestion, a time expression returned by function `time_UTC`. Filename suggestions are tested and then proposed if they meet test conditions. The default condition is to not overwrite existing files and to append an underscore followed by an integer in order to meet this condition.\n\n```Python\n\u003epython\nPython 2.7.6 (default, Mar 22 2014, 22:59:56) \n[GCC 4.8.2] on linux2\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\u003e\u003e\u003e import shijian\n\u003e\u003e\u003e shijian.propose_filename()\n'2015-01-05T092319Z'\n\u003e\u003e\u003e shijian.propose_filename(filename = \"data.pkl\")\n'data.pkl'\n\u003e\u003e\u003e \n\u003etouch data.pkl\n\u003epython\nPython 2.7.6 (default, Mar 22 2014, 22:59:56) \n[GCC 4.8.2] on linux2\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\u003e\u003e\u003e import shijian\n\u003e\u003e\u003e shijian.propose_filename(filename = \"data.pkl\")\n'data_1.pkl'\n```\n\nFunction `UID` returns a 128 bit integer unique identifier in hexadecimal with dashes in accordance with [RFC 4122 UUID version 4](http://tools.ietf.org/html/rfc4122.html).\n\n```Python\n\u003e\u003e\u003e shijian.UID()\n'91df3b90-285c-4f22-8ced-a154b3b5b09b'\n\u003e\u003e\u003e shijian.UID()\n'169bde88-2be2-4b46-bf2d-5bb7aee85658'\n```\n\nFunction `unique_number` returns an integer that does not exist in a global list of integers recorded by the function.\n\n```Python\n\u003e\u003e\u003e shijian.unique_number()\n1\n\u003e\u003e\u003e shijian.unique_number()\n2\n```\n\nFunction `unique_3_digit_number` returns an integer of 3 significant figures that does not exist in a global list of integers of 3 significant figures recorded by the function.\n\n```Python\n\u003e\u003e\u003e shijian.unique_3_digit_number()\n100\n\u003e\u003e\u003e shijian.unique_3_digit_number()\n101\n```\n\n## clocks\n\nClocks can be created in a straightforward way such as the following:\n\n```Python\nalpha = shijian.Clock(name = \"alpha\")\n```\n\nBy default, clocks keep time from their creation time. This behaviour can be disabled using Boolean argument `start = False`. Clocks can be assigned a name or can generate their own unique identifier. Clocks can be stopped easily:\n\n```Python\nbeta.stop()\n```\n\nand can be started easily:\n\n```Python\nalpha.start()\n```\n\nClocks can report on their characteristics in ways such as the following:\n\n```Python\nprint(alpha.name())\nprint(alpha.start_time())\nprint(alpha.stop_time())\nprint(alpha.time())\n```\n\nClocks can also provide a general printout of their characteristics:\n\n```Python\nalpha.printout()\n```\n\nAll clocks are recorded in the shijian list of clocks. Printouts of clocks are available in two styles: full and statistics. The style \"full\" returns the elapsed times of all clocks while the default style \"statistics\" returns the mean times of all clocks of the same name.\n\n```Python\nshijian.clocks.printout(style = \"full\")\nshijian.clocks.printout()\n```\n\n## daily time range\n\nWhether the current time is in a specified daily time range can be tested:\n\n```Python\nshijian.in_daily_time_range(time_range = \"1700--0900\")\n```\n\n## filename sequences\n\nThe function `natural_sort` naturally sorts a list. The function `find_file_sequences`, for which a directory and file extension can be specified, returns a naturally-sorted list of filenames that are in a sequence or returns a dictionary of lists of filenames that are in a sequence. For example, a list something like the following could be returned:\n\n```Bash\n['image-000001.png', 'image-000002.png', 'image-000003.png', 'image-000004.png', 'image-000005.png']\n```\n\n## configurations, Markdown lists\n\nMarkdown lists are human-readable and machine-readable. So, they can be used to specify configurations written by humans for programs. This module features utilities for loading configurations specified in Markdown lists to Python dictionaries and ordered dictionaries.\n\nIn order to facilitate the human-readability of configuration specifications, the idea is that lines that are not valid Markdown lists are ignored.\n\n## ICHEP 2016\n\n```Bash\n./time_ICHEP_2016.py\n```\n\n![](https://raw.githubusercontent.com/wdbm/shijian/master/media/ICHEP_2016.gif)\n\n# upcoming\n\nChanges to time style specifications are under consideration.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwdbm%2Fshijian","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwdbm%2Fshijian","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwdbm%2Fshijian/lists"}