Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Usage  



1.1  Custom epoch  







2 See also  














Module:TwitterSnowflake/sandbox







Add links
 









Module
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

< Module:TwitterSnowflake

This is a Lua module to translate snowflakes from platforms such as Twitter and Discord to timestamps. This can be used for automatically generating dates for templates like {{cite tweet}}.

Usage[edit]

There is one required parameter: |id_str=, which must be the snowflake ID of the tweet. For example, 1345021162959503360.

{{#invoke:TwitterSnowflake|snowflakeToDate|id_str=1345021162959503360}} returns January 1, 2021.

To specify the date format, use |format=.

{{#invoke:TwitterSnowflake|snowflakeToDate|id_str=1345021162959503360|format=%e %B %Y}} returns 1 January 2021 — useful to specify, especially for use in CS1 citations, in case the default date format would change in the future (though unlikely).

Custom epoch[edit]

By default, the epoch used is that of Twitter. To specify a different epoch, such as that of Twitter, use |epoch=. The epoch of Discord is 1420070400

{{#invoke:TwitterSnowflake|snowflakeToDate|id_str=797545051047460888|epoch=1420070400}} returns January 9, 2021.

See also[edit]

local p = {}
local TwitterSnowflake = require('Module:TwitterSnowflake')
local CiteWeb = require('Module:Cite web')['']

local function _if(arg)
 return arg and arg ~= '' or nil
end

p.main = function(frame)
 frame.args = frame:getParent().args
 return p[''](frame)
end

p[''] = function(frame)
 local args = frame.args
 local cite_args = {
  url   = 'https://twitter.com/' .. ((args.user and args.number) and (args.user .. '/status/' .. args.number) or ''),
  title  = (args.title or ''):gsub('https*://', ''),
  ['script-title'] = args['script-title'],
  ['trans-title'] = args['trans-title'],
  language = args.language,
  ['author-link'] = args['author-link'] or args.authorlink,
  others  = _if(args.retweet) and ('Retweeted by ' .. args.retweet),
  via   = args.link == 'no' and 'Twitter' or '[[Twitter]]',
  type  = 'Tweet',
  location = args.location,
  ['access-date'] = args['access-date'] or args.accessdate,
  ['archive-date'] = args['archive-date'] or args.archivedate,
  ['archive-url'] = args['archive-url'] or args.archiveurl,
  ['url-status'] = args['url-status'] or args['dead-url'] or args.deadurl,
  quote = args.quote,
  ref   = args.ref,
  df   = args.df
 }
 if _if(args.last1 or args.last) then
  cite_args.author = (args.last1 or args.last) ..
   (_if(args.first1 or args.first) and (', ' .. (args.first1 or args.first)) or '') ..
   ' [@' .. (args.user or '') .. ']'
 elseif _if(args.author1 or args.author) then
  cite_args.author = (args.author1 or args.author) .. ' [@' .. (args.user or '') .. ']'
 elseif _if(args['author-link']) then
  cite_args.author = args['author-link'] .. ' [@' .. (args.user or '') .. ']'
 else
  cite_args.author = '@' .. (args.user or '')
 end
 if cite_args.author:find ('[Tt]witter') then
  cite_args.author = '((' .. cite_args.author .. '))'
 end
 if _if(tonumber(args.number)) then
  cite_args.date = args.date or (_if(args.number) and TwitterSnowflake.snowflakeToDate{ args = {id_str = args.number} })
 else
  cite_args.date = args.date
 end
 
 frame.args = cite_args
 local output = CiteWeb(frame)
 frame.args = args
 
 -- Error checking
 local error_template = '<span class="cs1-visible-error citation-comment">%s</span>'
 local errors = {}
 if not (_if(args.title) or _if(args['script-title']) or args.user or args.number or args.date) then
  -- No title; error message is provided by CS1 module.
  errors[1] = ';'
 end
 if not _if(args.user) then
  errors[1 + #errors] = ' Missing or empty <kbd>&#124;user=</kbd>;'
 end
 if not _if(args.number) then
  errors[1 + #errors] = ' Missing or empty <kbd>&#124;number=</kbd>;'
 end
 errors[1 + #errors] = TwitterSnowflake.datecheck{ args = {
  id_str = args.number or '',
  date = args.date or '',
  error1 = ' <kbd>&#124;date=</kbd> mismatches calculated date from <kbd>&#124;number=</kbd> by two or more days;',
  error2  = ' Missing or empty <kbd>&#124;date=</kbd>, and posted before November 4, 2010;',
  error3 = ' Invalid <kbd>&#124;number=</kbd> parameter;'
 }}
 if errors[1] then
  local last = errors[#errors]
  errors[#errors] = last:sub(1, #last - 1) .. ' ([[Template:Cite_tweet#Error_detection|help]])'
  local error_out = error_template:rep(#errors):format(unpack(errors)) 
  if mw.title.getCurrentTitle():inNamespace(0) then
   error_out = error_out .. '[[Category:Cite tweet templates with errors]]'
  end
  output = output .. error_out
 end
 return output
end

return p

Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:TwitterSnowflake/sandbox&oldid=1098910087"

Category: 
Module sandboxes
 



This page was last edited on 18 July 2022, at 02:12 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki